summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/io.c b/io.c
index c5fb2359f6..946d332195 100644
--- a/io.c
+++ b/io.c
@@ -439,6 +439,28 @@ rb_io_set_sync(io, mode)
}
static VALUE
+rb_io_fsync(io)
+ VALUE io;
+{
+#ifdef HAVE_FSYNC
+ OpenFile *fptr;
+ FILE *f;
+
+ GetOpenFile(io, fptr);
+ rb_io_check_writable(fptr);
+ f = GetWriteFile(fptr);
+
+ io_fflush(f, fptr->path);
+ if (fsync(fileno(f)) < 0)
+ rb_sys_fail(fptr->path);
+ return INT2FIX(0);
+#else
+ rb_notimplement();
+ return Qnil; /* not reached */
+#endif
+}
+
+static VALUE
rb_io_fileno(io)
VALUE io;
{
@@ -3557,6 +3579,7 @@ Init_IO()
rb_define_alias(rb_cIO, "to_i", "fileno");
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, "sync", rb_io_sync, 0);
rb_define_method(rb_cIO, "sync=", rb_io_set_sync, 1);