5.14.3.3
Code:
FILE* fdevopen (int(*put)(char), int(*get)(void), int opts __attribute__ ((unused)));
This function is a replacement for fopen().
It opens a stream for a device where the actual device implementation needs to be provided by the application. If successful, a pointer to the structure for the opened stream is returned. Reasons for a possible failure currently include that neither the put nor the get argument have been provided, thus attempting to open a stream with no IO intent at all, or that insufficient dynamic memory is available to establish a new stream.
If the put function pointer is provided, the stream is opened with write intent. The function passed as put shall take one character to write to the device as argument, and shall return 0 if the output was successful, and a nonzero value if the character could not be sent to the device.
If the get function pointer is provided, the stream is opened with read intent. The function passed as get shall take no arguments, and return one character from the device, passed as an int type. If an error occurs when trying to read from the device, it shall return -1.
If both functions are provided, the stream is opened with read and write intent. The first stream opened with read intent is assigned to stdin, and the first one opened with write intent is assigned to both, stdout and stderr.
Lesezeichen