summaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-22 04:50:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-22 04:50:29 +0000
commitaf44082ad40035b63c357497fddef08ea3a2e6bd (patch)
tree2cbb3cde9982b1e609b02f94f35560f67e8f3b5e /io.c
parentbe7db43195986f5d133e40be6a1c7cb813065660 (diff)
downloadruby-af44082ad40035b63c357497fddef08ea3a2e6bd.tar.gz
ruby-af44082ad40035b63c357497fddef08ea3a2e6bd.tar.xz
ruby-af44082ad40035b63c357497fddef08ea3a2e6bd.zip
* io.c (rb_io_fdatasync): new method IO#fdatasync.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/io.c b/io.c
index 47c31a1a3..660fb14cc 100644
--- a/io.c
+++ b/io.c
@@ -1319,6 +1319,34 @@ rb_io_fsync(VALUE io)
#define rb_io_fsync rb_f_notimplement
#endif
+#ifdef HAVE_FDATASYNC
+/*
+ * call-seq:
+ * ios.fdatasync => 0 or nil
+ *
+ * Immediately writes all buffered data in <em>ios</em> to disk.
+ * Returns <code>nil</code> if the underlying operating system does not
+ * support <em>fdatasync(2)</em>.
+ */
+
+static VALUE
+rb_io_fdatasync(VALUE io)
+{
+ rb_io_t *fptr;
+
+ io = GetWriteIO(io);
+ GetOpenFile(io, fptr);
+
+ if (io_fflush(fptr) < 0)
+ rb_sys_fail(0);
+ if (fdatasync(fptr->fd) < 0)
+ rb_sys_fail_path(fptr->pathv);
+ return INT2FIX(0);
+}
+#else
+#define rb_io_fdatasync rb_f_notimplement
+#endif
+
/*
* call-seq:
* ios.fileno => fixnum
@@ -8781,6 +8809,7 @@ Init_IO(void)
rb_define_method(rb_cIO, "to_io", rb_io_to_io, 0);
rb_define_method(rb_cIO, "fsync", rb_io_fsync, 0);
+ rb_define_method(rb_cIO, "fdatasync", rb_io_fdatasync, 0);
rb_define_method(rb_cIO, "sync", rb_io_sync, 0);
rb_define_method(rb_cIO, "sync=", rb_io_set_sync, 1);