# HG changeset patch # User mmj # Date 1082668462 -36000 # Node ID 91830455b49c43e454e7b7d63cdb461308af5b31 # Parent 035484b0da60fd0a2d030c895f61a33aa5d650c5 mygetline is turned into myfgetline since it works on FILE *'s and mygetline(int fd) was added. diff -r 035484b0da60 -r 91830455b49c src/do_all_the_voodo_here.c --- a/src/do_all_the_voodo_here.c Fri Apr 23 03:41:20 2004 +1000 +++ b/src/do_all_the_voodo_here.c Fri Apr 23 07:14:22 2004 +1000 @@ -63,7 +63,7 @@ if((strlen(hdrline) == 1) && (hdrline[0] == '\n')){ if(hdradd) { fflush(out); - while((line = mygetline(hdradd))) { + while((line = myfgetline(hdradd))) { fputs(line, out); free(line); } @@ -87,7 +87,7 @@ } /* Just print the rest of the mail */ - while((line = mygetline(in))) { + while((line = myfgetline(in))) { fputs(line, out); free(line); } @@ -96,7 +96,7 @@ /* No more, lets add the footer if one*/ if(footers) { - while((line = mygetline(footers))) { + while((line = myfgetline(footers))) { fputs(line, out); free(line); } diff -r 035484b0da60 -r 91830455b49c src/gethdrline.c --- a/src/gethdrline.c Fri Apr 23 03:41:20 2004 +1000 +++ b/src/gethdrline.c Fri Apr 23 07:14:22 2004 +1000 @@ -19,12 +19,12 @@ int ch; for(;;) { - line = mygetline(infile); + line = myfgetline(infile); if(line == NULL) return NULL; ch = getc(infile); ungetc(ch, infile); if(ch == '\t' || ch == ' ') { - nextline = mygetline(infile); + nextline = myfgetline(infile); tmp = retstr; retstr = concatstr(3, retstr, line, nextline); free(tmp); free(line); free(nextline); diff -r 035484b0da60 -r 91830455b49c src/mlmmj-recieve.c --- a/src/mlmmj-recieve.c Fri Apr 23 03:41:20 2004 +1000 +++ b/src/mlmmj-recieve.c Fri Apr 23 07:14:22 2004 +1000 @@ -74,7 +74,7 @@ exit(EXIT_FAILURE); } - while((line = mygetline(stdin))) { + while((line = myfgetline(stdin))) { writen(fd, line, strlen(line)); fsync(fd); free(line); diff -r 035484b0da60 -r 91830455b49c src/mlmmj-unsubscribe.c --- a/src/mlmmj-unsubscribe.c Fri Apr 23 03:41:20 2004 +1000 +++ b/src/mlmmj-unsubscribe.c Fri Apr 23 07:14:22 2004 +1000 @@ -244,7 +244,7 @@ exit(EXIT_FAILURE); } - while((buf = mygetline(subfile))) { + while((buf = myfgetline(subfile))) { if(strncasecmp(buf, address, strlen(address)) != 0) writen(subwritefd, buf, strlen(buf)); free(buf); diff -r 035484b0da60 -r 91830455b49c src/mygetline.c --- a/src/mygetline.c Fri Apr 23 03:41:20 2004 +1000 +++ b/src/mygetline.c Fri Apr 23 07:14:22 2004 +1000 @@ -1,4 +1,5 @@ /* Copyright (C) 2004 Morten K. Poulsen + * Copyright (C) 2004 Mads Martin Joergensen * * $Id$ * @@ -9,9 +10,10 @@ #include #include #include +#include #include "mygetline.h" -char *mygetline(FILE *infile) +char *myfgetline(FILE *infile) { size_t buf_size = BUFSIZE; /* initial buffer size */ size_t buf_used; @@ -39,12 +41,38 @@ } } +char *mygetline(int fd) +{ + size_t i = 0, buf_size = BUFSIZE; /* initial buffer size */ + char *buf = malloc(buf_size); + int ch; + + buf[0] = '\0'; + while(read(fd, &ch, 1) > 0) { + if(i == buf_size - 1) { + buf_size *= 2; + buf = realloc(buf, buf_size); + } + buf[i++] = ch; + if(ch == '\n') { + buf[i] = '\0'; + return buf; + } + } + + if(buf[0]) { + buf[i] = '\0'; + return buf; + } + + return NULL; +} #if 0 int main(int argc, char **argv) { char *str; - while((str = mygetline(stdin))) { + while((str = mygetline(fileno(stdin)))) { printf("%s", str); free(str); } diff -r 035484b0da60 -r 91830455b49c src/subscriberfuncs.c --- a/src/subscriberfuncs.c Fri Apr 23 03:41:20 2004 +1000 +++ b/src/subscriberfuncs.c Fri Apr 23 07:14:22 2004 +1000 @@ -26,7 +26,7 @@ exit(EXIT_FAILURE); } - while ((buf = mygetline(subfile))) { + while ((buf = myfgetline(subfile))) { while (buf[0] && isspace(buf[strlen(buf)-1])) buf[strlen(buf)-1] = '\0'; if (strcasecmp(buf, address) == 0) {