{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

rec4-2010 - Recitation 4 File I/O system calls open read...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Recitation 4 File I/O system calls : open, read, write, close File I/O std. library functions : fopen, fgets, fread, fwrite, fclose. exercise: filemerge.c
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
‘Open’ system call Prototype : int open (const char * path, int oflag, ... ) Declared in “fcntl.h” Creates a connection between a process and a file, called the file descriptor. To open a file Specify the name of the file. The type of connection you want: O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_APPEND…
Image of page 2
‘Open’ system call cont… Opening a file is a kernel service, if the kernel detects a problem it returns the value -1. The kernel returns the file descriptor. It is a long or an int depending on the values of system constants.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
‘Read’ system call Prototype : ssize_t read (int fildes, void *buf, size_t nbyte) Declared in unistd.h Transfer up to nbyte bytes from the file. Associated with the open file descriptor into the buffer pointed to by buf.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}