unistd

Prototypes

  • public intclose(int fildes)
  • public int_execve(const char * path,char *const argv,char *const envp)
  • public void_exit(int __status)
  • public intfcntl(int fildes,int cmd,...)
  • public intfstat(int fildes,structstat* buf)
  • public pid_tgetpid()
  • public pid_tgetppid()
  • public intisatty(int fildes)
  • public intlink(const char * old,const char * new)
  • public off_tlseek(int fildes,off_t offset,int whence)
  • public intopen(const char * name,int flags,...)
  • public intread(int fildes,void * buf,size_t nbyte)
  • public intrename(const char * old,const char * new)
  • public intstat(const char * path,struct stat * buf)
  • public intsymlink(const char * old,const char * new)
  • public intunlink(const char * name)
  • public intwrite(int fildes,const void * buf,size_t nbyte)
  • public intaccess(const char * path,int amode)
  • public intchmod(const char * path,mode_t mode)
  • public intchown(const char * path,uid_t uid,gid_t gid)
  • public voidencrypt(char block,int edflag)
  • public char *crypt(const char * key,const char * salt)
  • public voidsetkey(const char * key)
  • public intfsync(int fildes)
  • public intioctl(int fildes,int request,...)
  • public intlstat(const char * path,structstat* buf)
  • public intmkdir(const char * path,mode_t mode)
  • public intrmdir(const char * path)
  • public unsigned intsleep(unsigned int seconds)
  • public intusleep(useconds_t useconds)

Details

public intclose(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

public int_execve(const char * path,char *const argv,char *const envp)


public 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


public intfcntl(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


public intfstat(int fildes,structstat* 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


public pid_tgetpid()

This function returns the process ID of the calling process.

Returns

The process ID of the caller.


public pid_tgetppid()

This function returns the process ID of the parent process.

Returns

The process ID of the caller's parent process.


public intisatty(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


public intlink(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

public off_tlseek(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


public intopen(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)


public intread(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


public intrename(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


public intstat(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


public intsymlink(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

public intunlink(const char * name)

Deletes a file or directory from the filesystem.


public intwrite(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


public intaccess(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


public intchmod(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


public intchown(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


public voidencrypt(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

public char *crypt(const char * key,const char * salt)


public voidsetkey(const char * key)


public intfsync(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()

  • 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


public intioctl(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


public intlstat(const char * path,structstat* 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


public intmkdir(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


public intrmdir(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


public unsigned intsleep(unsigned int seconds)

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

Returns

0


public intusleep(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.