Supported Standard IO System Call

Functions

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

open and possibly create a file

read more: man 2 open

Parameters:
  • path – file path

  • flags – flags

  • ...

Returns:

return file descriptor on success, -1 on failure

int close(int fd)

Close a file descriptor.

read more: man 2 close

Parameters:

fd – file descritor

Returns:

return file descriptor on success, -1 on failure

ssize_t read(int fd, void *buf, size_t count)

read from a file descriptor

Parameters:
  • fd – file descriptor

  • buf – buffer to store read data

  • count – number of bytes to read

Returns:

zero or number of bytes read on success, -1 on failure

ssize_t write(int fd, const void *buf, size_t count)

write to file descriptor

Parameters:
  • fd – file description

  • buf – buffer to write

  • count – number of bytes to write

Returns:

On success, the number of bytes written is returned. On error, -1 is returned

int fsync(int fd)

synchronize a file’s in-core state with storage device

Parameters:

fd – file descriptor

Returns:

On success, these system calls return zero. On error, -1 is returned

int isatty(int fd)

test whether a file descriptor refers to a terminal

Parameters:

fd – file descriptor

Returns:

returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned

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

reposition read/write file offset

Parameters:
  • fd – file descriptor

  • offset – offset value

  • whence – SEEK_SET, SEEK_CUR, SEEK_END

Returns:

resulting offset location on success, -1 on error

int ftruncate(int fd, off_t length)

truncate a file to a specified length

Parameters:
  • fd – file descriptor

  • length – new length

Returns:

On success, zero is returned. On error, -1 is returned

int fstat(int fd, struct stat *statbuf)

get file status

Parameters:
  • fd – file descriptor

  • statbuf – pointer to stat structure

Returns:

On success, zero is returned. On error, -1 is returned

int unlink(const char *pathname)

delete a file

Parameters:

pathname – path to file

Returns:

On success, zero is returned. On error, -1 is returned

int rename(const char *oldpath, const char *newpath)

change the name

Parameters:
  • oldpath – path to old file

  • newpath – path to new file

Returns:

On success, zero is returned. On error, -1 is returned

int access(const char *pathname, int mode)

check user’s permissions for a file

Parameters:
  • pathname – path to file

  • mode – the accessibility check(s) to be performed

Returns:

On success, zero is returned. On error, -1 is returned

int mkdir(const char *pathname, mode_t mode)

create a directory

Parameters:
  • pathname – path to directory

  • mode – mode for the new directory

Returns:

zero on success, or -1 if an error occurred

int rmdir(const char *pathname)

delete a directory

Parameters:

pathname – path to directory

Returns:

On success, zero is returned. On error, -1 is returned

int fcntl(int fd, int cmd, ...)

manipulate file descriptor

more details check: man 2 fcntl

Supported commmands: F_GETFL, F_SETFL, F_GETLK, F_SETLK, F_SETLKW

Parameters:
  • fd – file descriptor

  • cmd – operation to performed

  • ... – argument

Returns:

On success, zero is returned. On error, -1 is returned

int lockf(int fd, int cmd, off_t len)

apply, test or remove a POSIX lock on an open file

Parameters:
  • fd – File descriptor

  • cmd – operation to perform

  • len – unimplemented, only complete file locking possible

Returns:

On success, zero is returned. On error, -1 is returned

int flock(int fd, int operation)

apply or remove an advisory lock on an open file

Parameters:
  • fd – File descriptor

  • operation – operation to perform: LOCK_SH, LOCK_EX, LOCK_UN

Returns:

On success, zero is returned. On error, -1 is returned

pid_t getpid(void)

returns current task id

Returns:

returns taskid of current task