The world's most popular open source database
#include <stdio.h>Include dependency graph for fgetln.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Functions | |
| char * | fgetln (FILE *stream, size_t *len) |
| char* fgetln | ( | FILE * | stream, | |
| size_t * | len | |||
| ) |
Definition at line 48 of file fgetln.c.
00049 { 00050 static char *buf = NULL; 00051 static size_t bufsiz = 0; 00052 char *ptr; 00053 00054 00055 if (buf == NULL) { 00056 bufsiz = BUFSIZ; 00057 if ((buf = malloc(bufsiz)) == NULL) 00058 return NULL; 00059 } 00060 00061 if (fgets(buf, bufsiz, fp) == NULL) 00062 return NULL; 00063 *len = 0; 00064 00065 while ((ptr = strchr(&buf[*len], '\n')) == NULL) { 00066 size_t nbufsiz = bufsiz + BUFSIZ; 00067 char *nbuf = realloc(buf, nbufsiz); 00068 00069 if (nbuf == NULL) { 00070 int oerrno = errno; 00071 free(buf); 00072 errno = oerrno; 00073 buf = NULL; 00074 return NULL; 00075 } else 00076 buf = nbuf; 00077 00078 *len = bufsiz; 00079 if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) 00080 return buf; 00081 00082 bufsiz = nbufsiz; 00083 } 00084 00085 *len = (ptr - buf) + 1; 00086 return buf; 00087 }
1.4.7

