NCEPLIBS-prod_util  2.1.0
fsync_file.c
Go to the documentation of this file.
1 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 
12 
13 int main(int argc, char **argv) {
14 
15  int handle,rc;
16 
17  if(argc < 2) {
18  printf("Usage : %s <file to fsync> \n",argv[0]);
19  exit(1);
20  }
21 
22  handle = open(argv[1], O_WRONLY, 0666);
23  if (handle == -1)
24  {
25  fprintf(stderr, "Could not open file '%s' to fsync it, errno=%d\n",
26  argv[1], errno);
27  exit(1);
28  }
29  rc = fsync(handle);
30  if (rc == -1)
31  {
32  fprintf(stderr, "Error %d from fsync\n", errno);
33  exit(1);
34  }
35  rc = close(handle);
36  if (rc == -1)
37  {
38  fprintf(stderr, "Could not close file '%s' after fsync, errno=%d\n",
39  argv[1], errno);
40  exit(1);
41  }
42 }