readln()
含义:Read a line of data from a PSL file or process channel(从PSL文件或进程管道读取一行数据)
Format
read(channle)
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.
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 errno to E_PSL_UNBLOCKED_BY_CLOSE.
The readln() function has a line limitation of 4K when executed against files opened with the fopen() function. The readln() function may truncate lines longer than 4K. This limitation does not apply to channels opened using the popen() function.
Example
Code:
chan=fopen("/etc/passwd","r");
if (chan_exists(chan)) {data=readln(chan);#the readln() function sets errno=55(E_PSL_READ_FAILED) on end-of-filewhile (errno != 55) {printf("%s\n",data);data=readln(chan);}close(chan);
}
Output: