File management system calls in POSIX: open, close, read, write, lseek, stat

Here are the file management system calls in POSIX:

fd = open(file, how, …): It is used for opening a file for reading, or writing, or for both reading and writing. Here file is the filename which has to be opened. how specifies the absolute or the relative path name. Codes O_RDONLY, 0_ WRONLY, or O_RDWR, are used for reading, writing, or both reading and writing. For creating a new file, the O_CREAT parameter is used.

s = close(fd): It is used for closing an open file.

n = read(fd, buffer, nbytes): It is used for reading data from a file in to a buffer.

n = write(fd, buffer, nbytes): It is used for writing data from a buffer into a file.

position = lseek(fd, offset, whence): It is used for moving the file pointer from the current position of the file to a specific location in file. Here, parameter fd specifies file descriptor for file, offset specifies the file position and whence specifies file position relative to the start of the file, current position, or end of the file.

s = stat(name, &but): It is used for retrieving status information of a file. Here, name parameter specifies the name of file and but is a pointer to a structure where information will be kept.

Leave a Reply