src/hdrh/hdr_histogram_log.c
static ssize_t hdr_getline(char** lineptr, FILE* stream)
{
    if (stream == NULL)
    {
        return -1;
    }

    size_t allocation = 128;
    size_t used = 0;

    char* scratch = NULL;
    for (;;)
    {
        allocation += allocation;

        char* before = scratch;
        scratch = realloc(scratch, allocation);
        if (scratch == NULL)
        {
            if (before)
            {
                free(before);
            }
            return -1;
        }

        size_t wanted = allocation - used - 1;
        size_t read_length = hdr_read_chunk(scratch + used, wanted, '\n', stream);
        used += read_length;


        if (read_length < wanted || scratch[used - 1] == '\n' || scratch[used - 1] == '\0')
        {
            scratch[used] = '\0';
            *lineptr = scratch;
            return used;
        }
    }
}
/* Note that this version of getline assumes lineptr is valid. */
Note that this version of getline assumes lineptr is valid.
Note that this version of getline assumes lineptr is valid .
static ssize_t hdr_getline(char** lineptr, FILE* stream)
{
    if (stream == NULL)
    {
        return -1;
    }
    size_t allocation = 128;
    size_t used = 0;
    char* scratch = NULL;
    for (;;)
    {
        allocation += allocation;
        char* before = scratch;
        scratch = realloc(scratch, allocation);
        if (scratch == NULL)
        {
            if (before)
            {
                free(before);
            }
            return -1;
        }
        size_t wanted = allocation - used - 1;
        size_t read_length = hdr_read_chunk(scratch + used, wanted, '\n', stream);
        used += read_length;
        if (read_length < wanted || scratch[used - 1] == '\n' || scratch[used - 1] == '\0')
        {
            scratch[used] = '\0';
            *lineptr = scratch;
            return used;
        }
    }
}
static ssize_t hdr_getline ( char * * lineptr , FILE * stream ) { if ( stream == NULL ) { return -1 ; } size_t allocation = 128 ; size_t used = 0 ; char * scratch = NULL ; for ( ; ; ) { allocation += allocation ; char * before = scratch ; scratch = realloc ( scratch , allocation ) ; if ( scratch == NULL ) { if ( before ) { free ( before ) ; } return -1 ; } size_t wanted = allocation - used - 1 ; size_t read_length = hdr_read_chunk ( scratch + used , wanted , ' \n ' , stream ) ; used += read_length ; if ( read_length < wanted || scratch [ used - 1 ] == ' \n ' || scratch [ used - 1 ] == ' \0 ' ) { scratch [ used ] = ' \0 ' ; * lineptr = scratch ; return used ; } } }
Note that this version of getline assumes lineptr is valid.
Note that this version of getline assumes lineptr is valid .