include/unistd.h File Reference

#include <sys/time.h>
#include <sys/select.h>

Include dependency graph for unistd.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define _ABLE_CLIB_UNISTD_H   1
#define SEEK_SET   (0)
#define SEEK_CUR   (1)
#define SEEK_END   (2)
#define R_OK   4
#define W_OK   2
#define X_OK   1
#define F_OK   0

Functions

int close (int fd)
 Close a file descriptor.
int dup2 (int oldfd, int newfd)
 Duplicate the file descriptor.
int dup (int oldfd)
 Duplicate the file descriptor.
int pipe (int *pipefd)
 Create a pipe.
ssize_t read (int fd, void *data, size_t size)
 Read from the fd.
ssize_t write (int fd, const void *data, size_t size)
 Write data block to an fd.
off64_t lseek64 (int fd, off64_t off, int whence)
 Seek fd with an 64bit offset.
off_t lseek (int fd, off_t offset, int whence)
 Seek fd with an standard file offset.
ssize_t readlink (const char *path, char *buf, size_t bufsiz)
 Read the value of a symbolic link.
char * getcwd (char *buf, size_t size)
 Get the current working directory.
void _exit (int status)
 Exit a running process without atexit processing.
int getopt (int argc, char *const *argv, const char *options)
 Process command line options.
int access (const char *pathname, int mode)
 Check a users permissions for accessing a file.
int isatty (int desc)
 Check if a file descriptor refers to a terminal.
unsigned int sleep (unsigned int seconds)
 Delay exceution of a task for a given number of seconds.

Variables

char * optarg
 The argument to the returned option, if any.
int opterr
 Flag to inhibit the display of error messages.
int optind
 The index of the last processed option.
int optopt
 If the option character is unrecognised it is stored in this variable.


Define Documentation

#define _ABLE_CLIB_UNISTD_H   1

#define F_OK   0

#define R_OK   4

#define SEEK_CUR   (1)

#define SEEK_END   (2)

#define SEEK_SET   (0)

#define W_OK   2

#define X_OK   1


Function Documentation

void _exit ( int  status  ) 

Exit a running process without atexit processing.

int access ( const char *  pathname,
int  mode 
)

Check a users permissions for accessing a file.

Checks whether the calling process can access a file with a specific mode.

Parameters:
pathname The path to check.
mode The mode to check with.
Returns:
0 for success or -1 and errno set.

int close ( int  fd  ) 

Close a file descriptor.

Close this file descriptor, ending the use of this file descriptor and freeing the resources used if this is the last user of the open stream.

Parameters:
fd FD to close.
Returns:
0 for successful close, otherwise -1 and errno set.

int dup ( int  oldfd  ) 

Duplicate the file descriptor.

This call duplicates the oldfd on to the next available file descriptor. The two file descriptors share the same file pointers and status flags.

File status flags shared are O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_ASYNC, O_DIRECT and O_NONBLOCK.

Note, the man page on my laptop disagrees about the flags-sharing but all other the online references say that the flags are shared.

Parameters:
oldfd The file descriptor to copy from.
Returns:
The new file descriptor if successful, otherwise -1 and errno set appropriately.

int dup2 ( int  oldfd,
int  newfd 
)

Duplicate the file descriptor.

This call duplicates the oldfd on to the newfd. The two file descriptors share the same file pointers and status flags.

File status flags shared are O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_ASYNC, O_DIRECT and O_NONBLOCK.

Note, the man page on my laptop disagrees about the flags-sharing but all other the online references say that the flags are shared.

Parameters:
oldfd The file descriptor to copy from.
newfd The file descriptor to copy oldfd onto.
Returns:
newfd if successful, otherwise -1 and errno set appropriately.

char* getcwd ( char *  buf,
size_t  size 
)

Get the current working directory.

int getopt ( int  argc,
char *const *  argv,
const char *  options 
)

Process command line options.

Process the passed string vector an element at a time serching for valid option switches. Each time the function is called it returns either the option character specified in the options or -1 if there are no more options to process. On each iteration the variables optarg, opterr and optind are updated as apropriate for the option being parsed. If the option character is unrecognise dit is stored in optopt and a '?' character is returned. If opterr is set to 0 the display of the default error message is inhibited.

