sync: Support argument

This commit is contained in:
K. Lange 2021-11-16 08:55:57 +09:00
parent 8a643583bf
commit 32e99ff897

View File

@ -1,9 +1,27 @@
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
int fd = open(".",O_RDONLY|O_DIRECTORY); char * file = ".";
return ioctl(fd, IOCTLSYNC, NULL); if (argc > 1) {
file = argv[1];
}
int fd = open(file,O_RDONLY|O_DIRECTORY);
if (fd < 0) {
fd = open(file,O_RDONLY);
}
if (fd < 0) {
fprintf(stderr, "sync: open: %s: %s (%d)\n", file, strerror(errno), fd);
return 1;
}
int res = ioctl(fd, IOCTLSYNC, NULL);
if (res < 0) {
fprintf(stderr, "sync: ioctl: %s (%d)\n", strerror(errno), fd);
return 1;
}
return 0;
} }