The creat function creates a new file:
#include <fcntl.h>int creat( const char *pathname, mode_t mode );
Returned value: if the operation succeeds, the system returns a write-only file descriptor. If an error occurs, the system returns-1;
Open functions are used to open and create files:
# Include <fcntl. h>
Int open (const char * pathname, int Oflag,.../* mode_t mode */);
Returned value: if the operation is successful, the file descriptor is returned. Otherwise,-1 is returned.
Close function to close an open file:
#include <unistd.h>int close( int filedes );
Return Value: if the request succeeds, 0 is returned. If the request fails,-1 is returned;
The lseek function sets the offset for an opened file:
#include <unistd.h>off_t lseek( int filedes, off_t offset, int whence );
Return Value: if the operation succeeds, a new file offset is returned. If an error occurs,-1 is returned;
The READ function reads data from open files:
#include <unistd.h>ssize_t read( int filedes, void *buf, size_t nbytest );
Return Value: If successful, the number of bytes read is returned. If the number of bytes has been read to the end of the file, 0 is returned. If an error occurs,-1 is returned;
The Write function writes data to open files:
#include <unistd.h>ssize_t write( int filedes, const void *buf, size_t nbytes );
Return Value: if the operation succeeds, the number of written bytes is returned. If an error occurs, the value-1 is returned.
File IO Functions