micro-utils/coreutils/sync.c
Your Name 7eed71d9b2 mk
2023-10-13 15:34:16 +03:00

28 lines
444 B
C

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
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;
}