Open System Services System Calls Reference Manual (G06.28+, H06.05+)

System Functions (s and S) spt_fgetsx(2)
NAME
spt_fgetsx - Gets a string from a stream (thread-aware version)
LIBRARY
G-series native OSS processes: /G/system/sysnn/zsptsrl
H-series OSS processes: /G/system/zdllnnn/zsptdll
SYNOPSIS
[#include <stdio.h>]
#include <spthread.h>
char *spt_fgetsx (
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 le.
DESCRIPTION
The spt_fgetsx( ) function is the thread-aware version of the fgets() function.
The spt_fgetsx( ) 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 new-
line character is read and transferred to string, or until an end-of-le EOF condition is encoun-
tered. The string is then terminated with a NULL character.
NOTES
The macro to map fgets() to spt_fgetsx( ) is available in C applications when
SPT_THREAD_AWARE_NONBLOCK has been dened in the following manner before
including spthread.h:
#dene SPT_THREAD_AWARE_NONBLOCK
The alias to link fgets() to spt_fgetsx() is available in C++ applications when
SPT_THREAD_AWARE_PRAGMA_NONBLOCK has been dened in the following manner
before including spthread.h:
#dene SPT_THREAD_AWARE_PRAGMA_NONBLOCK
RETURN VALUES
If the end of the le 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.
If the le descriptor underlying stream becomes invalid (is closed by another thread), EOF is
returned with an errno value of [EBADF]. If a signal is received via the pthread_kill() function
and is not blocked, ignored, or handled, EOF is returned with an errno value of [EINTR].
ERRORS
If any of these conditions occur, the spt_fgetsx() function sets errno to the corresponding value:
[EAGAIN] The O_NONBLOCK ag is set for the underlying input stream and the process
would be delayed by the read operation.
527186-007 Hewlett-Packard Company 7131