blob: 6f3afb0c1945af65d204870913728aa498495130 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include <string.h>
#include <fcntl.h>
char *
readline(fd)
{
static char linebuf[256];
int cc;
char * p;
cc = read(fd, linebuf, sizeof(linebuf)-1);
if( cc <= 0 ) return 0;
p = strchr(linebuf, '\n');
if( p == 0 ) p = linebuf+sizeof(linebuf)-1;
else
{
p++; lseek(fd, (long)(p-linebuf)-cc, 1);
}
*p = 0;
return linebuf;
}
main()
{
int fd = open("/etc/passwd", O_RDONLY);
char * p;
if(fd<0) exit(1);
while( p=readline(fd) )
{
write(1, ">>", 2);
write(1, p, strlen(p));
}
}
|