#include <unistd.h>
|
|
int
fsync (int fd); |
The fsync system call should be used by programs that require a file to be in a known state, for example, in building a simple transaction facility.
/**
* Detailed description : Simple usage of fsync system call.
* Preconditions : Example.txt if present should not a ready-only file
**/
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd = 0;
fd = open("Example.txt" , O_CREAT | O_RDWR , 0666);
if(fd < 0 )
{
printf("Failed to open file Example.txt \n");
return -1;
}
if(fsync(fd) < 0 )
{
printf("fsync system call failed \n");
return -1;
}
close(fd);
printf("fsync system call succeeded \n");
return 0;
}
Output
fsync system call succeeded
| [EBADF] | |
| The fd argument is not a valid descriptor. | |
| [EINVAL] | |
| The fd argument refers to a socket, not to a file. | |
| [EIO] | An I/O error occurred while reading from or writing to the file system. |
The fsync system call appeared in BSD 4.2.
Feedback
For additional information or queries on this page send feedback
|
© 2005-2007 Nokia |