# See patch1.solaris for instructions. diff -urN nwebmail-0.1.77/header.h nwebmail-sgp/header.h --- nwebmail-0.1.77/header.h Thu Jan 1 01:00:00 1970 +++ nwebmail-sgp/header.h Fri Apr 6 16:05:17 2001 @@ -0,0 +1,3 @@ +int getline(char **s, unsigned int *lim, FILE *stream); + +int getdelim(char **lineptr, size_t *n, int delimiter, FILE *stream); diff -urN nwebmail-0.1.77/kandrgetline.c nwebmail-sgp/kandrgetline.c --- nwebmail-0.1.77/kandrgetline.c Thu Jan 1 01:00:00 1970 +++ nwebmail-sgp/kandrgetline.c Fri Apr 6 15:56:06 2001 @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include "header.h" + + + +ssize_t getdelim(char **linebuf, size_t *linebufsz, int delimiter, FILE *file) +{ + + static const int GROWBY = 80; /* how large we will grow strings by */ + + int ch; + int idx = 0; + + if ((file == NULL || linebuf==NULL || *linebuf == NULL || *linebufsz == 0) + && !(*linebuf == NULL && *linebufsz ==0 )) { + errno=EINVAL; + return -1; + } + + if (*linebuf == NULL && *linebufsz == 0){ + *linebuf = malloc(GROWBY); + if (!*linebuf) { + errno=ENOMEM; + return -1; + } + *linebufsz += GROWBY; + } + + while (1) { + ch = fgetc(file); + if (ch == EOF) + break; + /* grow the line buffer as necessary */ + while (idx > *linebufsz-2) { + *linebuf = realloc(*linebuf, *linebufsz += GROWBY); + if (!*linebuf) { + errno=ENOMEM; + return -1; + } + } + (*linebuf)[idx++] = (char)ch; + if ((char)ch == delimiter) + break; + } + + if (idx != 0) + (*linebuf)[idx] = 0; + else if ( ch == EOF ) + return -1; + return idx; +} + + + + + +int getline(char **s, unsigned int *lim, FILE *stream) +{ + return getdelim(s, lim, '\n', stream); +}