_dos_write
Writes to a file.
Defined in header <dos.h>
Syntax
#include <dos.h>
unsigned _dos_write(int handle, void far *buf,
unsigned len, unsigned *nwritten);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
_dos_write uses DOS function 0x40 to write len bytes from the buffer pointed to by the far pointer huf to the file associated with handle.
_dos_write does not translate a linefeed character (LF) to a CR/LF pair because all its files are binary files.
The actual number of bytes written is stored at the location pointed to by nwritten. If the number of bytes actually written is less than that requested, the condition should be considered an error and probably indicates a full disk.
For disk files, writing always proceeds from the current file pointer. On devices, bytes are directly sent to the device.
Return value
On successful completion, _dos_read returns 0. Otherwise, it returns the DOS error code and the global variable errno is set to one of the following:
EACCES Permission denied
| EBADF | Bad file number |
See also
Example
#include <dos.h>
#include <string.h>
#include <stdio.h>
int* main(void)
{
unsigned count;
int handle;
char buf[ll] = "0123456789";
/* create a file containing 10 bytes */
if (_dos_creat("DUMMY.FIL", _A_NORMAL, &handle) != 0) {
perror("Unable to create DUMMY.FIL");
return 1;
}
if {_dos_write (handle, buf, strlen(buf), &count) != 0) {
perror ("Unable to write to DUMMY.FIL");
return 1;
}
_dos_close (handle); /* close the file */
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `dos write` read as `_dos_write`
Stable link: /3.1/dos.h/_dos_write/
· short form /3.1/_dos_write/