Professional Documents
Culture Documents
By
James Murithi
Types
of files
File I/O related calls
File statistic related calls
File permission related calls
Reading/writing
Anything
File
Regular
Process
Open()
Create()
Socket()
Pipe()
etc
Read()
Write()
Chown()
Chmod()
dirfd
include<fcntl.h>
defines arguments
passed to the open and fcntl
functions
Receives at least two parameters:
int open(
const char *pathname,
int oflag,
... /* mode_t mode */
);
12
If
13
1.
2.
The
14
O_APPEND
append
O_CREAT creates file (if !exist)
O_TRUNC truncates
O_EXCL generates error if
O_CREAT is specified and the file
exists
O_NONBLOCK open in nonblocking
mode
ICS 2305 May-Aug 2013
15
int
fileDescriptor;
char* path =
/home/jamesmm/docs/list.txt;
fileDescriptor = open(path,
O_RDONLY);
16
Receives
close
int close(fd);
Returns 0 if ok -1 if error
Releases locks on the file
include
18
If
Receives
1.
2.
3.
three parameters
A file descriptor
A character buffer to store
bytes read
Number of bytes to read from file
Declare
necessary variables
char buffer[256];
ssize_t bytesRead;
size_t numBytes; numBytes =
sizeof(buffer);
bytes_read
numBytes);
= read(fd, buffer,
21
#include<unistd.h>
ssize_t
22
int
fd file descriptor
const void *buff message to write
size_t bytes bytes to write
char
System
File owner
Permissions
Date created
Date last modified etc
Stat
25
Can
All
All
Requires
29
When
Requires
32