O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading and Writing

The UNIX kernel readies a file for I/O by giving you a file descriptor, which is returned by open(2) or creat(2). The file descriptor might represent an I/O device, a socket or, most often, a regular file. The I/O semantics vary somewhat, depending on what it is that your program is interacting with. This will be noted in a few places as you are introduced to the system calls for I/O.

Introducing read(2) and write(2)

These are perhaps the most basic of all UNIX I/O system calls. Their function synopsis is as follows:

#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>

ssize_t read(int fd,void *buf,size_t nbytes);

ssize_t write(int fd,const void *buf,size_t nbytes);

The read(2) and write(2) calls take the same ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required