packages: don't put oss on cd.
[minix.git] / commands / pax / fgetln.c
blobf39aa9235806f92d0111fcd4ffffa3c69a33dedd
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
6 char *
7 fgetln(FILE *fp, size_t *lenp)
9 #define EXTRA 80
10 char *buf = NULL;
11 int used = 0, len = 0, remain = 0, final = 0;
12 while(!final) {
13 char *b;
14 int r;
15 if(remain < EXTRA) {
16 int newlen;
17 char *newbuf;
18 newlen = len + EXTRA;
19 if(!(newbuf = realloc(buf, newlen))) {
20 if(buf) free(buf);
21 return NULL;
23 buf = newbuf;
24 len = newlen;
25 remain += EXTRA;
27 buf[used] = '\0';
28 if(!fgets(buf + used, remain, fp))
29 break;
30 r = strlen(buf+used);
31 used += r;
32 remain -= r;
33 len += r;
35 *lenp = len;
36 return buf;