diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-04-16 07:42:49 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-04-16 07:42:49 +0000 |
commit | 94a1bece4a4adb5c0f8f09fb9b95356bae24912b (patch) | |
tree | 87c751178430d6471e391108c73d92cf25ad4af9 /file.c | |
parent | e0041160736f1c0f092400eb75336311ab10fa1e (diff) |
flock,flatten,signal to main_thread
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 47 |
1 files changed, 36 insertions, 11 deletions
@@ -189,7 +189,7 @@ file_tell(obj) GetOpenFile(obj, fptr); pos = ftell(fptr->f); - if (ferror(fptr->f) != 0) rb_sys_fail(0); + if (ferror(fptr->f) != 0) rb_sys_fail(fptr->path); return int2inum(pos); } @@ -203,10 +203,10 @@ file_seek(obj, offset, ptrname) GetOpenFile(obj, fptr); pos = fseek(fptr->f, NUM2INT(offset), NUM2INT(ptrname)); - if (pos != 0) rb_sys_fail(0); + if (pos != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); - return obj; + return INT2FIX(0); } static VALUE @@ -218,10 +218,10 @@ file_set_pos(obj, offset) GetOpenFile(obj, fptr); pos = fseek(fptr->f, NUM2INT(offset), 0); - if (pos != 0) rb_sys_fail(0); + if (pos != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); - return obj; + return INT2NUM(pos); } static VALUE @@ -231,10 +231,10 @@ file_rewind(obj) OpenFile *fptr; GetOpenFile(obj, fptr); - if (fseek(fptr->f, 0L, 0) != 0) rb_sys_fail(0); + if (fseek(fptr->f, 0L, 0) != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); - return obj; + return INT2FIX(0); } static VALUE @@ -1100,7 +1100,7 @@ file_s_symlink(obj, from, to) if (symlink(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0) rb_sys_fail(RSTRING(from)->ptr); - return TRUE; + return INT2FIX(0); #else rb_notimplement(); #endif @@ -1384,7 +1384,7 @@ file_s_truncate(obj, path, len) rb_notimplement(); # endif #endif - return TRUE; + return INT2FIX(0); } static VALUE @@ -1409,8 +1409,32 @@ file_truncate(obj, len) rb_notimplement(); # endif #endif - return TRUE; + return INT2FIX(0); +} + +#if defined(THREAD) && defined(EWOULDBLOCK) +static int +thread_flock(fd, op) + int fd, op; +{ + if (thread_alone() || (op & LOCK_NB)) { + return flock(fd, op); + } + op |= LOCK_NB; + while (flock(fd, op) < 0) { + switch (errno) { + case EINTR: /* can be happen? */ + case EWOULDBLOCK: + thread_schedule(); /* busy wait */ + break; + default: + return -1; + } + } + return 0; } +#define flock thread_flock +#endif static VALUE file_flock(obj, operation) @@ -1430,8 +1454,9 @@ file_flock(obj, operation) #endif rb_sys_fail(fptr->path); } - return obj; + return INT2FIX(0); } +#undef flock static void test_check(n, argc, argv) |