#include <unistd.h>
|
|
int
fdatasync (int fd); |
The functionality shall be equivalent to fsync() with the symbol -> _POSIX_SYNCHRONIZED_IO defined. This has an exception that all I/O operations shall be completed, before the call.
The fdatasync should be used by programs that require a file to be in a known state, for example, in building a simple transaction facility.
#include<unistd.h>
#include<stdio.h>
#define KMAXCHARS 100
int test_fdatasync()
{
char* array = "abcdefghijklmnopqrstuvwxyz";
struct stat buf;
if((fd = open(file , O_CREAT | O_RDWR , 0666)) < 0)
{
printf("Failed to create file");
}
size_t size = write(fd,array, KMAXCHARS);
if(fdatasync(fd) < 0)
{
printf("Fdatasync failed");
int retrn = remove(file);
return -1;
}
int retVal2 = fstat( fp, &buf );
if(!retVal2)
{
size_t bufsize = buf.st_size;
if (bufsize == size)
{
printf("file size = %d\n", size);
printf("Fdatasync passed");
int retrn = remove(file);
return 0;
}
}
}
Output
file size = 50
Fdatasync passed
|
© 2008-2009 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user. |