Detailed Description

Functions

int close (int fildes)
 
int open (const char *name, int flags,...)
 
int read (int fildes, void *buf, size_t nbyte)
 
int write (int fildes, const void *buf, size_t nbyte)
 
int ioctl (int fildes, int request,...)
 

Function Documentation

int close ( int  fildes)

This function closes the file associated with the specified descriptor.

Parameters
fildesThe File descriptor fildes.
Returns
Zero on success or -1 on error with errno (see Error Numbers) set to:
  • EBADF: Invalid file descriptor
int ioctl ( int  fildes,
int  request,
  ... 
)

This function performs a control request on the device associated with fildes. request is specific to the device. The value of request determines what value should be passed as the ctl argument.

Parameters
fildesThe file descriptor returned by open()
requestThe request to the device.
Returns
The number of bytes actually read of -1 with errno (see Error Numbers) set to:
  • EBADF: fildes is bad
  • EIO: IO error
  • EAGAIN: O_NONBLOCK is set for fildes and the device is busy
int open ( const char *  name,
int  flags,
  ... 
)

This function opens a file with flags being the OR'd combination of:

  • O_RDONLY, O_WRONLY or O_RDWR
  • O_NONBLOCK, O_CREAT, O_EXCL, O_TRUNC

If the O_CREAT flag is set, the third argument should specify the mode as a mode_t. The bits used with the mode are:

  • S_IRWXU: User read/write/execute
  • S_IRUSR: User read
  • S_IWUSR: User write
  • S_IXUSR: User execute
  • S_IRWXG: Group read/write/execute
  • S_IRGRP: Group read (groups not implemented)
  • S_IWGRP: Group write (groups not implemented)
  • S_IXGRP: Group execute (groups not implemented)
  • S_IRWXO: Other read/write/execute
  • S_IROTH: Other read
  • S_IWOTH: Other write
  • S_IXOTH: Other execute
Returns
Zero on success or -1 on error with errno (see Error Numbers) set to:
  • ENAMETOOLONG: name exceeds PATH_MAX or a component of name exceeds NAME_MAX
  • ENOENT: name could not be found
  • EIO: IO error
  • EEXIST: name already exists and flags is not set to overwrite
  • ENOMEM: not enough memory to open another file
    • ENOTDIR: the path to name does not exist
    • EFBIG: size error with the file (file is likely corrupt)
int read ( int  fildes,
void *  buf,
size_t  nbyte 
)

This function reads nbyte bytes from fildes to the memory location pointed to by buf.

read() is always a synchronous call which is either blocking or non-blocking depending on the value of O_NONBLOCK for fildes.

Parameters
fildesThe file descriptor returned by open()
bufA pointer to the destination memory (process must have write access)
nbyteThe number of bytes to read
Returns
The number of bytes actually read of -1 with errno (see Error Numbers) set to:
  • EBADF: fildes is bad
  • EACCESS: fildes is on in O_WRONLY mode
  • EIO: IO error
  • EAGAIN: O_NONBLOCK is set for fildes and no new data is available
int write ( int  fildes,
const void *  buf,
size_t  nbyte 
)

This function writes nbyte bytes fildes from the memory location pointed to by buf.

write() is always a synchronous call which is either blocking or non-blocking depending on the value of O_NONBLOCK for fildes.

Parameters
fildesThe file descriptor returned by open()
bufA pointer to the destination memory (process must have write access)
nbyteThe number of bytes to read
Returns
The number of bytes actually read of -1 with errno (see Error Numbers) set to:
  • EBADF: fildes is bad
  • EACCESS: fildes is on in O_RDONLY mode
  • EIO: IO error
  • EAGAIN: O_NONBLOCK is set for fildes and the device is busy