diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-28 04:06:14 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-28 04:06:14 +0000 |
commit | 0a7785431c05d6b1854af94465f49c6b6d27a304 (patch) | |
tree | 0aee16ded97f0211567451d5b584fd01f926a2c5 /io.c | |
parent | 37377b24d1aa2cff005da926115e4b690ded3545 (diff) |
* io.c (interpret_seek_whence): support SEEK_DATA and SEEK_HOLE.
These are whences for lseek(2) supported by Linux since version 3.1.
[ruby-core:56123] [Feature #8671]
* test/ruby/test_io.rb: Add tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -161,6 +161,12 @@ static ID id_write, id_read, id_getc, id_flush, id_readpartial, id_set_encoding; static VALUE sym_mode, sym_perm, sym_extenc, sym_intenc, sym_encoding, sym_open_args; static VALUE sym_textmode, sym_binmode, sym_autoclose; static VALUE sym_SET, sym_CUR, sym_END; +#ifdef SEEK_DATA +static VALUE sym_DATA; +#endif +#ifdef SEEK_HOLE +static VALUE sym_HOLE; +#endif struct argf { VALUE filename, current_file; @@ -1551,6 +1557,14 @@ interpret_seek_whence(VALUE vwhence) return SEEK_CUR; if (vwhence == sym_END) return SEEK_END; +#ifdef SEEK_DATA + if (vwhence == sym_DATA) + return SEEK_DATA; +#endif +#ifdef SEEK_HOLE + if (vwhence == sym_HOLE) + return SEEK_HOLE; +#endif return NUM2INT(vwhence); } @@ -11820,6 +11834,14 @@ Init_IO(void) rb_define_const(rb_cIO, "SEEK_CUR", INT2FIX(SEEK_CUR)); /* Set I/O position from the end */ rb_define_const(rb_cIO, "SEEK_END", INT2FIX(SEEK_END)); +#ifdef SEEK_DATA + /* Set I/O position to the next location containing data */ + rb_define_const(rb_cIO, "SEEK_DATA", INT2FIX(SEEK_DATA)); +#endif +#ifdef SEEK_HOLE + /* Set I/O position to the next hole */ + rb_define_const(rb_cIO, "SEEK_HOLE", INT2FIX(SEEK_HOLE)); +#endif rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0); rb_define_method(rb_cIO, "pos", rb_io_tell, 0); rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1); @@ -11989,4 +12011,10 @@ Init_IO(void) sym_SET = ID2SYM(rb_intern("SET")); sym_CUR = ID2SYM(rb_intern("CUR")); sym_END = ID2SYM(rb_intern("END")); +#ifdef SEEK_DATA + sym_DATA = ID2SYM(rb_intern("DATA")); +#endif +#ifdef SEEK_HOLE + sym_HOLE = ID2SYM(rb_intern("HOLE")); +#endif } |