Parameters:
argc The number of elements in the argument vector argv.
argv The argument vector.
options The short options string.
Returns:
The next option or -1 when no more options.

int isatty ( int  desc  ) 

Check if a file descriptor refers to a terminal.

Parameters:
desc The descriptor to check.
Returns:
1 If the descriptor is open and connected to a terminal, 0 if not.

off_t lseek ( int  fd,
off_t  offset,
int  whence 
)

Seek fd with an standard file offset.

Change the position of the given file descriptor using off and whence. The value of whence controls how the off is interpreted. SEEK_SET indicats off is a direct pointer into the stream, SEEK_CUR means that off is an offset from the current pointer, and SEEK_END is an offset from the file end.

See also:
lseek64
Parameters:
fd File descriptor to change pointers of.
offset Offset to use, see whence for meaning.
whence Type of offset, such as SEEK_SET, SEEK_CUR or SEEK_END.
Returns:
New offset, or -1 to indicate an error, with errno set.

off64_t lseek64 ( int  fd,
off64_t  off,
int  whence 
)

Seek fd with an 64bit offset.

Change the position of the given file descriptor using off and whence. The value of whence controls how the off is interpreted. SEEK_SET indicates off is a direct pointer into the stream, SEEK_CUR means that off is an offset from the current pointer, and SEEK_END is an offset from the file end.

See also:
lseek
Parameters:
fd File descriptor to change pointers of.
off Offset to use, see whence for meaning.
whence Type of offset, such as SEEK_SET, SEEK_CUR or SEEK_END.
Returns:
New offset, or -1 to indicate an error, with errno set.

int pipe ( int *  pipefd  ) 

Create a pipe.

Creates a buffered unidirectional data channel which can be used for interprocess communication. The array contains two file descriptors connected to each end of the pipe. pipefd[0] is the read end of the pipe and pipefd[1] is the write end of the pipe. The written data is buffered by the kernel until it is read from the other end of the pipe.

Parameters:
pipefd array of two integers.
Returns:
zero on success -1 on error and errno set.

ssize_t read ( int  fd,
void *  data,
size_t  size 
)

Read from the fd.

Read data from the given file descriptor into the specified block of memory. The call will try and fill the buffer with data, unless the call would block, and the fd is marked O_NONBLOCK.

This behaves as close as possible to the POSIX standard read call.

See also:
fcntl
Parameters:
fd File descriptor to read from.
data Data block to write data into.
size Size available in data block.
Returns:
positive for size of data, zero for end of file or -1 and errno set with the appropriate error.

ssize_t readlink ( const char *  path,
char *  buf,
size_t  bufsiz 
)

Read the value of a symbolic link.

Obtains the contents of a symbolic link.

Parameters:
path The path of the symbolic link to resolve.
buf The buffer to place teh result in.
bufsiz The size of the buf buffer.
Returns:
The number of characters placed in teh buffer or -1 and errno is set.

unsigned int sleep ( unsigned int  seconds  ) 

Delay exceution of a task for a given number of seconds.

Parameters:
seconds The number of seconds to wait.
Returns:
The number of seconds left to wait if sleep was terminated early.

ssize_t write ( int  fd,
const void *  data,
size_t  size 
)

Write data block to an fd.

Write data to the given file descriptor into the specified block of memory. The call will try and write the whole buffer, unless the call would block and the fd is marked O_NONBLOCK.

This behaves as close as possible to the POSIX standard write call.

See also:
fcntl
Parameters:
fd File descriptor to write to.
data Data block to write data from.
size Size available in data block.
Returns:
positive for size of data, zero for end of file or -1 and errno set with the appropriate error.


Variable Documentation

char* optarg

The argument to the returned option, if any.

int opterr

Flag to inhibit the display of error messages.

int optind

The index of the last processed option.

int optopt

If the option character is unrecognised it is stored in this variable.


Generated on Tue Jan 20 14:29:00 2009 for ABLE LIBC by  doxygen 1.5.6