readln()
Read a line of data from a PSL file or process channel.
Syntax
Parameter
Parameter | Definition |
---|---|
channel | process I/O channel number from which the readln() function is to read data |
Description
The readln() function reads the next line of data from channel and returns it. The readln() function returns the value EOF (NULL) on end-of-file or error and sets errno = 55 (E_PSL_READ_FAILED) on end-of-file.
Channels are created by calling the fopen() or popen() function. (See fopen() or popen().)
To enforce serialization for shared channels, no two reader processes (that is, read() or readln() functions) can be blocked on the same channel. The second reader process that attempts to block on the shared channel will fail, returning the NULL string and setting the PSL variable errno to E_PSL_BUSY_CHANNEL.
Another possible shared channel failure can be caused by a close() function being executed against a channel that also has a blocked reader process. The close() function will cause the reader process to return the NULL string and set errnoto E_PSL_UNBLOCKED_BY_CLOSE.
Limitation
The readln() function has a line limitation of 4K when executed against files opened with the fopen() function. Thereadln() function may truncate lines longer than 4K. This limitation does not apply to channels opened using the popen()function.
Example
The following example reads lines of text from a file or process channel:
if (chan_exists(chan)) {
data=readln(chan);
#The readln() function sets errno = 55 (E_PSL_READ_FAILED) on end-of-file
while ( errno != 55) {
printf("%s\n",data);
data=readln(chan);
}
close(chan);
}