Next: , Previous: fget_rec_delete, Up: I/O


7.3 fget_rec_read

Read a record of arbitrary length.

Synopsis

     #include <suplib/io.h>
     
     
     
char *fget_rec_read( FILE *fin, void *recbuf, size_t start );

Parameters

FILE *fin
the input stream from which to read the data
void *recbuf
an fget_rec buffer structure, created by fget_rec_new
size_t start
the zero-based index into the buffer where the incoming record should be stored

Description

fget_rec_read reads data from the passed stream until either an end of line character or the end of file is reached. It removes any end of line character from the string. It writes the data into a user provided buffer, and extends the buffer as necessary to hold a complete input record. The end of the buffer is terminated with a '\0'. The buffer structure should created by fget_rec_new and deleted with fget_rec_delete. The data is written into the buffer at the position specified by the start parameter. If the starting position is beyond the end of the buffer the buffer is extended and the string currently in the buffer is extended with spaces to have length start. This happens even if there is no new data available in the input stream.

Returns

It normally returns a pointer to the data that has been read. Upon end of file, it returns NULL. If it cannot extend the record, it returns NULL and sets errno to ENOMEM. If there was a read error on the stream, it returns NULL and the stream's error flag is set (use ferror to check it).

Author

Diab Jerius