delorie.com/djgpp/doc/libc/libc_867.html | search |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#include <io.h> ssize_t _write(int fildes, const void *buf, size_t nbyte); |
This is a direct connection to the MS-DOS write function call, int
0x21, %ah = 0x40. No conversion is done on the data; it is written as
raw binary data. This function can be hooked by the File-system
extensions, see File System Extensions. If you don't want this,
you should use _dos_write
instead, see _dos_write.
The number of bytes written, or -1 (and errno
set) in case of
failure.
Note that DOS doesn't return an error indication when the target disk is
full; therefore if the disk fills up while the data is written,
_write
does not return -1, it returns the number of
bytes it succeeded to write. If you need to detect the disk full
condition reliably, call _write
again to try to write the rest of
the data. This will cause DOS to return zero as the number of written
bytes, and then _write
will return -1 and set errno
to ENOSPC
. The example below shows one way of doing this.
ANSI/ISO C | No |
POSIX | No |
This example shows how to call _write
in a way which ensures that
errno
will be set to ENOSPC
if the target filesystem is or
becomes full:
char *buf_ptr; /* the buffer to write */ size_t buf_len; /* the number of bytes to write */ int desc; /* the file descriptor to write to */ while (buf_len > 0) { int written = _write (desc, buf_ptr, buf_len); if (written <= 0) break; buf_ptr += written; buf_len -= written; } |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster | delorie software privacy |
Copyright © 2004 | Updated Apr 2004 |