Sun Java System Web Server 6.1 SP11 NSAPI Programmer's Guide


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 of a text file, such as a configuration file.


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


0 if successful; line contains the string.

1 if the end of file was reached; line contains the string.

-1 if an error occurred; 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.

See Also

util_can_exec, util_env_create, util_hostname