koh_fsync.c
1#include "koh_fsync.h"23#include <fcntl.h>4#include <unistd.h>56/* Opening read-only is enough to sync and works for both files and folders on7 * Linux and macOS; a folder cannot be opened for writing at all. */8static int koh_fsync_path(const char *path) {9 int fd = open(path, O_RDONLY);10 if (fd < 0) {11 return 0;12 }13 int ok = fsync(fd) == 0;14 close(fd);15 return ok ? 1 : 0;16}1718int koh_fsync_file(const char *path) {19 return koh_fsync_path(path);20}2122int koh_fsync_dir(const char *path) {23 return koh_fsync_path(path);24}