Guardian Native C Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

Guardian Native C Library Calls (f) fgets(3)
NAME
fgets - Gets a string from a stream
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <stdio.h>
char *fgets(
char *string,
int n,
FILE *stream);
PARAMETERS
string Points to a string to receive bytes.
n Species an upper bound on the number of bytes to read.
stream Points to the FILE structure of an open file.
DESCRIPTION
The fgets() function reads bytes from the data pointed to by the stream parameter into the array
pointed to by the string parameter. Data is read until n-1 bytes have been read, until a newline
character is read and transferred to string, or until an EOF (End-of-File) condition is encountered.
The string is then terminated with a NULL character.
RETURN VALUES
If the end of the file is encountered and no characters have been read, no characters are
transferred to string and a null pointer is returned. If a read error occurs, a null pointer is
returned. Otherwise, string is returned.
ERRORS
If any of these conditions occurs, the fgets() function sets errno to the corresponding value:
[EAGAIN] The O_NONBLOCK flag is set for the underlying input stream and the process
would be delayed by the read operation.
[EBADF] The file descriptor underlying the input stream is not a valid file descriptor or is
not open for reading.
[EINTR] The read operation was interrupted by a signal which was caught and no data
was transferred.
[ENXIO] A request was made on a nonexistent device, or the request was outside the
capabilities of the device.
[EIO] The call is attempting to read from the process’s controlling terminal and either
the process is ignoring or blocking the SIGTTIN signal or the process group is
orphaned.
527192-018 Hewlett-Packard Company 235