The Open Source Swiss Army Knife

/code/c/unix_c/unbufferedIO/
/code/c/unix_c/unbufferedIO/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /unix_c   /unbufferedIO 
Permalink: unbufferedIO.htm
Title: add
article options : please login   |  print view

file descriptor I/O routines
  1. read
  2. write

read

reads data from a file corresponding to a file descriptor

#include 
ssize_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.

write

The write() system call is used to write data to the file corresponding to a file descriptor.

#include

ssize_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
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top