diff --git a/src/sync.c b/src/sync.c new file mode 100644 index 0000000..ef52bf6 --- /dev/null +++ b/src/sync.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include + +int main(const int argc, const char **argv) { + if (argc == 1) + sync(); + + for (int i = 1; i < argc; i++) { + int fd = open(argv[i], O_WRONLY); + if (fd < 0) { + fprintf(stderr, "sync: %s\n", strerror(errno)); + return 1; + } + + if (fsync(fd)) { + fprintf(stderr, "sync: %s\n", strerror(errno)); + return 1; + } + + close(fd); + } + + return 0; +}