Skip to main content

Unix Standard (unistd)

Functions

close(int fildes)#

int close (int fildes)

Type: int

Parameters:

  • int fildes

Details#

This function closes the file associated with the specified descriptor.

Returns:

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

  • EBADF: Invalid file descriptor

_execve(const char path, char const argv[], char *const envp[])#

int _execve (const char *path, char *const argv[], char *const envp[])

Type: int

Parameters:

  • const char * path
  • char *const argv
  • char *const envp

_exit(int __status)#

void _exit (int __status)

Type: void

Parameters:

  • int __status

Details#

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

fcntl(int fildes, int cmd,...)#

int fcntl (int fildes, int cmd,...)

Type: int

Parameters:

  • int fildes
  • int cmd
  • ...

Details#

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.

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

fstat(int fildes, struct stat *buf)#

int fstat (int fildes, struct stat *buf)

Type: int

Parameters:

  • int fildes
  • struct stat * buf

Details#

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

getpid()#

pid_t getpid ()

Type: pid_t

Details#

This function returns the process ID of the calling process.

Returns:

The process ID of the caller.

getppid()#

pid_t getppid ()

Type: pid_t

Details#

This function returns the process ID of the parent process.

Returns:

The process ID of the caller's parent process.

isatty(int fildes)#

int isatty (int fildes)

Type: int

Parameters:

  • int fildes

Details#

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

link(const char old, const char new)#

int link (const char *old, const char *new)

Type: int

Parameters:

  • const char * old
  • const char * new

Details#

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

lseek(int fildes, off_t offset, int whence)#

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

Type: off_t

Parameters:

  • int fildes
  • off_t offset
  • int whence

Details#

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

open(const char *name, int flags,...)#

int open (const char *name, int flags,...)

Type: int

Parameters:

  • const char * name
  • int flags
  • ...

Details#

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
  • EMFILE: Too many files are already open
  • 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)

read(int fildes, void *buf, size_t nbyte)#

int read (int fildes, void *buf, size_t nbyte)

Type: int

Parameters:

  • int fildes
  • void * buf
  • size_t nbyte

Details#

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.

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

rename(const char old, const char new)#

int rename (const char *old, const char *new)

Type: int

Parameters:

  • const char * old
  • const char * new

Details#

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

stat(const char path, struct stat buf)#

int stat (const char *path, struct stat *buf)

Type: int

Parameters:

  • const char * path
  • struct stat * buf

Details#

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

symlink(const char old, const char new)#

int symlink (const char *old, const char *new)

Type: int

Parameters:

  • const char * old
  • const char * new

Details#

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

unlink(const char *name)#

int unlink (const char *name)

Type: int

Parameters:

  • const char * name

Details#

Deletes a file or directory from the filesystem.

write(int fildes, const void *buf, size_t nbyte)#

int write (int fildes, const void *buf, size_t nbyte)

Type: int

Parameters:

  • int fildes
  • const void * buf
  • size_t nbyte

Details#

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.

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

access(const char *path, int amode)#

int access (const char *path, int amode)

Type: int

Parameters:

  • const char * path
  • int amode

Details#

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

chmod(const char *path, mode_t mode)#

int chmod (const char *path, mode_t mode)

Type: int

Parameters:

  • const char * path
  • mode_t mode

Details#

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

chown(const char *path, uid_t uid, gid_t gid)#

int chown (const char *path, uid_t uid, gid_t gid)

Type: int

Parameters:

  • const char * path
  • uid_t uid
  • gid_t gid

Details#

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

encrypt(char block[64], int edflag)#

void encrypt (char block[64], int edflag)

Type: void

Parameters:

  • char block
  • int edflag

Details#

Encrypts a block of data.

Returns:

No return value but errno may be set to:

  • ENOSYS: function not supported on this platform

crypt(const char key, const char salt)#

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

Type: char *

Parameters:

  • const char * key
  • const char * salt

setkey(const char *key)#

void setkey (const char *key)

Type: void

Parameters:

  • const char * key

fsync(int fildes)#

int fsync (int fildes)

Type: int

Parameters:

  • int fildes

Details#

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.

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

ioctl(int fildes, int request,...)#

int ioctl (int fildes, int request,...)

Type: int

Parameters:

  • int fildes
  • int request
  • ...

Details#

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.

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

lstat(const char path, struct stat buf)#

int lstat (const char *path, struct stat *buf)

Type: int

Parameters:

  • const char * path: The path the to symbolic link
  • struct stat * buf: The destination buffer

Details#

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

mkdir(const char *path, mode_t mode)#

int mkdir (const char *path, mode_t mode)

Type: int

Parameters:

  • const char * path
  • mode_t mode

Details#

This function creates a new directory.

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

rmdir(const char *path)#

int rmdir (const char *path)

Type: int

Parameters:

  • const char * path

Details#

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

sleep(unsigned int seconds)#

unsigned int sleep (unsigned int seconds)

Type: unsigned int

Parameters:

  • unsigned int seconds: The number of seconds to sleep

Details#

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

Returns:

0

svcall_update_task_root(void *args)#

static void svcall_update_task_root (void *args)

Type: void

Parameters:

  • void * args

geteuid()#

uid_t geteuid ()

Type: uid_t

Details#

gets the effective user id.The effectictive user id is not always the same as the user id. If the caller is authenticated, the user id will always be root and the effective user id can switch between root and user based on the usage .

Returns:

0 for root and 1 for user

getuid()#

uid_t getuid ()

Type: uid_t

Details#

gets the user id.If the process is authenticated, the user id is root (0) otherwise, the user id is user (1).

Returns:

0 for root and 1 for user

seteuid(uid_t uid)#

int seteuid (uid_t uid)

Type: int

Parameters:

  • uid_t uid

Details#

sets the effective user id. When the effective

Returns:

0 on success or -1 with the errno set to:

  • EPERM: process is not authenticated
  • EINVAL: uid is not SYSFS_USER or SYSFS_ROOT

setuid(uid_t uid)#

int setuid (uid_t uid)

Type: int

Parameters:

  • uid_t uid

Details#

functions exactly like

getgid()#

gid_t getgid ()

Type: gid_t

getegid()#

gid_t getegid ()

Type: gid_t

usleep(useconds_t useconds)#

int usleep (useconds_t useconds)

Type: int

Parameters:

  • useconds_t useconds

Details#

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.