diff options
author | Robert de Bath <rdebath@poboxes.com> | 1997-02-25 20:42:19 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:38:07 +0200 |
commit | 4c36e9a0c125ccfff37aa440dab2cf58c4152fff (patch) | |
tree | a5d9c84ba2661029ddb2223dacd50529a361c3d5 /tests/lines.c | |
parent | f8de35da65c5d93bb733073cf40da154bc1c0748 (diff) | |
parent | 9696d7b0e1f3a1b0f5fd4a0428eb75afe8ad4ed6 (diff) | |
download | dev86-4c36e9a0c125ccfff37aa440dab2cf58c4152fff.tar.gz |
Import Dev86src-0.0.11.tar.gzv0.0.11
Diffstat (limited to 'tests/lines.c')
-rw-r--r-- | tests/lines.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lines.c b/tests/lines.c new file mode 100644 index 0000000..6f3afb0 --- /dev/null +++ b/tests/lines.c @@ -0,0 +1,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)); + } +} |