source: trunk/minix/commands/pax/fgetln.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 610 bytes
Line 
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6char *
7fgetln(FILE *fp, size_t *lenp)
8{
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;
22 }
23 buf = newbuf;
24 len = newlen;
25 remain += EXTRA;
26 }
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;
34 }
35 *lenp = len;
36 return buf;
37}
38
Note: See TracBrowser for help on using the repository browser.