From 62e648e148b3cb9f96dcce808c55c02b7ccb4486 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 20 Jan 1999 04:59:39 +0000 Subject: ruby 1.3 cycle git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/RUBY@372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 905 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 446 insertions(+), 459 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index b60ec65d55..11a8dedf14 100644 --- a/file.c +++ b/file.c @@ -6,12 +6,17 @@ $Date$ created at: Mon Nov 15 12:24:34 JST 1993 - Copyright (C) 1993-1996 Yukihiro Matsumoto + Copyright (C) 1993-1998 Yukihiro Matsumoto ************************************************/ +#ifdef NT +#include "missing/file.h" +#endif + #include "ruby.h" -#include "io.h" +#include "rubyio.h" +#include "rubysig.h" #ifdef HAVE_UNISTD_H #include @@ -43,44 +48,44 @@ struct timeval { #endif #ifndef HAVE_STRING_H -char *strrchr(); +char *strrchr _((char*,char)); #endif +#include #include -#ifndef NT -char *strdup(); -char *getenv(); +#ifdef USE_CWGUSI + #include "macruby_missing.h" + extern int fileno(FILE *stream); + extern int utimes(); #endif -extern VALUE cIO; -VALUE cFile; -VALUE mFileTest; +VALUE rb_cFile; +VALUE rb_mFileTest; static VALUE sStat; -VALUE time_new(); - VALUE -file_open(fname, mode) +rb_file_open(fname, mode) char *fname, *mode; { OpenFile *fptr; NEWOBJ(port, struct RFile); - OBJSETUP(port, cFile, T_FILE); + OBJSETUP(port, rb_cFile, T_FILE); MakeOpenFile(port, fptr); - fptr->mode = io_mode_flags(mode); + fptr->mode = rb_io_mode_flags(mode); fptr->f = rb_fopen(fname, mode); fptr->path = strdup(fname); + rb_obj_call_init((VALUE)port); return (VALUE)port; } static VALUE -file_s_open(argc, argv, class) +rb_file_s_open(argc, argv, klass) int argc; VALUE *argv; - VALUE class; + VALUE klass; { VALUE fname, vmode, file; char *mode; @@ -88,24 +93,24 @@ file_s_open(argc, argv, class) rb_scan_args(argc, argv, "11", &fname, &vmode); Check_SafeStr(fname); if (!NIL_P(vmode)) { - Check_Type(vmode, T_STRING); - mode = RSTRING(vmode)->ptr; + mode = STR2CSTR(vmode); } else { mode = "r"; } - file = file_open(RSTRING(fname)->ptr, mode); + file = rb_file_open(RSTRING(fname)->ptr, mode); - RBASIC(file)->class = class; - if (iterator_p()) { - rb_ensure(rb_yield, file, io_close, file); + RBASIC(file)->klass = klass; + rb_obj_call_init(file); + if (rb_iterator_p()) { + return rb_ensure(rb_yield, file, rb_io_close, file); } return file; } static VALUE -file_reopen(argc, argv, file) +rb_file_reopen(argc, argv, file) int argc; VALUE *argv; VALUE file; @@ -114,16 +119,16 @@ file_reopen(argc, argv, file) char *mode; OpenFile *fptr; + rb_secure(4); if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) { if (TYPE(fname) == T_FILE) { /* fname must be IO */ - return io_reopen(file, fname); + return rb_io_reopen(file, fname); } } Check_SafeStr(fname); if (!NIL_P(nmode)) { - Check_Type(nmode, T_STRING); - mode = RSTRING(nmode)->ptr; + mode = STR2CSTR(nmode); } else { mode = "r"; @@ -132,12 +137,11 @@ file_reopen(argc, argv, file) GetOpenFile(file, fptr); if (fptr->path) free(fptr->path); fptr->path = strdup(RSTRING(fname)->ptr); - fptr->mode = io_mode_flags(mode); + fptr->mode = rb_io_mode_flags(mode); if (!fptr->f) { fptr->f = rb_fopen(RSTRING(fname)->ptr, mode); if (fptr->f2) { - if (fileno(fptr->f2) < 3) /* need to keep stdio */ - fclose(fptr->f2); + fclose(fptr->f2); fptr->f2 = NULL; } return file; @@ -179,95 +183,20 @@ apply2files(func, vargs, arg) } static VALUE -file_tell(obj) - VALUE obj; -{ - OpenFile *fptr; - long pos; - - GetOpenFile(obj, fptr); - - pos = ftell(fptr->f); - if (ferror(fptr->f) != 0) rb_sys_fail(0); - - return int2inum(pos); -} - -static VALUE -file_seek(obj, offset, ptrname) - VALUE obj, offset, ptrname; -{ - OpenFile *fptr; - long pos; - - GetOpenFile(obj, fptr); - - pos = fseek(fptr->f, NUM2INT(offset), NUM2INT(ptrname)); - if (pos != 0) rb_sys_fail(0); - clearerr(fptr->f); - - return obj; -} - -static VALUE -file_set_pos(obj, offset) - VALUE obj, offset; -{ - OpenFile *fptr; - long pos; - - GetOpenFile(obj, fptr); - pos = fseek(fptr->f, NUM2INT(offset), 0); - if (pos != 0) rb_sys_fail(0); - clearerr(fptr->f); - - return obj; -} - -static VALUE -file_rewind(obj) - VALUE obj; -{ - OpenFile *fptr; - - GetOpenFile(obj, fptr); - if (fseek(fptr->f, 0L, 0) != 0) rb_sys_fail(0); - clearerr(fptr->f); - - return obj; -} - -static VALUE -file_eof(obj) +rb_file_path(obj) VALUE obj; { OpenFile *fptr; GetOpenFile(obj, fptr); - if (feof(fptr->f) == 0) return FALSE; - return TRUE; + if (fptr->path == NULL) return Qnil; + return rb_str_new2(fptr->path); } -static VALUE -file_path(obj) - VALUE obj; -{ - OpenFile *fptr; - - GetOpenFile(obj, fptr); - return str_new2(fptr->path); -} - -static VALUE -file_isatty(obj) - VALUE obj; -{ - return FALSE; -} - -#include #ifndef NT -#include +# ifndef USE_CWGUSI +# include +# endif #else #include "missing/file.h" #endif @@ -276,37 +205,53 @@ static VALUE stat_new(st) struct stat *st; { - if (!st) Bug("stat_new() called with bad value"); - return struct_new(sStat, - INT2FIX((int)st->st_dev), - INT2FIX((int)st->st_ino), - INT2FIX((int)st->st_mode), - INT2FIX((int)st->st_nlink), - INT2FIX((int)st->st_uid), - INT2FIX((int)st->st_gid), + if (!st) rb_bug("stat_new() called with bad value"); + return rb_struct_new(sStat, + INT2FIX((int)st->st_dev), + INT2FIX((int)st->st_ino), + INT2FIX((int)st->st_mode), + INT2FIX((int)st->st_nlink), + INT2FIX((int)st->st_uid), + INT2FIX((int)st->st_gid), #ifdef HAVE_ST_RDEV - INT2FIX((int)st->st_rdev), + INT2FIX((int)st->st_rdev), #else - INT2FIX(0), + INT2FIX(0), #endif - INT2FIX((int)st->st_size), + INT2FIX((int)st->st_size), #ifdef HAVE_ST_BLKSIZE - INT2FIX((int)st->st_blksize), + INT2FIX((int)st->st_blksize), #else - INT2FIX(0), + INT2FIX(0), #endif #ifdef HAVE_ST_BLOCKS - INT2FIX((int)st->st_blocks), + INT2FIX((int)st->st_blocks), #else - INT2FIX(0), + INT2FIX(0), #endif - time_new(st->st_atime, 0), - time_new(st->st_mtime, 0), - time_new(st->st_ctime, 0)); + rb_time_new(st->st_atime, 0), + rb_time_new(st->st_mtime, 0), + rb_time_new(st->st_ctime, 0)); +} + +static int +rb_stat(file, st) + VALUE file; + struct stat *st; +{ + if (TYPE(file) == T_FILE) { + OpenFile *fptr; + + rb_secure(4); + GetOpenFile(file, fptr); + return fstat(fileno(fptr->f), st); + } + Check_SafeStr(file); + return stat(RSTRING(file)->ptr, st); } static VALUE -file_s_stat(obj, fname) +rb_file_s_stat(obj, fname) VALUE obj, fname; { struct stat st; @@ -319,7 +264,7 @@ file_s_stat(obj, fname) } static VALUE -file_stat(obj) +rb_io_stat(obj) VALUE obj; { OpenFile *fptr; @@ -333,7 +278,7 @@ file_stat(obj) } static VALUE -file_s_lstat(obj, fname) +rb_file_s_lstat(obj, fname) VALUE obj, fname; { #if !defined(MSDOS) && !defined(NT) @@ -345,25 +290,28 @@ file_s_lstat(obj, fname) } return stat_new(&st); #else - rb_notimplement(); + rb_notimplement(); + return Qnil; /* not reached */ #endif } static VALUE -file_lstat(obj) +rb_file_lstat(obj) VALUE obj; { #if !defined(MSDOS) && !defined(NT) OpenFile *fptr; struct stat st; + rb_secure(4); GetOpenFile(obj, fptr); if (lstat(fptr->path, &st) == -1) { rb_sys_fail(fptr->path); } return stat_new(&st); #else - rb_notimplement(); + rb_notimplement(); + return Qnil; /* not reached */ #endif } @@ -371,9 +319,9 @@ static int group_member(gid) GETGROUPS_T gid; { -#ifndef NT +#if !defined(NT) && !defined(USE_CWGUSI) if (getgid() == gid || getegid() == gid) - return TRUE; + return Qtrue; # ifdef HAVE_GETGROUPS # ifndef NGROUPS @@ -386,11 +334,11 @@ group_member(gid) anum = getgroups(NGROUPS, gary); while (--anum >= 0) if (gary[anum] == gid) - return TRUE; + return Qtrue; } # endif #endif - return FALSE; + return Qfalse; } #ifndef S_IXUGO @@ -446,10 +394,9 @@ test_d(obj, fname) struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISDIR(st.st_mode)) return TRUE; - return FALSE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (S_ISDIR(st.st_mode)) return Qtrue; + return Qfalse; } static VALUE @@ -463,12 +410,11 @@ test_p(obj, fname) struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISFIFO(st.st_mode)) return TRUE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (S_ISFIFO(st.st_mode)) return Qtrue; #endif - return FALSE; + return Qfalse; } static VALUE @@ -493,11 +439,11 @@ test_l(obj, fname) struct stat st; Check_SafeStr(fname); - if (lstat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISLNK(st.st_mode)) return TRUE; + if (lstat(RSTRING(fname)->ptr, &st) < 0) return Qfalse; + if (S_ISLNK(st.st_mode)) return Qtrue; #endif - return FALSE; + return Qfalse; } static VALUE @@ -521,12 +467,11 @@ test_S(obj, fname) #ifdef S_ISSOCK struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISSOCK(st.st_mode)) return TRUE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (S_ISSOCK(st.st_mode)) return Qtrue; #endif - return FALSE; + return Qfalse; } static VALUE @@ -544,12 +489,11 @@ test_b(obj, fname) #ifdef S_ISBLK struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISBLK(st.st_mode)) return TRUE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (S_ISBLK(st.st_mode)) return Qtrue; #endif - return FALSE; + return Qfalse; } static VALUE @@ -562,11 +506,10 @@ test_c(obj, fname) struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISBLK(st.st_mode)) return TRUE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (S_ISBLK(st.st_mode)) return Qtrue; - return FALSE; + return Qfalse; } static VALUE @@ -575,9 +518,8 @@ test_e(obj, fname) { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - return TRUE; + if (rb_stat(fname, &st) < 0) return Qfalse; + return Qtrue; } static VALUE @@ -585,8 +527,8 @@ test_r(obj, fname) VALUE obj, fname; { Check_SafeStr(fname); - if (eaccess(RSTRING(fname)->ptr, R_OK) < 0) return FALSE; - return TRUE; + if (eaccess(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse; + return Qtrue; } static VALUE @@ -594,8 +536,8 @@ test_R(obj, fname) VALUE obj, fname; { Check_SafeStr(fname); - if (access(RSTRING(fname)->ptr, R_OK) < 0) return FALSE; - return TRUE; + if (access(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse; + return Qtrue; } static VALUE @@ -603,8 +545,8 @@ test_w(obj, fname) VALUE obj, fname; { Check_SafeStr(fname); - if (eaccess(RSTRING(fname)->ptr, W_OK) < 0) return FALSE; - return TRUE; + if (eaccess(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse; + return Qtrue; } static VALUE @@ -612,8 +554,8 @@ test_W(obj, fname) VALUE obj, fname; { Check_SafeStr(fname); - if (access(RSTRING(fname)->ptr, W_OK) < 0) return FALSE; - return TRUE; + if (access(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse; + return Qtrue; } static VALUE @@ -621,8 +563,8 @@ test_x(obj, fname) VALUE obj, fname; { Check_SafeStr(fname); - if (eaccess(RSTRING(fname)->ptr, X_OK) < 0) return FALSE; - return TRUE; + if (eaccess(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse; + return Qtrue; } static VALUE @@ -630,8 +572,8 @@ test_X(obj, fname) VALUE obj, fname; { Check_SafeStr(fname); - if (access(RSTRING(fname)->ptr, X_OK) < 0) return FALSE; - return TRUE; + if (access(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse; + return Qtrue; } #ifndef S_ISREG @@ -644,10 +586,9 @@ test_f(obj, fname) { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (S_ISREG(st.st_mode)) return TRUE; - return FALSE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (S_ISREG(st.st_mode)) return Qtrue; + return Qfalse; } static VALUE @@ -656,10 +597,9 @@ test_z(obj, fname) { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (st.st_size == 0) return TRUE; - return FALSE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (st.st_size == 0) return Qtrue; + return Qfalse; } static VALUE @@ -668,10 +608,9 @@ test_s(obj, fname) { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (st.st_size == 0) return FALSE; - return int2inum(st.st_size); + if (rb_stat(fname, &st) < 0) return Qfalse; + if (st.st_size == 0) return Qfalse; + return rb_int2inum(st.st_size); } static VALUE @@ -680,10 +619,9 @@ test_owned(obj, fname) { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (st.st_uid == geteuid()) return TRUE; - return FALSE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (st.st_uid == geteuid()) return Qtrue; + return Qfalse; } static VALUE @@ -692,10 +630,9 @@ test_rowned(obj, fname) { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (st.st_uid == getuid()) return TRUE; - return FALSE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (st.st_uid == getuid()) return Qtrue; + return Qfalse; } static VALUE @@ -705,11 +642,10 @@ test_grpowned(obj, fname) #ifndef NT struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) return FALSE; - if (st.st_gid == getegid()) return TRUE; + if (rb_stat(fname, &st) < 0) return Qfalse; + if (st.st_gid == getegid()) return Qtrue; #endif - return FALSE; + return Qfalse; } #if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX) @@ -720,9 +656,9 @@ check3rdbyte(file, mode) { struct stat st; - if (stat(file, &st) < 0) return FALSE; - if (st.st_mode & mode) return TRUE; - return FALSE; + if (stat(file, &st) < 0) return Qfalse; + if (st.st_mode & mode) return Qtrue; + return Qfalse; } #endif @@ -734,7 +670,7 @@ test_suid(obj, fname) Check_SafeStr(fname); return check3rdbyte(RSTRING(fname)->ptr, S_ISUID); #else - return FALSE; + return Qfalse; #endif } @@ -746,7 +682,7 @@ test_sgid(obj, fname) Check_SafeStr(fname); return check3rdbyte(RSTRING(fname)->ptr, S_ISGID); #else - return FALSE; + return Qfalse; #endif } @@ -754,36 +690,40 @@ static VALUE test_sticky(obj, fname) VALUE obj, fname; { - Check_Type(fname, T_STRING); #ifdef S_ISVTX - return check3rdbyte(RSTRING(fname)->ptr, S_ISVTX); + return check3rdbyte(STR2CSTR(fname), S_ISVTX); #else - return FALSE; + return Qfalse; #endif } static VALUE -file_s_size(obj, fname) +rb_file_s_size(obj, fname) VALUE obj, fname; { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) + if (rb_stat(fname, &st) < 0) rb_sys_fail(RSTRING(fname)->ptr); - return int2inum(st.st_size); + return rb_int2inum(st.st_size); } static VALUE -file_s_ftype(obj, fname) +rb_file_s_ftype(obj, fname) VALUE obj, fname; { struct stat st; char *t; +#if defined(MSDOS) || defined(NT) + if (rb_stat(fname, &st) < 0) + rb_sys_fail(RSTRING(fname)->ptr); +#else Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) + if (lstat(RSTRING(fname)->ptr, &st) == -1) { rb_sys_fail(RSTRING(fname)->ptr); + } +#endif if (S_ISREG(st.st_mode)) { t = "file"; @@ -816,23 +756,22 @@ file_s_ftype(obj, fname) t = "unknown"; } - return str_new2(t); + return rb_str_new2(t); } static VALUE -file_s_atime(obj, fname) +rb_file_s_atime(obj, fname) VALUE obj, fname; { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) + if (rb_stat(fname, &st) < 0) rb_sys_fail(RSTRING(fname)->ptr); - return time_new(st.st_atime, 0); + return rb_time_new(st.st_atime, 0); } static VALUE -file_atime(obj) +rb_file_atime(obj) VALUE obj; { OpenFile *fptr; @@ -842,23 +781,22 @@ file_atime(obj) if (fstat(fileno(fptr->f), &st) == -1) { rb_sys_fail(fptr->path); } - return time_new(st.st_atime, 0); + return rb_time_new(st.st_atime, 0); } static VALUE -file_s_mtime(obj, fname) +rb_file_s_mtime(obj, fname) VALUE obj, fname; { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) + if (rb_stat(fname, &st) < 0) rb_sys_fail(RSTRING(fname)->ptr); - return time_new(st.st_mtime, 0); + return rb_time_new(st.st_mtime, 0); } static VALUE -file_mtime(obj) +rb_file_mtime(obj) VALUE obj; { OpenFile *fptr; @@ -868,23 +806,22 @@ file_mtime(obj) if (fstat(fileno(fptr->f), &st) == -1) { rb_sys_fail(fptr->path); } - return time_new(st.st_mtime, 0); + return rb_time_new(st.st_mtime, 0); } static VALUE -file_s_ctime(obj, fname) +rb_file_s_ctime(obj, fname) VALUE obj, fname; { struct stat st; - Check_SafeStr(fname); - if (stat(RSTRING(fname)->ptr, &st) < 0) + if (rb_stat(fname, &st) < 0) rb_sys_fail(RSTRING(fname)->ptr); - return time_new(st.st_ctime, 0); + return rb_time_new(st.st_ctime, 0); } static VALUE -file_ctime(obj) +rb_file_ctime(obj) VALUE obj; { OpenFile *fptr; @@ -894,7 +831,7 @@ file_ctime(obj) if (fstat(fileno(fptr->f), &st) == -1) { rb_sys_fail(fptr->path); } - return time_new(st.st_ctime, 0); + return rb_time_new(st.st_ctime, 0); } static void @@ -907,7 +844,7 @@ chmod_internal(path, mode) } static VALUE -file_s_chmod(argc, argv) +rb_file_s_chmod(argc, argv) int argc; VALUE *argv; { @@ -923,17 +860,17 @@ file_s_chmod(argc, argv) } static VALUE -file_chmod(obj, vmode) +rb_file_chmod(obj, vmode) VALUE obj, vmode; { OpenFile *fptr; int mode; - rb_secure(2); + rb_secure(4); mode = NUM2INT(vmode); GetOpenFile(obj, fptr); -#if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT) +#if defined(DJGPP) || defined(NT) || defined(USE_CWGUSI) || defined(__BEOS__) if (chmod(fptr->path, mode) == -1) rb_sys_fail(fptr->path); #else @@ -958,7 +895,7 @@ chown_internal(path, args) } static VALUE -file_s_chown(argc, argv) +rb_file_s_chown(argc, argv) int argc; VALUE *argv; { @@ -985,14 +922,14 @@ file_s_chown(argc, argv) } static VALUE -file_chown(obj, owner, group) +rb_file_chown(obj, owner, group) VALUE obj, owner, group; { OpenFile *fptr; - rb_secure(2); + rb_secure(4); GetOpenFile(obj, fptr); -#if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT) +#if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT) || defined(USE_CWGUSI) if (chown(fptr->path, NUM2INT(owner), NUM2INT(group)) == -1) rb_sys_fail(fptr->path); #else @@ -1003,7 +940,7 @@ file_chown(obj, owner, group) return INT2FIX(0); } -struct timeval time_timeval(); +struct timeval rb_time_timeval(); #ifdef HAVE_UTIMES @@ -1017,7 +954,7 @@ utime_internal(path, tvp) } static VALUE -file_s_utime(argc, argv) +rb_file_s_utime(argc, argv) int argc; VALUE *argv; { @@ -1027,8 +964,8 @@ file_s_utime(argc, argv) rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest); - tvp[0] = time_timeval(atime); - tvp[1] = time_timeval(mtime); + tvp[0] = rb_time_timeval(atime); + tvp[1] = rb_time_timeval(mtime); n = apply2files(utime_internal, rest, tvp); return INT2FIX(n); @@ -1038,8 +975,14 @@ file_s_utime(argc, argv) #ifndef HAVE_UTIME_H # ifdef NT +# if defined(__BORLANDC__) +# include +# else # include +# endif +# if defined(_MSC_VER) # define utimbuf _utimbuf +# endif # else struct utimbuf { long actime; @@ -1058,7 +1001,7 @@ utime_internal(path, utp) } static VALUE -file_s_utime(argc, argv) +rb_file_s_utime(argc, argv) int argc; VALUE *argv; { @@ -1069,9 +1012,9 @@ file_s_utime(argc, argv) rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest); - tv = time_timeval(atime); + tv = rb_time_timeval(atime); utbuf.actime = tv.tv_sec; - tv = time_timeval(mtime); + tv = rb_time_timeval(mtime); utbuf.modtime = tv.tv_sec; n = apply2files(utime_internal, rest, &utbuf); @@ -1081,19 +1024,23 @@ file_s_utime(argc, argv) #endif static VALUE -file_s_link(obj, from, to) +rb_file_s_link(obj, from, to) VALUE obj, from, to; { +#if defined(USE_CWGUSI) + rb_notimplement(); +#else Check_SafeStr(from); Check_SafeStr(to); if (link(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0) rb_sys_fail(RSTRING(from)->ptr); return INT2FIX(0); +#endif /* USE_CWGUSI */ } static VALUE -file_s_symlink(obj, from, to) +rb_file_s_symlink(obj, from, to) VALUE obj, from, to; { #if !defined(MSDOS) && !defined(NT) @@ -1102,14 +1049,15 @@ 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(); + rb_notimplement(); + return Qnil; /* not reached */ #endif } static VALUE -file_s_readlink(obj, path) +rb_file_s_readlink(obj, path) VALUE obj, path; { #if !defined(MSDOS) && !defined(NT) @@ -1121,9 +1069,10 @@ file_s_readlink(obj, path) if ((cc = readlink(RSTRING(path)->ptr, buf, MAXPATHLEN)) < 0) rb_sys_fail(RSTRING(path)->ptr); - return str_new(buf, cc); + return rb_tainted_str_new(buf, cc); #else rb_notimplement(); + return Qnil; /* not reached */ #endif } @@ -1136,7 +1085,7 @@ unlink_internal(path) } static VALUE -file_s_unlink(obj, args) +rb_file_s_unlink(obj, args) VALUE obj, args; { int n; @@ -1146,7 +1095,7 @@ file_s_unlink(obj, args) } static VALUE -file_s_rename(obj, from, to) +rb_file_s_rename(obj, from, to) VALUE obj, from, to; { Check_SafeStr(from); @@ -1159,42 +1108,53 @@ file_s_rename(obj, from, to) } static VALUE -file_s_umask(argc, argv) +rb_file_s_umask(argc, argv) int argc; VALUE *argv; { +#ifdef USE_CWGUSI + rb_notimplement(); +#else int omask = 0; + rb_secure(4); if (argc == 0) { - int omask = umask(0); + omask = umask(0); umask(omask); } else if (argc == 1) { omask = umask(NUM2INT(argv[0])); } else { - ArgError("wrong # of argument"); + rb_raise(rb_eArgError, "wrong # of argument"); } return INT2FIX(omask); +#endif /* USE_CWGUSI */ } VALUE -file_s_expand_path(obj, fname) - VALUE obj, fname; +rb_file_s_expand_path(argc, argv) + int argc; + VALUE *argv; { + VALUE fname, dname; char *s, *p; - char buf[MAXPATHLEN]; + char buf[MAXPATHLEN+2]; - Check_Type(fname, T_STRING); - s = RSTRING(fname)->ptr; + rb_scan_args(argc, argv, "11", &fname, &dname); + s = STR2CSTR(fname); p = buf; if (s[0] == '~') { - if (s[1] == '/' || s[1] == '\0') { + if (s[1] == '/' || +#if defined(MSDOS) || defined(NT) || defined(__human68k__) + s[1] == '\\' || +#endif + s[1] == '\0') { char *dir = getenv("HOME"); if (!dir) { - Fail("couldn't find HOME environment -- expanding `%s'", s); + rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `%s'", s); } strcpy(buf, dir); p = &buf[strlen(buf)]; @@ -1205,7 +1165,6 @@ file_s_expand_path(obj, fname) struct passwd *pwPtr; s++; #endif - while (*s && *s != '/') { *p++ = *s++; } @@ -1214,7 +1173,7 @@ file_s_expand_path(obj, fname) pwPtr = getpwnam(buf); if (!pwPtr) { endpwent(); - Fail("user %s doesn't exist", buf); + rb_raise(rb_eArgError, "user %s doesn't exist", buf); } strcpy(buf, pwPtr->pw_dir); p = &buf[strlen(buf)]; @@ -1223,12 +1182,19 @@ file_s_expand_path(obj, fname) } } else if (s[0] != '/') { + if (argc == 2) { + dname = rb_file_s_expand_path(1, &dname); + strcpy(buf, RSTRING(dname)->ptr); + } + else { #ifdef HAVE_GETCWD - getcwd(buf, MAXPATHLEN); + getcwd(buf, MAXPATHLEN); #else - getwd(buf); + getwd(buf); #endif + } p = &buf[strlen(buf)]; + while (p > buf && *(p - 1) == '/') p--; } *p = '/'; @@ -1267,7 +1233,7 @@ file_s_expand_path(obj, fname) if (p == buf || *p != '/') p++; *p = '\0'; - return str_taint(str_new2(buf)); + return rb_tainted_str_new2(buf); } static int @@ -1294,67 +1260,68 @@ rmext(p, e) } static VALUE -file_s_basename(argc, argv) +rb_file_s_basename(argc, argv) int argc; VALUE *argv; { - VALUE fname, ext; - char *p; + VALUE fname, fext; + char *name, *p, *ext; int f; - rb_scan_args(argc, argv, "11", &fname, &ext); - Check_Type(fname, T_STRING); - if (!NIL_P(ext)) Check_Type(ext, T_STRING); - p = strrchr(RSTRING(fname)->ptr, '/'); + if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) { + ext = STR2CSTR(fext); + } + name = STR2CSTR(fname); + p = strrchr(name, '/'); if (!p) { - if (!NIL_P(ext)) { - f = rmext(RSTRING(fname)->ptr, RSTRING(ext)->ptr); - if (f) return str_new(RSTRING(fname)->ptr, f); + if (!NIL_P(fext)) { + f = rmext(name, ext); + if (f) return rb_str_new(name, f); } - return (VALUE)fname; + return fname; } p++; /* skip last `/' */ - if (!NIL_P(ext)) { - f = rmext(p, RSTRING(ext)->ptr); - if (f) return str_new(p, f); + if (!NIL_P(fext)) { + f = rmext(p, ext); + if (f) return rb_str_new(p, f); } - return str_taint(str_new2(p)); + return rb_tainted_str_new2(p); } static VALUE -file_s_dirname(obj, fname) +rb_file_s_dirname(obj, fname) VALUE obj, fname; { - UCHAR *p; + char *name, *p; - Check_Type(fname, T_STRING); - p = strrchr(RSTRING(fname)->ptr, '/'); + name = STR2CSTR(fname); + p = strrchr(name, '/'); if (!p) { - return str_new2("."); + return rb_str_new2("."); } - if (p == RSTRING(fname)->ptr) + if (p == name) p++; - return str_taint(str_new(RSTRING(fname)->ptr, p - RSTRING(fname)->ptr)); + return rb_tainted_str_new(name, p - name); } static VALUE -file_s_split(obj, path) +rb_file_s_split(obj, path) VALUE obj, path; { - return assoc_new(file_s_dirname(Qnil, path), file_s_basename(1,&path)); + return rb_assoc_new(rb_file_s_dirname(Qnil, path), rb_file_s_basename(1,&path)); } static VALUE separator; static VALUE -file_s_join(obj, args) +rb_file_s_join(obj, args) VALUE obj, args; { - return ary_join(args, separator); + return rb_ary_join(args, separator); } static VALUE -file_s_truncate(obj, path, len) +rb_file_s_truncate(obj, path, len) VALUE obj, path, len; { Check_SafeStr(path); @@ -1386,20 +1353,19 @@ file_s_truncate(obj, path, len) rb_notimplement(); # endif #endif - return TRUE; + return INT2FIX(0); } static VALUE -file_truncate(obj, len) +rb_file_truncate(obj, len) VALUE obj, len; { OpenFile *fptr; + rb_secure(4); GetOpenFile(obj, fptr); - - rb_secure(2); if (!(fptr->mode & FMODE_WRITABLE)) { - Fail("not opened for writing"); + rb_raise(rb_eIOError, "not opened for writing"); } #ifdef HAVE_TRUNCATE if (ftruncate(fileno(fptr->f), NUM2INT(len)) < 0) @@ -1412,29 +1378,71 @@ file_truncate(obj, len) rb_notimplement(); # endif #endif - return TRUE; + return INT2FIX(0); +} + +# ifndef LOCK_SH +# define LOCK_SH 1 +# endif +# ifndef LOCK_EX +# define LOCK_EX 2 +# endif +# ifndef LOCK_NB +# define LOCK_NB 4 +# endif +# ifndef LOCK_UN +# define LOCK_UN 8 +# endif + +#if defined(USE_THREAD) && defined(EWOULDBLOCK) +static int +rb_thread_flock(fd, op) + int fd, op; +{ + if (rb_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: + rb_thread_schedule(); /* busy wait */ + break; + default: + return -1; + } + } + return 0; } +#define flock rb_thread_flock +#endif static VALUE -file_flock(obj, operation) +rb_file_flock(obj, operation) VALUE obj; VALUE operation; { +#ifdef USE_CWGUSI + rb_notimplement(); +#else OpenFile *fptr; + rb_secure(4); GetOpenFile(obj, fptr); - rb_secure(2); if (flock(fileno(fptr->f), NUM2INT(operation)) < 0) { #ifdef EWOULDBLOCK if (errno == EWOULDBLOCK) { - return FALSE; + return Qfalse; } #endif rb_sys_fail(fptr->path); } - return obj; + return INT2FIX(0); +#endif /* USE_CWGUSI */ } +#undef flock static void test_check(n, argc, argv) @@ -1444,29 +1452,33 @@ test_check(n, argc, argv) int i; n+=1; - if (n < argc) ArgError("Wrong # of arguments(%d for %d)", argc, n); + if (n < argc) rb_raise(rb_eArgError, "Wrong # of arguments(%d for %d)", argc, n); for (i=1; ilen == 1) { - cmd = RSTRING(argv[0])->ptr[0]; - } - else { - cmd = NUM2INT(argv[0]); - } - if (cmd == 0) return FALSE; + if (argc == 0) rb_raise(rb_eArgError, "Wrong # of arguments"); + cmd = NUM2CHR(argv[0]); + if (cmd == 0) return Qfalse; if (strchr("bcdefgGkloOprRsSuwWxXz", cmd)) { CHECK(1); switch (cmd) { @@ -1543,17 +1555,17 @@ f_test(argc, argv) struct stat st; CHECK(1); - if (stat(RSTRING(argv[1])->ptr, &st) == -1) { + if (rb_stat(argv[1], &st) == -1) { rb_sys_fail(RSTRING(argv[1])->ptr); } switch (cmd) { case 'A': - return time_new(st.st_atime, 0); + return rb_time_new(st.st_atime, 0); case 'M': - return time_new(st.st_mtime, 0); + return rb_time_new(st.st_mtime, 0); case 'C': - return time_new(st.st_ctime, 0); + return rb_time_new(st.st_ctime, 0); } } @@ -1561,161 +1573,136 @@ f_test(argc, argv) struct stat st1, st2; CHECK(2); - if (stat(RSTRING(argv[1])->ptr, &st1) < 0) return FALSE; - if (stat(RSTRING(argv[2])->ptr, &st2) < 0) return FALSE; + if (rb_stat(argv[1], &st1) < 0) return Qfalse; + if (rb_stat(argv[2], &st2) < 0) return Qfalse; switch (cmd) { case '-': if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) - return TRUE; + return Qtrue; break; case '=': - if (st1.st_mtime == st2.st_mtime) return TRUE; + if (st1.st_mtime == st2.st_mtime) return Qtrue; break; case '>': - if (st1.st_mtime > st2.st_mtime) return TRUE; + if (st1.st_mtime > st2.st_mtime) return Qtrue; break; case '<': - if (st1.st_mtime < st2.st_mtime) return TRUE; + if (st1.st_mtime < st2.st_mtime) return Qtrue; break; } } - return FALSE; + /* unknown command */ + rb_raise(rb_eArgError, "unknow command ?%c", cmd); + return Qnil; /* not reached */ } -extern VALUE mKernel; - void Init_File() { - VALUE mConst; - - mFileTest = rb_define_module("FileTest"); - - rb_define_module_function(mFileTest, "directory?", test_d, 1); - rb_define_module_function(mFileTest, "exist?", test_e, 1); - rb_define_module_function(mFileTest, "exists?", test_e, 1); /* temporary */ - rb_define_module_function(mFileTest, "readable?", test_r, 1); - rb_define_module_function(mFileTest, "readable_real?", test_R, 1); - rb_define_module_function(mFileTest, "writable?", test_w, 1); - rb_define_module_function(mFileTest, "writable_real?", test_W, 1); - rb_define_module_function(mFileTest, "executable?", test_x, 1); - rb_define_module_function(mFileTest, "executable_real?", test_X, 1); - rb_define_module_function(mFileTest, "file?", test_f, 1); - rb_define_module_function(mFileTest, "zero?", test_z, 1); - rb_define_module_function(mFileTest, "size?", test_s, 1); - rb_define_module_function(mFileTest, "size", test_s, 1); - rb_define_module_function(mFileTest, "owned?", test_owned, 1); - rb_define_module_function(mFileTest, "grpowned?", test_grpowned, 1); - - rb_define_module_function(mFileTest, "pipe?", test_p, 1); - rb_define_module_function(mFileTest, "symlink?", test_l, 1); - rb_define_module_function(mFileTest, "socket?", test_S, 1); - - rb_define_module_function(mFileTest, "blockdev?", test_b, 1); - rb_define_module_function(mFileTest, "chardev?", test_c, 1); - - rb_define_module_function(mFileTest, "setuid?", test_suid, 1); - rb_define_module_function(mFileTest, "setgid?", test_sgid, 1); - rb_define_module_function(mFileTest, "sticky?", test_sticky, 1); - - cFile = rb_define_class("File", cIO); - rb_extend_object(cFile, CLASS_OF(mFileTest)); - - rb_define_singleton_method(cFile, "new", file_s_open, -1); - rb_define_singleton_method(cFile, "open", file_s_open, -1); - - rb_define_singleton_method(cFile, "stat", file_s_stat, 1); - rb_define_singleton_method(cFile, "lstat", file_s_lstat, 1); - rb_define_singleton_method(cFile, "ftype", file_s_ftype, 1); - - rb_define_singleton_method(cFile, "atime", file_s_atime, 1); - rb_define_singleton_method(cFile, "mtime", file_s_mtime, 1); - rb_define_singleton_method(cFile, "ctime", file_s_ctime, 1); - rb_define_singleton_method(cFile, "size", file_s_size, 1); - - rb_define_singleton_method(cFile, "utime", file_s_utime, -1); - rb_define_singleton_method(cFile, "chmod", file_s_chmod, -1); - rb_define_singleton_method(cFile, "chown", file_s_chown, -1); - - rb_define_singleton_method(cFile, "link", file_s_link, 2); - rb_define_singleton_method(cFile, "symlink", file_s_symlink, 2); - rb_define_singleton_method(cFile, "readlink", file_s_readlink, 1); - - rb_define_singleton_method(cFile, "unlink", file_s_unlink, -2); - rb_define_singleton_method(cFile, "delete", file_s_unlink, -2); - rb_define_singleton_method(cFile, "rename", file_s_rename, 2); - rb_define_singleton_method(cFile, "umask", file_s_umask, -1); - rb_define_singleton_method(cFile, "truncate", file_s_truncate, 2); - rb_define_singleton_method(cFile, "expand_path", file_s_expand_path, 1); - rb_define_singleton_method(cFile, "basename", file_s_basename, -1); - rb_define_singleton_method(cFile, "dirname", file_s_dirname, 1); - - separator = str_new2("/"); - rb_define_const(cFile, "Separator", separator); - rb_define_singleton_method(cFile, "split", file_s_split, 1); - rb_define_singleton_method(cFile, "join", file_s_join, -2); - - rb_define_method(cFile, "reopen", file_reopen, -1); - - rb_define_method(cFile, "stat", file_stat, 0); - rb_define_method(cFile, "lstat", file_lstat, 0); - - rb_define_method(cFile, "atime", file_atime, 0); - rb_define_method(cFile, "mtime", file_mtime, 0); - rb_define_method(cFile, "ctime", file_ctime, 0); - - rb_define_method(cFile, "chmod", file_chmod, 1); - rb_define_method(cFile, "chown", file_chown, 2); - rb_define_method(cFile, "truncate", file_truncate, 1); - - rb_define_method(cFile, "tell", file_tell, 0); - rb_define_method(cFile, "seek", file_seek, 2); - - rb_define_method(cFile, "pos", file_tell, 0); - rb_define_method(cFile, "pos=", file_set_pos, 1); - - rb_define_method(cFile, "rewind", file_rewind, 0); - rb_define_method(cFile, "isatty", file_isatty, 0); - rb_define_method(cFile, "tty?", file_isatty, 0); - rb_define_method(cFile, "eof", file_eof, 0); - rb_define_method(cFile, "eof?", file_eof, 0); - - rb_define_method(cFile, "flock", file_flock, 1); - -# ifndef LOCK_SH -# define LOCK_SH 1 -# endif -# ifndef LOCK_EX -# define LOCK_EX 2 -# endif -# ifndef LOCK_NB -# define LOCK_NB 4 -# endif -# ifndef LOCK_UN -# define LOCK_UN 8 -# endif - - mConst = rb_define_module_under(cFile, "Constants"); - rb_define_const(cFile, "LOCK_SH", INT2FIX(LOCK_SH)); - rb_define_const(cFile, "LOCK_EX", INT2FIX(LOCK_EX)); - rb_define_const(cFile, "LOCK_UN", INT2FIX(LOCK_UN)); - rb_define_const(cFile, "LOCK_NB", INT2FIX(LOCK_NB)); - - rb_define_const(mConst, "LOCK_SH", INT2FIX(LOCK_SH)); - rb_define_const(mConst, "LOCK_EX", INT2FIX(LOCK_EX)); - rb_define_const(mConst, "LOCK_UN", INT2FIX(LOCK_UN)); - rb_define_const(mConst, "LOCK_NB", INT2FIX(LOCK_NB)); - - rb_define_method(cFile, "path", file_path, 0); - - rb_define_global_function("test", f_test, -1); - - sStat = struct_define("Stat", "dev", "ino", "mode", - "nlink", "uid", "gid", "rdev", - "size", "blksize", "blocks", - "atime", "mtime", "ctime", 0); + VALUE rb_mConst; + + rb_mFileTest = rb_define_module("FileTest"); + + rb_define_module_function(rb_mFileTest, "directory?", test_d, 1); + rb_define_module_function(rb_mFileTest, "exist?", test_e, 1); + rb_define_module_function(rb_mFileTest, "exists?", test_e, 1); /* temporary */ + rb_define_module_function(rb_mFileTest, "readable?", test_r, 1); + rb_define_module_function(rb_mFileTest, "readable_real?", test_R, 1); + rb_define_module_function(rb_mFileTest, "writable?", test_w, 1); + rb_define_module_function(rb_mFileTest, "writable_real?", test_W, 1); + rb_define_module_function(rb_mFileTest, "executable?", test_x, 1); + rb_define_module_function(rb_mFileTest, "executable_real?", test_X, 1); + rb_define_module_function(rb_mFileTest, "file?", test_f, 1); + rb_define_module_function(rb_mFileTest, "zero?", test_z, 1); + rb_define_module_function(rb_mFileTest, "size?", test_s, 1); + rb_define_module_function(rb_mFileTest, "size", test_s, 1); + rb_define_module_function(rb_mFileTest, "owned?", test_owned, 1); + rb_define_module_function(rb_mFileTest, "grpowned?", test_grpowned, 1); + + rb_define_module_function(rb_mFileTest, "pipe?", test_p, 1); + rb_define_module_function(rb_mFileTest, "symlink?", test_l, 1); + rb_define_module_function(rb_mFileTest, "socket?", test_S, 1); + + rb_define_module_function(rb_mFileTest, "blockdev?", test_b, 1); + rb_define_module_function(rb_mFileTest, "chardev?", test_c, 1); + + rb_define_module_function(rb_mFileTest, "setuid?", test_suid, 1); + rb_define_module_function(rb_mFileTest, "setgid?", test_sgid, 1); + rb_define_module_function(rb_mFileTest, "sticky?", test_sticky, 1); + + rb_cFile = rb_define_class("File", rb_cIO); + rb_extend_object(rb_cFile, CLASS_OF(rb_mFileTest)); + + rb_define_singleton_method(rb_cFile, "new", rb_file_s_open, -1); + rb_define_singleton_method(rb_cFile, "open", rb_file_s_open, -1); + + rb_define_singleton_method(rb_cFile, "stat", rb_file_s_stat, 1); + rb_define_singleton_method(rb_cFile, "lstat", rb_file_s_lstat, 1); + rb_define_singleton_method(rb_cFile, "ftype", rb_file_s_ftype, 1); + + rb_define_singleton_method(rb_cFile, "atime", rb_file_s_atime, 1); + rb_define_singleton_method(rb_cFile, "mtime", rb_file_s_mtime, 1); + rb_define_singleton_method(rb_cFile, "ctime", rb_file_s_ctime, 1); + rb_define_singleton_method(rb_cFile, "size", rb_file_s_size, 1); + + rb_define_singleton_method(rb_cFile, "utime", rb_file_s_utime, -1); + rb_define_singleton_method(rb_cFile, "chmod", rb_file_s_chmod, -1); + rb_define_singleton_method(rb_cFile, "chown", rb_file_s_chown, -1); + + rb_define_singleton_method(rb_cFile, "link", rb_file_s_link, 2); + rb_define_singleton_method(rb_cFile, "symlink", rb_file_s_symlink, 2); + rb_define_singleton_method(rb_cFile, "readlink", rb_file_s_readlink, 1); + + rb_define_singleton_method(rb_cFile, "unlink", rb_file_s_unlink, -2); + rb_define_singleton_method(rb_cFile, "delete", rb_file_s_unlink, -2); + rb_define_singleton_method(rb_cFile, "rename", rb_file_s_rename, 2); + rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1); + rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2); + rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1); + rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1); + rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1); + + separator = rb_str_new2("/"); + rb_define_const(rb_cFile, "Separator", separator); + rb_define_singleton_method(rb_cFile, "split", rb_file_s_split, 1); + rb_define_singleton_method(rb_cFile, "join", rb_file_s_join, -2); + + rb_define_method(rb_cFile, "reopen", rb_file_reopen, -1); + + rb_define_method(rb_cIO, "stat", rb_io_stat, 0); /* this is IO's method */ + rb_define_method(rb_cFile, "lstat", rb_file_lstat, 0); + + rb_define_method(rb_cFile, "atime", rb_file_atime, 0); + rb_define_method(rb_cFile, "mtime", rb_file_mtime, 0); + rb_define_method(rb_cFile, "ctime", rb_file_ctime, 0); + + rb_define_method(rb_cFile, "chmod", rb_file_chmod, 1); + rb_define_method(rb_cFile, "chown", rb_file_chown, 2); + rb_define_method(rb_cFile, "truncate", rb_file_truncate, 1); + + rb_define_method(rb_cFile, "flock", rb_file_flock, 1); + + rb_mConst = rb_define_module_under(rb_cFile, "Constants"); + rb_define_const(rb_cFile, "LOCK_SH", INT2FIX(LOCK_SH)); + rb_define_const(rb_cFile, "LOCK_EX", INT2FIX(LOCK_EX)); + rb_define_const(rb_cFile, "LOCK_UN", INT2FIX(LOCK_UN)); + rb_define_const(rb_cFile, "LOCK_NB", INT2FIX(LOCK_NB)); + + rb_define_const(rb_mConst, "LOCK_SH", INT2FIX(LOCK_SH)); + rb_define_const(rb_mConst, "LOCK_EX", INT2FIX(LOCK_EX)); + rb_define_const(rb_mConst, "LOCK_UN", INT2FIX(LOCK_UN)); + rb_define_const(rb_mConst, "LOCK_NB", INT2FIX(LOCK_NB)); + + rb_define_method(rb_cFile, "path", rb_file_path, 0); + + rb_define_global_function("test", rb_f_test, -1); + + sStat = rb_struct_define("Stat", "dev", "ino", "mode", + "nlink", "uid", "gid", "rdev", + "size", "blksize", "blocks", + "atime", "mtime", "ctime", 0); } -- cgit v1.2.3