]> mj.ucw.cz Git - libucw.git/blob - ucw/sync.c
make Sherlock compilable on Darwin without hacks due to missing direct IO
[libucw.git] / ucw / sync.c
1 /*
2  *      UCW Library -- Syncing Directories
3  *
4  *      (c) 2004--2005 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "ucw/lib.h"
8
9 #include <fcntl.h>
10 #include <unistd.h>
11
12 void
13 sync_dir(const char *name)
14 {
15   int fd = open(name, O_RDONLY
16 #ifdef CONFIG_LINUX
17                 | O_DIRECTORY
18 #endif
19 );
20   if (fd < 0)
21     goto err;
22   int err = fsync(fd);
23   close(fd);
24   if (err >= 0)
25     return;
26  err:
27   msg(L_ERROR, "Unable to sync directory %s: %m", name);
28 }