summaryrefslogtreecommitdiffstats
path: root/gnu/libexec/uucp/libunix/sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/libexec/uucp/libunix/sync.c')
-rw-r--r--gnu/libexec/uucp/libunix/sync.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/gnu/libexec/uucp/libunix/sync.c b/gnu/libexec/uucp/libunix/sync.c
new file mode 100644
index 0000000..c346c58
--- /dev/null
+++ b/gnu/libexec/uucp/libunix/sync.c
@@ -0,0 +1,42 @@
+/* sync.c
+ Sync a file to disk, if FSYNC_ON_CLOSE is set. */
+
+#include "uucp.h"
+
+#include "uudefs.h"
+#include "sysdep.h"
+#include "system.h"
+
+#include <errno.h>
+
+boolean
+fsysdep_sync (e, zmsg)
+ openfile_t e;
+ const char *zmsg;
+{
+ int o;
+
+#if USE_STDIO
+ if (fflush (e) == EOF)
+ {
+ ulog (LOG_ERROR, "%s: fflush: %s", zmsg, strerror (errno));
+ return FALSE;
+ }
+#endif
+
+#if USE_STDIO
+ o = fileno (e);
+#else
+ o = e;
+#endif
+
+#if FSYNC_ON_CLOSE
+ if (fsync (o) < 0)
+ {
+ ulog (LOG_ERROR, "%s: fsync: %s", zmsg, strerror (errno));
+ return FALSE;
+ }
+#endif
+
+ return TRUE;
+}
OpenPOWER on IntegriCloud