#include "koh_fsync.h" #include #include /* Opening read-only is enough to sync and works for both files and folders on * Linux and macOS; a folder cannot be opened for writing at all. */ static int koh_fsync_path(const char *path) { int fd = open(path, O_RDONLY); if (fd < 0) { return 0; } int ok = fsync(fd) == 0; close(fd); return ok ? 1 : 0; } int koh_fsync_file(const char *path) { return koh_fsync_path(path); } int koh_fsync_dir(const char *path) { return koh_fsync_path(path); }