Definition | #include <stdio.h> int write(int fp, const char *buf, int n);
SAM files are always processed as text files with elementary functions. | |
Parameters | int fd File descriptor of the output file. A file descriptor (positive integer) is the result of a successful const char *buf Pointer to the area containing the data to be written to the output file. int n Number of bytes to be written to the file. There is no guarantee that | |
Return val. | Number of bytes actually written | |
if successful. | ||
-1 | Nothing was written due to one of the following errors:
| |
Notes | After each You should use the The data is not written immediately to the external file but is stored in an internal C buffer (see section “Buffering” (Basic terms)). Control characters for white space (\n, \t, etc.) are converted to their appropriate effect when output to text files, depending on the type of text file (see section “White space” (Basic terms)). The following applies in the case of text files with SAM access mode and variable record length for which a maximum record length is also specified: When the O_NOSPLIT specification was entered for In the case of files with record-oriented input/output (record I/O), i.e. when the specification O_RECORD was entered for | |
Example | The following program copies the standard input (file descriptor 0) to the standard output (file descriptor 1). If you utilize the redirection mechanism, you can use this program to copy from any source to any destination. BUFSIZ (8192 bytes) is defined in the include file <stdio.h>. #include <stdio.h> int main(void) { char buf[BUFSIZ]; int n; while((n = read(0, buf, sizeof(buf))) > 0) write(1, buf, n); return 0; } | |
See also | read, open, open64, creat, creat64 |