Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-239
writeread (supplementary)
writeread (supplementary)
The writeread function writes a message and then reads the resulting input. More
specifically, writeread:
1. Writes a number of bytes from a buffer to a file
2. Begins to read a number of bytes from the file to the buffer
3. Causes suspension of C program execution until the read operation is complete
4. Returns either the number of bytes that it has read or an end-of-file or error
indication
The file can be a disk file, a terminal, or a process.
file_des
is the descriptor of a file opened for alternate I/O.
buf
points to the buffer used both for the write and the subsequent read.
write_bytes
specifies the number of bytes to write from the buffer.
read_bytes
specifies the maximum number of bytes to read into the buffer.
Return Value
is the number of bytes read if the operation is successful. If writeread encounters the
end of the file, it returns zero and sets errno to 1. If an error occurs, writeread returns
-1 and sets errno to the Guardian error number.
Usage Guidelines
You can use the writeread function only with files that are opened for alternate I/O
and read-write access.
You should set errno to zero before each call to writeread.
You can use writeread with both text and binary files. The function appends the data
in buf to any buffered output data and then flushes the buffer.
#include <fcntlh>
short writeread(short file_des, char *buf, short write_bytes,
short read_bytes);