[glib: 1/2] Add a wrapper for fsync() function
- From: Nirbheek Chauhan <nirbheekc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] Add a wrapper for fsync() function
- Date: Mon, 23 Sep 2019 11:22:42 +0000 (UTC)
commit 3636bb5fe1b5d7dc5a6f52a779e4d5087c1b68cd
Author: Todd Goyen <unknown email net>
Date: Fri Sep 13 19:53:15 2019 +0200
Add a wrapper for fsync() function
Closes issue #35
docs/reference/glib/glib-sections.txt | 1 +
glib/gstdio.c | 25 +++++++++++++++++++++++++
glib/gstdio.h | 4 ++++
glib/tests/fileutils.c | 1 +
4 files changed, 31 insertions(+)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 63457a1ad..c67af683d 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1626,6 +1626,7 @@ g_remove
g_rmdir
g_fopen
g_freopen
+g_fsync
g_chmod
g_access
g_creat
diff --git a/glib/gstdio.c b/glib/gstdio.c
index 653c8a3a1..a554b421c 100644
--- a/glib/gstdio.c
+++ b/glib/gstdio.c
@@ -1641,6 +1641,31 @@ g_freopen (const gchar *filename,
#endif
}
+/**
+ * g_fsync:
+ * @fd: a file descriptor
+ *
+ * A wrapper for the POSIX fsync() function (_commit() on Windows).
+ * The fsync() function is used to synchronize a file's in-core
+ * state with that of the disk.
+ *
+ * See the C library manual for more details about fsync().
+ *
+ * Returns: 0 on success, or -1 if an error occurred.
+ * The return value can be used exactly like the return value from fsync().
+ *
+ * Since: 2.64
+ */
+gint
+g_fsync (gint fd)
+{
+#ifdef G_OS_WIN32
+ return _commit (fd);
+#else
+ return fsync (fd);
+#endif
+}
+
/**
* g_utime:
* @filename: (type filename): a pathname in the GLib file name encoding
diff --git a/glib/gstdio.h b/glib/gstdio.h
index f1781f3e9..7ed9c5dfa 100644
--- a/glib/gstdio.h
+++ b/glib/gstdio.h
@@ -76,6 +76,7 @@ typedef struct stat GStatBuf;
#define g_remove remove
#define g_fopen fopen
#define g_freopen freopen
+#define g_fsync fsync
#define g_utime utime
#endif
@@ -158,6 +159,9 @@ FILE *g_freopen (const gchar *filename,
const gchar *mode,
FILE *stream);
+GLIB_AVAILABLE_IN_2_64
+gint g_fsync (gint fd);
+
struct utimbuf; /* Don't need the real definition of struct utimbuf when just
* including this header.
*/
diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c
index 07a91a67f..06b14bead 100644
--- a/glib/tests/fileutils.c
+++ b/glib/tests/fileutils.c
@@ -866,6 +866,7 @@ test_set_contents (void)
fd = g_file_open_tmp (NULL, &name, &error);
g_assert_no_error (error);
write (fd, "a", 1);
+ g_assert_cmpint (g_fsync (fd), ==, 0);
close (fd);
ret = g_file_get_contents (name, &buf, &len, &error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]