Sun Java System Web Server 7.0 Update 4 NSAPI Developer's Guide

util_getline() Function

The util_getline function scans the specified file buffer to find a line feed or carriage return/line feed terminated string. The string is copied into the specified buffer, and NULL-terminates it. The function returns a value that indicates whether the operation stored a string in the buffer, encountered an error, or reached the end of the file.

Use this function to scan lines out of a text file, such as a configuration file.


int util_getline(filebuf *buf, int lineno, int maxlen, char *line);

Return Values

0 if successful, line contains the string.

1 if the end of file is reached, line contains the string.

-1 if an error occurs, line contains a description of the error.


filebuf *buf is the file buffer to be scanned.

int lineno is used to include the line number in the error message when an error occurs. The caller is responsible for making sure the line number is accurate.

int maxlen is the maximum number of characters that can be written into l.

char *l is the buffer in which to store the string. The user is responsible for allocating and deallocating line.