unistd

Details

int close(

int fildes
)

This function closes the file associated with the specified descriptor.

Parameters

  • fildes The File descriptor fildes.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • EBADF: Invalid file descriptor

int _execve(

const char * path,
char *const argv,
char *const envp
)


void _exit(

int __status
)

This function causes the calling process to exit with the specified exit code.

In this version, named semaphores are not closed in this function.

Returns

This function never returns


int fcntl(

int fildes,
int cmd,

)

This function performs various operations on open files such as:

  • F_DUPFD: duplicate a file descriptor
  • F_GETFD: get the file descriptor flags
  • F_SETFD: set the file descriptor flags
  • F_GETOWN: get the file descriptor owner process ID.

Parameters

  • fildes The file descriptor

  • cmd The operation to perform

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • EBADF: invalid file descriptor
  • ENOTSUP: cmd is not supported for the file descriptor

int fstat(

int fildes,
struct stat * buf
)

This function gets various file statistics for the specified file descriptor.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • EBADF: fildes is invalid
  • EINVAL: buf is NULL

pid_t getpid()

This function returns the process ID of the calling process.

Returns

The process ID of the caller.


pid_t getppid()

This function returns the process ID of the parent process.

Returns

The process ID of the caller’s parent process.


int isatty(

int fildes
)

This function checks to see if fildes is associated with a terminal device.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • ENOTTY: fildes is not associated with a terminal device
  • EBADF: fildes is invalid

const char * old,
const char * new
)

This function creates a hard link between old and new.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • ENOTSUP: operation not supported

off_t lseek(

int fildes,
off_t offset,
int whence
)

This function sets the file offset for fildes using the following values of whence:

  • SEEK_SET: set the offset to offset
  • SEEK_CUR: set the offset to current location plus offset
  • SEEK_END: set the offset to the size of the file plus offset

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • EBADF: fildes is invalid
  • EINVAL: whence is invalid

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 Errno) 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

  • fildes The file descriptor returned by open()

  • buf A pointer to the destination memory (process must have write access)

  • nbyte The number of bytes to read

Returns

The number of bytes actually read of -1 with errno (see Errno) 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 rename(

const char * old,
const char * new
)

This functions renames old to new.

Returns

Zero on success or -1 with errno set to:

  • EEXIST: new already exists
  • EIO: IO error
  • ENOENT: old does not exist
  • EACCESS: old or new cannot be written

int stat(

const char * path,
struct stat * buf
)

This function gets various file statistics for a given file name.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • ENAMETOOLONG: path exceeds PATH_MAX or a component of path exceeds NAME_MAX
  • ENOENT: path does not exist
  • EACCES: search permission is denied for a component of path

const char * old,
const char * new
)

This function creates a hard link between old and new.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • ENOTSUP: operation not supported

const char * name
)

Deletes a file or directory from the filesystem.


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

  • fildes The file descriptor returned by open()

  • buf A pointer to the destination memory (process must have write access)

  • nbyte The number of bytes to read

Returns

The number of bytes actually read of -1 with errno (see Errno) set to:

  • EBADF: fildes is bad
  • EACCES: fildes is on in O_RDONLY mode
  • EIO: IO error
  • EAGAIN: O_NONBLOCK is set for fildes and the device is busy

int access(

const char * path,
int amode
)

This function checks to see if the specified access (amode) is allowed for path.

Returns

Zero on success (ie amode is allowed) or -1 with errno (see Errno) set to:

  • ENAMETOOLONG: path exceeds PATH_MAX or a component of path exceeds NAME_MAX
  • ENOENT: path does not exist
  • EACCES: amode is not allowed for path or search permission is denied for a component of path

int chmod(

const char * path,
mode_t mode
)

This function changes the mode of the specified file or directory.

Returns

Zero on success or -1 with errno (see Errno) set to:

  • EIO: IO Error
  • ENAMETOOLONG: path exceeds PATH_MAX or a component of path exceeds NAME_MAX
  • ENOENT: path does not exist
  • EACCES: search permission is denied for a component of path

int chown(

const char * path,
uid_t uid,
gid_t gid
)

This function changes the mode of the specified file or directory.

Returns

Zero on success or -1 with errno (see Errno) set to:

  • EIO: IO Error
  • ENAMETOOLONG: path exceeds PATH_MAX or a component of path exceeds NAME_MAX
  • ENOENT: path does not exist
  • EACCES: search permission is denied for a component of path

void encrypt(

char block,
int edflag
)

Encrypts a block of data.

Returns

No return value but errno may be set to:

  • ENOSYS: function not supported on this platform

char * crypt(

const char * key,
const char * salt
)


void setkey(

const char * key
)


int fsync(

int fildes
)

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

  • fildes The file descriptor returned by open()

Returns

The number of bytes actually read of -1 with errno (see Errno) set to:

  • EBADF: fildes is bad
  • EIO: IO error
  • EAGAIN: O_NONBLOCK is set for fildes and the device is busy

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

  • fildes The file descriptor returned by open()

  • request The request to the device.

Returns

The number of bytes actually read of -1 with errno (see Errno) set to:

  • EBADF: fildes is bad
  • EIO: IO error
  • EAGAIN: O_NONBLOCK is set for fildes and the device is busy

int lstat(

const char * path,
struct stat * buf
)

This function is equivalent to stat() except path refers to a symbolic link.

Returns

Zero on success or -1 on error with errno (see Errno) set to:

  • ENAMETOOLONG: path exceeds PATH_MAX or a component of path exceeds NAME_MAX
  • ENOENT: path does not exist
  • EACCES: search permission is denied for a component of path

int mkdir(

const char * path,
mode_t mode
)

This function creates a new directory.

Parameters

  • path Path to the new directory

  • mode Ignored

Returns

Zero on success or -1 with errno (see Errno) set to:

  • ENOENT: path is an empty string or the parent directory cannot be found
  • EEXIST: path already exists
  • ENOSPC: Not enough space on the disk to add a new directory

int rmdir(

const char * path
)

This function removes the directory specified by path.

Returns

Zero on success or -1 with errno (see Errno) set to:

  • ENOENT: path is an empty string or the parent directory cannot be found
  • EEXIST: path already exists
  • ENOTDIR: path is not a directory
  • ENOTEMPTY: path is not an empty directory

unsigned int sleep(

unsigned int seconds
)

This function causes the calling thread to sleep for seconds seconds.

Returns

0


int usleep(

useconds_t useconds
)

Causes the calling thread to sleep for useconds microseconds.

If useconds is greater than a threshold, the calling thread will yield the processor.

Returns

0 or -1 for an error with errno (see Errno) set to:

  • EINVAL: useconds is greater than 1 million.

X

Thanks for Coming!

Subscribe to news and updates