user_write()
spio_t_error_code user_write( void *user_data, void *buf, size_t *pbuf_size, spio_t_bits write_options );
This is the prototype for one of the methods of user defined streams. It is used when SICStus wants to write data to the user defined stream.
SP_create_stream()
.
*pbuf_size
should be set to the number of
bytes actually written, which should always be positive for
successful return.
Note that buffer size is measured in bytes also for text streams.
SPIO_DEVICE_WRITE_OPTION_BINARY
*pbuf_size
bytes.
SPIO_DEVICE_WRITE_OPTION_TEXT
spio_t_wchar
. Note that *buf_size
is size in
bytes, not in characters.
SPIO_DEVICE_WRITE_OPTION_NONBLOCKING
SPIO_E_WOULD_BLOCK
code.
If your user_write
will never block, you can ignore this value.
You should return SPIO_E_NOT_SUPPORTED
if user_write
cannot support non-blocking write.
On success, *pbuf_size
should be assigned to with the number of
bytes written and SPIO_S_NOERR
or some other success code
returned. On success, something must have been written, e.g.
*pbuf_size
must be set to a positive value.
On failure, return a SPIO error code. Error codes with special meaning
for user_write
:
SPIO_E_END_OF_FILE
SPIO_E_WOULD_BLOCK
SPIO_DEVICE_WRITE_OPTION_NONBLOCKING
was set but the operation
would block.
SPIO_E_NOT_SUPPORTED
SPIO_DEVICE_WRITE_OPTION_NONBLOCKING
, was passed.
Other error codes may also be returned.
Should write up to *buf_size
bytes of data from
buf
. Data could be either bytes, for a binary device, or wide
characters, for a text device.
cpg-ref-SP_create_stream. Defining a New Stream.