1 /* fsync.c - Synchronize a file's in-core state with storage device.
2  *
3  * Copyright 2015 Ranjan Kumar <ranjankumar.bth@gmail.comi>
4  *
5  * No Standard.
6 
7 USE_FSYNC(NEWTOY(fsync, "<1d", TOYFLAG_BIN))
8 
9 config FSYNC
10   bool "fsync"
11   default y
12   help
13     usage: fsync [-d] [FILE...]
14 
15     Synchronize a file's in-core state with storage device.
16 
17     -d	Avoid syncing metadata.
18 */
19 
20 #define FOR_fsync
21 #include "toys.h"
22 
do_fsync(int fd,char * name)23 static void do_fsync(int fd, char *name)
24 {
25   if (((toys.optflags & FLAG_d) ? fdatasync(fd) : fsync(fd)))
26     perror_msg("can't sync '%s'", name);
27 }
28 
fsync_main(void)29 void fsync_main(void)
30 {
31   loopfiles_rw(toys.optargs, O_RDONLY|O_NOATIME|O_NOCTTY|O_CLOEXEC,
32       0, 0, do_fsync);
33 }
34