Main Page | Data Structures | File List | Globals

libgu/getline.c File Reference

read lines of unimited length from a file efficiently More...

#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include "gu.h"

Functions

char * gu_getline (char *line, int *space_available, FILE *fstream)
 read lines of unlimited length from a file efficiently


Detailed Description

read lines of unimited length from a file efficiently


Function Documentation

char* gu_getline char *  line,
int *  space_available,
FILE *  fstream
 

read lines of unlimited length from a file efficiently

This function is used to read configuration file lines. It avoids the problem of buffers that are too small. The parameter "line" points to a buffer in gu_alloc()ed memory. On the first call this may be a NULL pointer. If it is too small, a new, longer one will be obtained and "space_available" will be updated. The new buffer is returned. The caller should initialy set "line_available" to a little bigger than the LIKELY line length. Notice that on EOF the line is automatically freed. If you don't read until EOF you must manually free the line. The file will still be open.

Use the function like this:

int line_available = 80;
char *line = NULL;

while((line = gu_getline(line, &line_available, stdin))
        {

        }


Generated on Fri Feb 20 15:17:52 2004 for PPR Libraries by doxygen 1.3.5