Ticket #4647: fgetln.patch

File fgetln.patch, 859 bytes (added by joshe, 15 years ago)
  • src/libs/bsd/fgetln.c

    commit 895443883937da997e5bfdb26ae91f28472506bd
    Author: Joshua R. Elsasser <joshua@elsasser.org>
    Date:   Sat Sep 26 17:07:54 2009 +0000
    
        Fix fgetln() in libbsd to actually return the length of the string.
    
    diff --git a/src/libs/bsd/fgetln.c b/src/libs/bsd/fgetln.c
    index 0d6dd4b..65b3194 100644
    a b fgetln(FILE *stream, size_t *_length)  
    3434
    3535    line = sBuffer;
    3636    left = sBufferSize;
     37    if (_length != NULL)
     38        *_length = 0;
    3739
    3840    for (;;) {
    3941        line = fgets(line, left, stream);
    fgetln(FILE *stream, size_t *_length)  
    4446        }
    4547
    4648        length = strlen(line);
     49        if (_length != NULL)
     50            *_length += length;
    4751        if (line[length - 1] != '\n' && length == sBufferSize - 1) {
    4852            // more data is following, enlarge buffer
    4953            char *newBuffer = realloc(sBuffer, sBufferSize + LINE_LENGTH);