Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/libbb/get_line_from_file.c

    r2725 r3232  
    1212#include "libbb.h"
    1313
    14 /* This function reads an entire line from a text file, up to a newline
    15  * or NUL byte, inclusive.  It returns a malloc'ed char * which
    16  * must be free'ed by the caller.  If end is NULL '\n' isn't considered
    17  * end of line.  If end isn't NULL, length of the chunk is stored in it.
    18  * If lineno is not NULL, *lineno is incremented for each line,
    19  * and also trailing '\' is recognized as line continuation.
    20  *
    21  * Returns NULL if EOF/error. */
    22 char* FAST_FUNC bb_get_chunk_with_continuation(FILE *file, int *end, int *lineno)
     14char* FAST_FUNC bb_get_chunk_from_file(FILE *file, int *end)
    2315{
    2416    int ch;
    25     int idx = 0;
     17    unsigned idx = 0;
    2618    char *linebuf = NULL;
    27     int linebufsz = 0;
    2819
    2920    while ((ch = getc(file)) != EOF) {
    3021        /* grow the line buffer as necessary */
    31         if (idx >= linebufsz) {
    32             linebufsz += 256;
    33             linebuf = xrealloc(linebuf, linebufsz);
    34         }
     22        if (!(idx & 0xff))
     23            linebuf = xrealloc(linebuf, idx + 0x100);
    3524        linebuf[idx++] = (char) ch;
    36         if (!ch)
     25        if (ch == '\0')
    3726            break;
    38         if (end && ch == '\n') {
    39             if (lineno == NULL)
    40                 break;
    41             (*lineno)++;
    42             if (idx < 2 || linebuf[idx-2] != '\\')
    43                 break;
    44             idx -= 2;
    45         }
     27        if (end && ch == '\n')
     28            break;
    4629    }
    4730    if (end)
     
    5841    }
    5942    return linebuf;
    60 }
    61 
    62 char* FAST_FUNC bb_get_chunk_from_file(FILE *file, int *end)
    63 {
    64     return bb_get_chunk_with_continuation(file, end, NULL);
    6543}
    6644
Note: See TracChangeset for help on using the changeset viewer.