File IO Functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.