|
|||||
| | |||||
| file descriptor I/O routines |
|---|
reads data from a file corresponding to a file descriptor
#includessize_t read(int fd, void *buf, size_t count);
The second argument is a pointer to a buffer to copy the data from.
read() has the same return values as write.
you can see the same source file as above for an example of read(), too. That file opens an existing file from the command line, creates a pipe, reads from the file descriptor created by the open() call, and printf's it in 16-byte buffer increments to STDOUT with, by formatting the read buffer with %s.
The write() system call is used to write data to the file corresponding to a file descriptor.
#includessize_t write(int fd, const void *buf, size_t count);
The first argument is the file descriptor which was returned from a previous open/pipe ? call. (An example of passing a file descriptor can be found in pipe.c. The second argument is a pointer for the buffer which will hold the write operation. The third argument is the number of bytes to write.
write() returns the number of bytes read or -1 if an error occurs.
| Leave a Reply |