2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
file.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Mon Nov 15 12:24:34 JST 1993
|
|
|
|
|
2003-01-16 10:34:03 +03:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#ifdef _WIN32
|
1999-01-20 07:59:39 +03:00
|
|
|
#include "missing/file.h"
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#include "ruby.h"
|
1999-01-20 07:59:39 +03:00
|
|
|
#include "rubyio.h"
|
|
|
|
#include "rubysig.h"
|
2001-11-08 09:43:14 +03:00
|
|
|
#include "util.h"
|
2000-01-05 07:41:21 +03:00
|
|
|
#include "dln.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2000-05-12 13:07:57 +04:00
|
|
|
#ifdef HAVE_SYS_FILE_H
|
|
|
|
# include <sys/file.h>
|
|
|
|
#else
|
|
|
|
int flock _((int, int));
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
2002-11-22 12:14:24 +03:00
|
|
|
#endif
|
|
|
|
#ifndef MAXPATHLEN
|
1998-01-16 15:13:05 +03:00
|
|
|
# define MAXPATHLEN 1024
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#include <time.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
VALUE rb_time_new _((time_t, time_t));
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef HAVE_UTIME_H
|
|
|
|
#include <utime.h>
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#elif defined HAVE_SYS_UTIME_H
|
|
|
|
#include <sys/utime.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
#ifndef HAVE_STRING_H
|
1999-08-13 09:45:20 +04:00
|
|
|
char *strrchr _((const char*,const char));
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#include <sys/types.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2002-01-29 12:15:59 +03:00
|
|
|
#ifdef HAVE_SYS_MKDEV_H
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#endif
|
|
|
|
|
2000-09-21 13:31:00 +04:00
|
|
|
#ifndef HAVE_LSTAT
|
2001-03-21 06:51:23 +03:00
|
|
|
#define lstat(path,st) stat(path,st)
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
2001-07-16 08:22:46 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_cFile;
|
|
|
|
VALUE rb_mFileTest;
|
1999-12-01 12:24:48 +03:00
|
|
|
static VALUE rb_cStat;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-08-28 12:05:23 +04:00
|
|
|
static long
|
1998-01-16 15:19:22 +03:00
|
|
|
apply2files(func, vargs, arg)
|
2001-09-19 10:54:11 +04:00
|
|
|
void (*func)();
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE vargs;
|
1998-01-16 15:13:05 +03:00
|
|
|
void *arg;
|
|
|
|
{
|
2002-08-21 19:47:54 +04:00
|
|
|
long i;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE path;
|
1998-01-16 15:19:22 +03:00
|
|
|
struct RArray *args = RARRAY(vargs);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
for (i=0; i<args->len; i++) {
|
|
|
|
path = args->ptr[i];
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(path);
|
2001-09-19 10:54:11 +04:00
|
|
|
(*func)(RSTRING(path)->ptr, arg);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return args->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_path(obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
1999-12-14 09:50:43 +03:00
|
|
|
if (!fptr->path) return Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_str_new2(fptr->path);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
stat_new_0(klass, st)
|
|
|
|
VALUE klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct stat *st;
|
|
|
|
{
|
2001-10-03 11:19:19 +04:00
|
|
|
struct stat *nst = 0;
|
1999-12-01 12:24:48 +03:00
|
|
|
|
2001-10-03 11:19:19 +04:00
|
|
|
if (st) {
|
|
|
|
nst = ALLOC(struct stat);
|
|
|
|
*nst = *st;
|
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
return Data_Wrap_Struct(klass, NULL, free, nst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
stat_new(st)
|
|
|
|
struct stat *st;
|
|
|
|
{
|
|
|
|
return stat_new_0(rb_cStat, st);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct stat*
|
|
|
|
get_stat(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
struct stat* st;
|
|
|
|
Data_Get_Struct(self, struct stat, st);
|
2001-10-03 11:19:19 +04:00
|
|
|
if (!st) rb_raise(rb_eTypeError, "uninitialized File::Stat");
|
1999-12-01 12:24:48 +03:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_cmp(self, other)
|
|
|
|
VALUE self, other;
|
|
|
|
{
|
2001-10-29 08:07:26 +03:00
|
|
|
if (rb_obj_is_kind_of(other, rb_obj_class(self))) {
|
|
|
|
time_t t1 = get_stat(self)->st_mtime;
|
|
|
|
time_t t2 = get_stat(other)->st_mtime;
|
|
|
|
if (t1 == t2)
|
|
|
|
return INT2FIX(0);
|
|
|
|
else if (t1 < t2)
|
|
|
|
return INT2FIX(-1);
|
|
|
|
else
|
|
|
|
return INT2FIX(1);
|
|
|
|
}
|
2002-11-22 12:14:24 +03:00
|
|
|
return Qnil;
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_dev(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
return INT2NUM(get_stat(self)->st_dev);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_ino(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_ino);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_mode(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2002-06-11 05:27:48 +04:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
return UINT2NUM((unsigned short)(get_stat(self)->st_mode));
|
|
|
|
#else
|
|
|
|
return UINT2NUM(get_stat(self)->st_mode);
|
|
|
|
#endif
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_nlink(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
return UINT2NUM(get_stat(self)->st_nlink);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_uid(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
return UINT2NUM(get_stat(self)->st_uid);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_gid(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
return UINT2NUM(get_stat(self)->st_gid);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_rdev(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef HAVE_ST_RDEV
|
2001-05-02 08:22:21 +04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_rdev);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2002-08-12 11:39:12 +04:00
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
2002-01-29 10:16:09 +03:00
|
|
|
static VALUE
|
|
|
|
rb_stat_rdev_major(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
#if defined(HAVE_ST_RDEV) && defined(major)
|
|
|
|
long rdev = get_stat(self)->st_rdev;
|
|
|
|
return ULONG2NUM(major(rdev));
|
|
|
|
#else
|
2002-08-12 11:39:12 +04:00
|
|
|
return Qnil;
|
2002-01-29 10:16:09 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_rdev_minor(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
#if defined(HAVE_ST_RDEV) && defined(minor)
|
|
|
|
long rdev = get_stat(self)->st_rdev;
|
|
|
|
return ULONG2NUM(minor(rdev));
|
|
|
|
#else
|
2002-08-12 11:39:12 +04:00
|
|
|
return Qnil;
|
2002-01-29 10:16:09 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-12-01 12:24:48 +03:00
|
|
|
static VALUE
|
|
|
|
rb_stat_size(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2002-03-14 09:23:46 +03:00
|
|
|
return OFFT2NUM(get_stat(self)->st_size);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_blksize(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
2001-05-02 08:22:21 +04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_blksize);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2002-08-12 11:39:12 +04:00
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_blocks(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef HAVE_ST_BLOCKS
|
2001-05-02 08:22:21 +04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_blocks);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2002-08-12 11:39:12 +04:00
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_atime(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
return rb_time_new(get_stat(self)->st_atime, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_mtime(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
return rb_time_new(get_stat(self)->st_mtime, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_ctime(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
return rb_time_new(get_stat(self)->st_ctime, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2000-06-19 12:38:11 +04:00
|
|
|
static VALUE
|
|
|
|
rb_stat_inspect(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
int i;
|
2002-05-29 09:20:39 +04:00
|
|
|
static struct {
|
2000-06-19 12:38:11 +04:00
|
|
|
char *name;
|
|
|
|
VALUE (*func)();
|
|
|
|
} member[] = {
|
|
|
|
{"dev", rb_stat_dev},
|
|
|
|
{"ino", rb_stat_ino},
|
|
|
|
{"mode", rb_stat_mode},
|
|
|
|
{"nlink", rb_stat_nlink},
|
|
|
|
{"uid", rb_stat_uid},
|
|
|
|
{"gid", rb_stat_gid},
|
|
|
|
{"rdev", rb_stat_rdev},
|
|
|
|
{"size", rb_stat_size},
|
|
|
|
{"blksize", rb_stat_blksize},
|
|
|
|
{"blocks", rb_stat_blocks},
|
|
|
|
{"atime", rb_stat_atime},
|
|
|
|
{"mtime", rb_stat_mtime},
|
|
|
|
{"ctime", rb_stat_ctime},
|
|
|
|
};
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
str = rb_str_buf_new2("#<");
|
|
|
|
rb_str_buf_cat2(str, rb_class2name(CLASS_OF(self)));
|
|
|
|
rb_str_buf_cat2(str, " ");
|
2000-06-19 12:38:11 +04:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) {
|
2002-01-29 10:16:09 +03:00
|
|
|
VALUE v;
|
2000-06-19 12:38:11 +04:00
|
|
|
|
|
|
|
if (i > 0) {
|
2001-05-30 13:12:34 +04:00
|
|
|
rb_str_buf_cat2(str, ", ");
|
2000-06-19 12:38:11 +04:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
rb_str_buf_cat2(str, member[i].name);
|
|
|
|
rb_str_buf_cat2(str, "=");
|
2002-01-29 10:16:09 +03:00
|
|
|
v = (*member[i].func)(self);
|
|
|
|
if (i == 2) { /* mode */
|
|
|
|
char buf[32];
|
|
|
|
|
2002-10-30 00:35:28 +03:00
|
|
|
sprintf(buf, "0%o", NUM2INT(v));
|
2002-01-29 10:16:09 +03:00
|
|
|
rb_str_buf_cat2(str, buf);
|
|
|
|
}
|
2002-02-01 09:03:03 +03:00
|
|
|
else if (i == 0 || i == 6) { /* dev/rdev */
|
|
|
|
char buf[32];
|
|
|
|
|
2002-05-29 09:20:39 +04:00
|
|
|
sprintf(buf, "0x%lx", NUM2ULONG(v));
|
2002-02-01 09:03:03 +03:00
|
|
|
rb_str_buf_cat2(str, buf);
|
|
|
|
}
|
2002-01-29 10:16:09 +03:00
|
|
|
else {
|
|
|
|
rb_str_append(str, rb_inspect(v));
|
|
|
|
}
|
2000-06-19 12:38:11 +04:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
rb_str_buf_cat2(str, ">");
|
2000-06-19 12:38:11 +04:00
|
|
|
OBJ_INFECT(str, self);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int
|
|
|
|
rb_stat(file, st)
|
|
|
|
VALUE file;
|
|
|
|
struct stat *st;
|
|
|
|
{
|
|
|
|
if (TYPE(file) == T_FILE) {
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1999-01-20 07:59:39 +03:00
|
|
|
GetOpenFile(file, fptr);
|
|
|
|
return fstat(fileno(fptr->f), st);
|
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(file);
|
1999-08-13 09:45:20 +04:00
|
|
|
#if defined DJGPP
|
|
|
|
if (RSTRING(file)->len == 0) return -1;
|
|
|
|
#endif
|
2001-03-21 06:51:23 +03:00
|
|
|
return stat(RSTRING(file)->ptr, st);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_stat(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
2001-03-21 06:51:23 +03:00
|
|
|
if (stat(RSTRING(fname)->ptr, &st) == -1) {
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_stat(obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
if (fstat(fileno(fptr->f), &st) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_lstat(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-09-21 13:31:00 +04:00
|
|
|
#ifdef HAVE_LSTAT
|
1998-01-16 15:13:05 +03:00
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1998-01-16 15:19:22 +03:00
|
|
|
if (lstat(RSTRING(fname)->ptr, &st) == -1) {
|
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
#else
|
2001-05-02 08:22:21 +04:00
|
|
|
return rb_file_s_stat(klass, fname);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_lstat(obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-09-21 13:31:00 +04:00
|
|
|
#ifdef HAVE_LSTAT
|
1998-01-16 15:13:05 +03:00
|
|
|
OpenFile *fptr;
|
|
|
|
struct stat st;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(obj, fptr);
|
1999-12-14 09:50:43 +03:00
|
|
|
if (!fptr->path) return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (lstat(fptr->path, &st) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
#else
|
2000-09-21 13:31:00 +04:00
|
|
|
return rb_io_stat(obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
group_member(gid)
|
|
|
|
GETGROUPS_T gid;
|
|
|
|
{
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#ifndef _WIN32
|
2001-08-23 10:02:15 +04:00
|
|
|
if (getgid() == gid)
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
# ifdef HAVE_GETGROUPS
|
|
|
|
# ifndef NGROUPS
|
2001-10-10 12:21:13 +04:00
|
|
|
# ifdef NGROUPS_MAX
|
|
|
|
# define NGROUPS NGROUPS_MAX
|
|
|
|
# else
|
1998-01-16 15:13:05 +03:00
|
|
|
# define NGROUPS 32
|
2001-10-10 12:21:13 +04:00
|
|
|
# endif
|
1998-01-16 15:13:05 +03:00
|
|
|
# endif
|
|
|
|
{
|
|
|
|
GETGROUPS_T gary[NGROUPS];
|
|
|
|
int anum;
|
|
|
|
|
|
|
|
anum = getgroups(NGROUPS, gary);
|
|
|
|
while (--anum >= 0)
|
|
|
|
if (gary[anum] == gid)
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef S_IXUGO
|
|
|
|
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
eaccess(path, mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *path;
|
1998-01-16 15:13:05 +03:00
|
|
|
int mode;
|
|
|
|
{
|
2003-01-19 18:19:52 +03:00
|
|
|
#if defined(S_IXGRP) && !defined(_WIN32)
|
2001-08-23 10:02:15 +04:00
|
|
|
struct stat st;
|
|
|
|
int euid;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-23 10:02:15 +04:00
|
|
|
if (stat(path, &st) < 0) return -1;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-23 10:02:15 +04:00
|
|
|
euid = geteuid();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-23 10:02:15 +04:00
|
|
|
if (euid == 0) {
|
|
|
|
/* Root can read or write any file. */
|
|
|
|
if (!(mode & X_OK))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Root can execute any file that has any one of the execute
|
|
|
|
bits set. */
|
|
|
|
if (st.st_mode & S_IXUGO)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2001-08-23 10:02:15 +04:00
|
|
|
if (st.st_uid == euid) /* owner */
|
|
|
|
mode <<= 6;
|
|
|
|
else if (getegid() == st.st_gid || group_member(st.st_gid))
|
|
|
|
mode <<= 3;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-23 10:02:15 +04:00
|
|
|
if ((st.st_mode & mode) == mode) return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-23 10:02:15 +04:00
|
|
|
return -1;
|
2001-05-30 13:12:34 +04:00
|
|
|
#else
|
2001-08-23 10:02:15 +04:00
|
|
|
return access(path, mode);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_d(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISDIR(st.st_mode)) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_p(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifdef S_IFIFO
|
|
|
|
# ifndef S_ISFIFO
|
|
|
|
# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
|
|
|
|
# endif
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISFIFO(st.st_mode)) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_l(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
# ifdef _S_ISLNK
|
|
|
|
# define S_ISLNK(m) _S_ISLNK(m)
|
2002-06-11 05:27:48 +04:00
|
|
|
# elif defined __BORLANDC__
|
|
|
|
# ifdef _S_IFLNK
|
|
|
|
# define S_ISLNK(m) (((unsigned short)(m) & S_IFMT) == _S_IFLNK)
|
|
|
|
# else
|
|
|
|
# ifdef S_IFLNK
|
|
|
|
# define S_ISLNK(m) (((unsigned short)(m) & S_IFMT) == S_IFLNK)
|
|
|
|
# endif
|
|
|
|
# endif
|
1998-01-16 15:13:05 +03:00
|
|
|
# else
|
|
|
|
# ifdef _S_IFLNK
|
|
|
|
# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
|
|
|
|
# else
|
|
|
|
# ifdef S_IFLNK
|
|
|
|
# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef S_ISLNK
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (lstat(RSTRING(fname)->ptr, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISLNK(st.st_mode)) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-12-14 09:50:43 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_S(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifndef S_ISSOCK
|
|
|
|
# ifdef _S_ISSOCK
|
|
|
|
# define S_ISSOCK(m) _S_ISSOCK(m)
|
2002-06-11 05:27:48 +04:00
|
|
|
# elif defined __BORLANDC__
|
|
|
|
# ifdef _S_IFSOCK
|
|
|
|
# define S_ISSOCK(m) (((unsigned short)(m) & S_IFMT) == _S_IFSOCK)
|
|
|
|
# else
|
|
|
|
# ifdef S_IFSOCK
|
|
|
|
# define S_ISSOCK(m) (((unsigned short)(m) & S_IFMT) == S_IFSOCK)
|
|
|
|
# endif
|
|
|
|
# endif
|
1998-01-16 15:13:05 +03:00
|
|
|
# else
|
|
|
|
# ifdef _S_IFSOCK
|
|
|
|
# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
|
|
|
|
# else
|
|
|
|
# ifdef S_IFSOCK
|
|
|
|
# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef S_ISSOCK
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISSOCK(st.st_mode)) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_b(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifndef S_ISBLK
|
|
|
|
# ifdef S_IFBLK
|
|
|
|
# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
|
|
|
|
# else
|
|
|
|
# define S_ISBLK(m) (0) /* anytime false */
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef S_ISBLK
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISBLK(st.st_mode)) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_c(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifndef S_ISCHR
|
|
|
|
# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
2000-02-01 06:12:21 +03:00
|
|
|
if (S_ISCHR(st.st_mode)) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_e(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_r(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (eaccess(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_R(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (access(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_w(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (eaccess(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_W(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (access(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_x(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (eaccess(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_X(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (access(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef S_ISREG
|
|
|
|
# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_f(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISREG(st.st_mode)) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_z(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_size == 0) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_s(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qnil;
|
|
|
|
if (st.st_size == 0) return Qnil;
|
2002-03-14 09:23:46 +03:00
|
|
|
return OFFT2NUM(st.st_size);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_owned(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_uid == geteuid()) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_rowned(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_uid == getuid()) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_grpowned(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#ifndef _WIN32
|
1998-01-16 15:13:05 +03:00
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_gid == getegid()) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX)
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
check3rdbyte(fname, mode)
|
|
|
|
VALUE fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
|
|
|
if (stat(RSTRING(fname)->ptr, &st) < 0) return Qfalse;
|
1999-01-20 07:59:39 +03:00
|
|
|
if (st.st_mode & mode) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_suid(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifdef S_ISUID
|
2001-05-02 08:22:21 +04:00
|
|
|
return check3rdbyte(fname, S_ISUID);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_sgid(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-05-13 20:13:31 +04:00
|
|
|
#ifdef S_ISGID
|
2001-05-02 08:22:21 +04:00
|
|
|
return check3rdbyte(fname, S_ISGID);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_sticky(obj, fname)
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifdef S_ISVTX
|
2001-05-02 08:22:21 +04:00
|
|
|
return check3rdbyte(fname, S_ISVTX);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
1999-08-13 09:45:20 +04:00
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_size(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
2002-08-28 12:05:23 +04:00
|
|
|
return OFFT2NUM(st.st_size);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-12-07 12:25:55 +03:00
|
|
|
rb_file_ftype(st)
|
|
|
|
struct stat *st;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
1999-12-07 12:25:55 +03:00
|
|
|
if (S_ISREG(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "file";
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
|
|
|
else if (S_ISDIR(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "directory";
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
|
|
|
else if (S_ISCHR(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "characterSpecial";
|
|
|
|
}
|
|
|
|
#ifdef S_ISBLK
|
1999-12-07 12:25:55 +03:00
|
|
|
else if (S_ISBLK(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "blockSpecial";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef S_ISFIFO
|
1999-12-07 12:25:55 +03:00
|
|
|
else if (S_ISFIFO(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "fifo";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef S_ISLNK
|
1999-12-07 12:25:55 +03:00
|
|
|
else if (S_ISLNK(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "link";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef S_ISSOCK
|
1999-12-07 12:25:55 +03:00
|
|
|
else if (S_ISSOCK(st->st_mode)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
t = "socket";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
t = "unknown";
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_str_new2(t);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-11-25 12:03:08 +03:00
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_ftype(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1999-11-25 12:03:08 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(fname);
|
1999-11-25 12:03:08 +03:00
|
|
|
if (lstat(RSTRING(fname)->ptr, &st) == -1) {
|
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
|
|
|
}
|
|
|
|
|
1999-12-07 12:25:55 +03:00
|
|
|
return rb_file_ftype(&st);
|
1999-11-25 12:03:08 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_atime(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_atime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_atime(obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
if (fstat(fileno(fptr->f), &st) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_atime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_mtime(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_mtime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_mtime(obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
if (fstat(fileno(fptr->f), &st) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_mtime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_ctime(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_ctime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_ctime(obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
if (fstat(fileno(fptr->f), &st) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_ctime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chmod_internal(path, mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *path;
|
1998-01-16 15:13:05 +03:00
|
|
|
int mode;
|
|
|
|
{
|
2001-09-19 10:54:11 +04:00
|
|
|
if (chmod(path, mode) < 0)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_chmod(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE vmode;
|
|
|
|
VALUE rest;
|
2002-08-28 12:05:23 +04:00
|
|
|
int mode;
|
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-12 13:07:57 +04:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_scan_args(argc, argv, "1*", &vmode, &rest);
|
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
|
2002-12-31 13:28:52 +03:00
|
|
|
n = apply2files(chmod_internal, rest, (void *)(long)mode);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_chmod(obj, vmode)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj, vmode;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
int mode;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
2000-11-13 08:39:35 +03:00
|
|
|
#ifdef HAVE_FCHMOD
|
|
|
|
if (fchmod(fileno(fptr->f), mode) == -1)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#else
|
2000-11-13 08:39:35 +03:00
|
|
|
if (!fptr->path) return Qnil;
|
|
|
|
if (chmod(fptr->path, mode) == -1)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2001-02-16 10:53:21 +03:00
|
|
|
#if defined(HAVE_LCHMOD)
|
|
|
|
static void
|
|
|
|
lchmod_internal(path, mode)
|
|
|
|
const char *path;
|
|
|
|
int mode;
|
|
|
|
{
|
2001-09-19 10:54:11 +04:00
|
|
|
if (lchmod(path, mode) < 0)
|
2001-02-16 10:53:21 +03:00
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchmod(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE vmode;
|
|
|
|
VALUE rest;
|
2002-08-28 12:05:23 +04:00
|
|
|
int mode;
|
|
|
|
long n;
|
2001-02-16 10:53:21 +03:00
|
|
|
|
|
|
|
rb_secure(2);
|
|
|
|
rb_scan_args(argc, argv, "1*", &vmode, &rest);
|
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
|
2003-01-03 19:52:56 +03:00
|
|
|
n = apply2files(lchmod_internal, rest, (void *)(long)mode);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
2001-02-16 10:53:21 +03:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchmod(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
struct chown_args {
|
|
|
|
int owner, group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
chown_internal(path, args)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *path;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct chown_args *args;
|
|
|
|
{
|
|
|
|
if (chown(path, args->owner, args->group) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_chown(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE o, g, rest;
|
|
|
|
struct chown_args arg;
|
2002-08-28 12:05:23 +04:00
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-12 13:07:57 +04:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_scan_args(argc, argv, "2*", &o, &g, &rest);
|
|
|
|
if (NIL_P(o)) {
|
|
|
|
arg.owner = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg.owner = NUM2INT(o);
|
|
|
|
}
|
|
|
|
if (NIL_P(g)) {
|
|
|
|
arg.group = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg.group = NUM2INT(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = apply2files(chown_internal, rest, &arg);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_chown(obj, owner, group)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj, owner, group;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(obj, fptr);
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__)
|
1999-12-14 09:50:43 +03:00
|
|
|
if (!fptr->path) return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (chown(fptr->path, NUM2INT(owner), NUM2INT(group)) == -1)
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#else
|
|
|
|
if (fchown(fileno(fptr->f), NUM2INT(owner), NUM2INT(group)) == -1)
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
#if defined(HAVE_LCHOWN) && !defined(__CHECKER__)
|
2001-02-16 10:53:21 +03:00
|
|
|
static void
|
|
|
|
lchown_internal(path, args)
|
|
|
|
const char *path;
|
|
|
|
struct chown_args *args;
|
|
|
|
{
|
|
|
|
if (lchown(path, args->owner, args->group) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchown(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE o, g, rest;
|
|
|
|
struct chown_args arg;
|
2002-08-28 12:05:23 +04:00
|
|
|
long n;
|
2001-02-16 10:53:21 +03:00
|
|
|
|
|
|
|
rb_secure(2);
|
|
|
|
rb_scan_args(argc, argv, "2*", &o, &g, &rest);
|
|
|
|
if (NIL_P(o)) {
|
|
|
|
arg.owner = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg.owner = NUM2INT(o);
|
|
|
|
}
|
|
|
|
if (NIL_P(g)) {
|
|
|
|
arg.group = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg.group = NUM2INT(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = apply2files(lchown_internal, rest, &arg);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
2001-02-16 10:53:21 +03:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchown(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
struct timeval rb_time_timeval();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-08-07 09:05:04 +04:00
|
|
|
#if defined(HAVE_UTIMES) && !defined(__CHECKER__)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
utime_internal(path, tvp)
|
|
|
|
char *path;
|
|
|
|
struct timeval tvp[];
|
|
|
|
{
|
|
|
|
if (utimes(path, tvp) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_utime(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE atime, mtime, rest;
|
|
|
|
struct timeval tvp[2];
|
2002-08-28 12:05:23 +04:00
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
tvp[0] = rb_time_timeval(atime);
|
|
|
|
tvp[1] = rb_time_timeval(mtime);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
n = apply2files(utime_internal, rest, tvp);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if !defined HAVE_UTIME_H && !defined HAVE_SYS_UTIME_H
|
1998-01-16 15:13:05 +03:00
|
|
|
struct utimbuf {
|
|
|
|
long actime;
|
|
|
|
long modtime;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
utime_internal(path, utp)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *path;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct utimbuf *utp;
|
|
|
|
{
|
|
|
|
if (utime(path, utp) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_utime(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE atime, mtime, rest;
|
2002-08-28 12:05:23 +04:00
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct timeval tv;
|
|
|
|
struct utimbuf utbuf;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
tv = rb_time_timeval(atime);
|
1998-01-16 15:13:05 +03:00
|
|
|
utbuf.actime = tv.tv_sec;
|
1999-01-20 07:59:39 +03:00
|
|
|
tv = rb_time_timeval(mtime);
|
1998-01-16 15:13:05 +03:00
|
|
|
utbuf.modtime = tv.tv_sec;
|
|
|
|
|
|
|
|
n = apply2files(utime_internal, rest, &utbuf);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_link(klass, from, to)
|
|
|
|
VALUE klass, from, to;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(from);
|
|
|
|
SafeStringValue(to);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
if (link(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0)
|
|
|
|
rb_sys_fail(RSTRING(from)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_symlink(klass, from, to)
|
|
|
|
VALUE klass, from, to;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-09-21 13:31:00 +04:00
|
|
|
#ifdef HAVE_SYMLINK
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(from);
|
|
|
|
SafeStringValue(to);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
if (symlink(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0)
|
|
|
|
rb_sys_fail(RSTRING(from)->ptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
return INT2FIX(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_notimplement();
|
|
|
|
return Qnil; /* not reached */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_readlink(klass, path)
|
|
|
|
VALUE klass, path;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-09-22 07:37:27 +04:00
|
|
|
#ifdef HAVE_READLINK
|
2001-11-08 09:43:14 +03:00
|
|
|
char *buf;
|
|
|
|
int size = 100;
|
|
|
|
int rv;
|
|
|
|
VALUE v;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(path);
|
2001-11-08 09:43:14 +03:00
|
|
|
buf = xmalloc(size);
|
|
|
|
if ((rv = readlink(RSTRING(path)->ptr, buf, size)) == size) {
|
|
|
|
size *= 2;
|
|
|
|
buf = xrealloc(buf, size);
|
|
|
|
}
|
2002-09-02 12:02:56 +04:00
|
|
|
if (rv < 0) {
|
|
|
|
free(buf);
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
|
|
|
}
|
2001-11-08 09:43:14 +03:00
|
|
|
v = rb_tainted_str_new(buf, rv);
|
|
|
|
free(buf);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-11-08 09:43:14 +03:00
|
|
|
return v;
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
rb_notimplement();
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unlink_internal(path)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *path;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
if (unlink(path) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_unlink(klass, args)
|
|
|
|
VALUE klass, args;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-08-28 12:05:23 +04:00
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-06-01 10:47:32 +04:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
n = apply2files(unlink_internal, args, 0);
|
2002-08-28 12:05:23 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_rename(klass, from, to)
|
|
|
|
VALUE klass, from, to;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(from);
|
|
|
|
SafeStringValue(to);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-02-24 20:51:02 +03:00
|
|
|
if (rename(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0) {
|
|
|
|
#if defined __CYGWIN__
|
|
|
|
extern unsigned long __attribute__((stdcall)) GetLastError();
|
|
|
|
errno = GetLastError(); /* This is a Cygwin bug */
|
|
|
|
#endif
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(from)->ptr);
|
2001-02-24 20:51:02 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_umask(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
int omask = 0;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (argc == 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
omask = umask(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
umask(omask);
|
|
|
|
}
|
|
|
|
else if (argc == 1) {
|
|
|
|
omask = umask(NUM2INT(argv[0]));
|
|
|
|
}
|
|
|
|
else {
|
2001-11-19 08:03:03 +03:00
|
|
|
rb_raise(rb_eArgError, "wrong number of argument");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return INT2FIX(omask);
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#if defined DOSISH
|
|
|
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
|
|
|
#else
|
|
|
|
#define isdirsep(x) ((x) == '/')
|
|
|
|
#endif
|
2001-07-24 19:11:02 +04:00
|
|
|
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
|
|
|
|
# if defined(DJGPP)
|
|
|
|
# define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
|
|
|
|
# else
|
|
|
|
# define CharNext(p) ((p) + 1)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2003-01-06 12:44:15 +03:00
|
|
|
#if defined(DOSISH_DRIVE_LETTER) || defined(__CYGWIN__)
|
|
|
|
static inline int
|
|
|
|
has_drive_letter(buf)
|
|
|
|
char *buf;
|
|
|
|
{
|
|
|
|
if (ISALPHA(buf[0]) && buf[1] == ':') {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
getcwdofdrv(drv, buf, len)
|
|
|
|
int drv;
|
|
|
|
char *buf;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
char drive[4];
|
|
|
|
char oldcwd[MAXPATHLEN+1];
|
|
|
|
|
|
|
|
drive[0] = drv;
|
|
|
|
drive[1] = ':';
|
|
|
|
drive[2] = '\0';
|
|
|
|
|
|
|
|
/* the only way that I know to get the current directory
|
|
|
|
of a particular drive is to change chdir() to that drive,
|
|
|
|
so save the old cwd before chdir()
|
|
|
|
*/
|
|
|
|
getcwd(oldcwd, MAXPATHLEN);
|
|
|
|
if (chdir(drive) == 0) {
|
|
|
|
getcwd(buf, len);
|
|
|
|
chdir(oldcwd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* perhaps the drive is not exist. we return only drive letter */
|
|
|
|
strncpy(buf, drive, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-07-24 19:11:02 +04:00
|
|
|
static char *
|
|
|
|
strrdirsep(path)
|
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
char *last = NULL;
|
|
|
|
while (*path) {
|
|
|
|
if (isdirsep(*path)) {
|
|
|
|
last = path++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
path = CharNext(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-02-04 11:09:14 +03:00
|
|
|
#define BUFCHECK(cond) while (cond) {\
|
|
|
|
long bdiff = p - buf;\
|
|
|
|
buflen *= 2;\
|
|
|
|
rb_str_resize(result, buflen);\
|
|
|
|
buf = RSTRING(result)->ptr;\
|
|
|
|
p = buf + bdiff;\
|
|
|
|
pend = buf + buflen;\
|
|
|
|
}
|
|
|
|
|
2003-01-06 12:44:15 +03:00
|
|
|
#if !defined(TOLOWER)
|
|
|
|
#define TOLOWER(c) (ISUPPER(c) ? tolower(c) : (c))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int is_absolute_path _((const char*));
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_expand_path(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-02-04 11:09:14 +03:00
|
|
|
VALUE fname, dname, result;
|
|
|
|
char *s, *buf, *b, *p, *pend;
|
|
|
|
long buflen = MAXPATHLEN;
|
2000-01-05 07:41:21 +03:00
|
|
|
int tainted;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_scan_args(argc, argv, "11", &fname, &dname);
|
2002-02-04 11:09:14 +03:00
|
|
|
result = rb_str_new(0, buflen + 2);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-07-31 02:41:59 +04:00
|
|
|
s = StringValuePtr(fname);
|
2002-02-04 11:09:14 +03:00
|
|
|
p = buf = RSTRING(result)->ptr;
|
|
|
|
pend = p + buflen;
|
|
|
|
tainted = OBJ_TAINTED(fname);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
if (s[0] == '~') {
|
1999-08-13 09:45:20 +04:00
|
|
|
if (isdirsep(s[1]) || s[1] == '\0') {
|
1998-01-16 15:13:05 +03:00
|
|
|
char *dir = getenv("HOME");
|
|
|
|
|
|
|
|
if (!dir) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `%s'", s);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(strlen(dir) > buflen);
|
1998-01-16 15:13:05 +03:00
|
|
|
strcpy(buf, dir);
|
2003-01-06 12:44:15 +03:00
|
|
|
for (p = buf; p < buf + strlen(dir); p = CharNext(p)) {
|
|
|
|
if (isdirsep(*p)) {
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
}
|
2002-02-04 11:09:14 +03:00
|
|
|
p = buf + strlen(dir);
|
1998-01-16 15:13:05 +03:00
|
|
|
s++;
|
1999-12-07 12:25:55 +03:00
|
|
|
tainted = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
struct passwd *pwPtr;
|
|
|
|
s++;
|
|
|
|
#endif
|
2001-07-27 13:12:12 +04:00
|
|
|
b = s;
|
1999-08-13 09:45:20 +04:00
|
|
|
while (*s && !isdirsep(*s)) {
|
2001-07-27 13:12:12 +04:00
|
|
|
s = CharNext(s);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(p + (s-b) >= pend);
|
2001-07-27 13:12:12 +04:00
|
|
|
memcpy(p, b, s-b);
|
|
|
|
p += s-b;
|
1998-01-16 15:13:05 +03:00
|
|
|
*p = '\0';
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
pwPtr = getpwnam(buf);
|
|
|
|
if (!pwPtr) {
|
|
|
|
endpwent();
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "user %s doesn't exist", buf);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(strlen(pwPtr->pw_dir) > buflen);
|
1998-01-16 15:13:05 +03:00
|
|
|
strcpy(buf, pwPtr->pw_dir);
|
2002-02-04 11:09:14 +03:00
|
|
|
p = buf + strlen(pwPtr->pw_dir);
|
1998-01-16 15:13:05 +03:00
|
|
|
endpwent();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined DOSISH_DRIVE_LETTER || defined __CYGWIN__
|
1999-08-13 09:45:20 +04:00
|
|
|
/* skip drive letter */
|
2003-01-06 12:44:15 +03:00
|
|
|
else if (has_drive_letter(s)) {
|
|
|
|
if (isdirsep(s[2])) {
|
|
|
|
/* specified drive letter, and full path */
|
|
|
|
/* skip drive letter */
|
|
|
|
b = s;
|
|
|
|
while (*s && !isdirsep(*s)) {
|
|
|
|
s = CharNext(s);
|
|
|
|
}
|
|
|
|
BUFCHECK(p + (s-b) >= pend);
|
|
|
|
memcpy(p, b, s-b);
|
|
|
|
p += s-b;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* specified drive, but not full path */
|
|
|
|
int same = 0;
|
|
|
|
if (!NIL_P(dname)) {
|
|
|
|
dname = rb_file_s_expand_path(1, &dname);
|
|
|
|
if (has_drive_letter(RSTRING(dname)->ptr) &&
|
|
|
|
TOLOWER(*RSTRING(dname)->ptr) == TOLOWER(s[0])) {
|
|
|
|
/* ok, same drive */
|
|
|
|
same = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (same) {
|
|
|
|
if (OBJ_TAINTED(dname)) tainted = 1;
|
|
|
|
BUFCHECK (strlen(RSTRING(dname)->ptr) >= buflen);
|
|
|
|
strcpy(buf, RSTRING(dname)->ptr);
|
|
|
|
p = &buf[strlen(buf)];
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
getcwdofdrv(*s, buf, MAXPATHLEN);
|
|
|
|
s += 2;
|
|
|
|
tainted = 1;
|
|
|
|
p = &buf[strlen(buf)];
|
|
|
|
if (strrdirsep(buf) == p - 1 && *s) p--; /* drop `/' */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined DOSISH && ! defined(__CYGWIN__)
|
|
|
|
else if (isdirsep(*s) && !is_absolute_path(s)) {
|
|
|
|
/* specified full path, but not drive letter */
|
|
|
|
/* we need to get the drive letter */
|
|
|
|
tainted = 1;
|
|
|
|
getcwd(buf, MAXPATHLEN);
|
|
|
|
p = &buf[2];
|
2001-07-27 13:12:12 +04:00
|
|
|
b = s;
|
1999-08-13 09:45:20 +04:00
|
|
|
while (*s && !isdirsep(*s)) {
|
2001-07-27 13:12:12 +04:00
|
|
|
s = CharNext(s);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(p + (s-b) >= pend);
|
2001-07-27 13:12:12 +04:00
|
|
|
memcpy(p, b, s-b);
|
|
|
|
p += s-b;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
2003-01-06 12:44:15 +03:00
|
|
|
else if (!is_absolute_path(s)) {
|
2000-10-13 13:01:58 +04:00
|
|
|
if (!NIL_P(dname)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
dname = rb_file_s_expand_path(1, &dname);
|
1999-12-06 12:04:03 +03:00
|
|
|
if (OBJ_TAINTED(dname)) tainted = 1;
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(RSTRING(dname)->len > buflen);
|
2002-02-05 10:56:31 +03:00
|
|
|
memcpy(buf, RSTRING(dname)->ptr, RSTRING(dname)->len);
|
|
|
|
p += RSTRING(dname)->len;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-02-04 11:09:14 +03:00
|
|
|
char *dir = my_getcwd();
|
|
|
|
|
1999-12-06 12:04:03 +03:00
|
|
|
tainted = 1;
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(strlen(dir) > buflen);
|
2002-02-04 11:09:14 +03:00
|
|
|
strcpy(buf, dir);
|
2002-03-20 12:43:15 +03:00
|
|
|
free(dir);
|
2002-02-05 10:56:31 +03:00
|
|
|
p = &buf[strlen(buf)];
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2003-01-06 12:44:15 +03:00
|
|
|
while (p > buf && strrdirsep(buf) == p - 1) p--;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-01-17 11:37:53 +03:00
|
|
|
else {
|
1999-09-16 13:40:33 +04:00
|
|
|
while (*s && isdirsep(*s)) {
|
|
|
|
*p++ = '/';
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(p >= pend);
|
1999-09-16 13:40:33 +04:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (p > buf && *s) p--;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
*p = '/';
|
|
|
|
|
2001-07-31 02:41:59 +04:00
|
|
|
b = s;
|
2001-07-27 13:12:12 +04:00
|
|
|
while (*s) {
|
1998-01-16 15:13:05 +03:00
|
|
|
switch (*s) {
|
|
|
|
case '.':
|
2001-07-31 02:41:59 +04:00
|
|
|
if (b == s++) { /* beginning of path element */
|
|
|
|
switch (*s) {
|
|
|
|
case '\0':
|
|
|
|
b = s;
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
case '.':
|
2001-07-16 08:22:46 +04:00
|
|
|
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
|
1998-01-16 15:13:05 +03:00
|
|
|
/* We must go back to the parent */
|
2001-07-31 02:41:59 +04:00
|
|
|
*p = '\0';
|
|
|
|
if (!(b = strrdirsep(buf))) {
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = b;
|
|
|
|
}
|
|
|
|
b = ++s;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
1999-08-13 09:45:20 +04:00
|
|
|
#if defined DOSISH
|
|
|
|
case '\\':
|
|
|
|
#endif
|
2001-07-31 02:41:59 +04:00
|
|
|
b = ++s;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
default:
|
2001-07-31 02:41:59 +04:00
|
|
|
/* ordinary path element, beginning don't move */
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
1999-08-13 09:45:20 +04:00
|
|
|
#if defined DOSISH
|
|
|
|
case '\\':
|
|
|
|
#endif
|
2001-07-31 02:41:59 +04:00
|
|
|
if (s > b) {
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(p + (s-b+1) >= pend);
|
2001-07-31 02:41:59 +04:00
|
|
|
memcpy(++p, b, s-b);
|
|
|
|
p += s-b;
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
b = ++s;
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
default:
|
2001-07-27 13:12:12 +04:00
|
|
|
s = CharNext(s);
|
2001-07-31 02:41:59 +04:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2001-07-16 08:22:46 +04:00
|
|
|
|
2001-07-31 02:41:59 +04:00
|
|
|
if (s > b) {
|
2002-11-22 12:14:24 +03:00
|
|
|
BUFCHECK(p + (s-b) >= pend);
|
2001-07-31 02:41:59 +04:00
|
|
|
memcpy(++p, b, s-b);
|
|
|
|
p += s-b;
|
|
|
|
}
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined DOSISH_DRIVE_LETTER || defined __CYGWIN__
|
2001-07-31 02:41:59 +04:00
|
|
|
else if (ISALPHA(buf[0]) && (buf[1] == ':') && isdirsep(buf[2])) {
|
|
|
|
/* root directory needs a trailing backslash,
|
|
|
|
otherwise it mean the current directory of the drive */
|
|
|
|
if (p == (buf+2)) p++;
|
|
|
|
}
|
|
|
|
else if (isdirsep(buf[0]) && isdirsep(buf[1])) {
|
|
|
|
if (p == (buf+1)) p++;
|
|
|
|
}
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-04 11:09:14 +03:00
|
|
|
if (tainted) OBJ_TAINT(result);
|
|
|
|
RSTRING(result)->len = p - buf;
|
2002-02-05 10:56:31 +03:00
|
|
|
*p = '\0';
|
2002-02-04 11:09:14 +03:00
|
|
|
return result;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rmext(p, e)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *p, *e;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int l1, l2;
|
|
|
|
|
|
|
|
if (!e) return 0;
|
|
|
|
|
2002-04-10 12:45:26 +04:00
|
|
|
l1 = strlen(p);
|
1998-01-16 15:13:05 +03:00
|
|
|
l2 = strlen(e);
|
1998-01-16 15:19:22 +03:00
|
|
|
if (l2 == 2 && e[1] == '*') {
|
|
|
|
e = strrchr(p, *e);
|
|
|
|
if (!e) return 0;
|
|
|
|
return e - p;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (l1 < l2) return l1;
|
|
|
|
|
|
|
|
if (strcmp(p+l1-l2, e) == 0) {
|
|
|
|
return l1-l2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_s_basename(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
1999-12-01 12:24:48 +03:00
|
|
|
VALUE fname, fext, basename;
|
2002-04-24 08:54:16 +04:00
|
|
|
char *name, *p, *ext = NULL;
|
1998-01-16 15:13:05 +03:00
|
|
|
int f;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
|
2001-05-02 08:22:21 +04:00
|
|
|
ext = StringValuePtr(fext);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
name = StringValuePtr(fname);
|
2001-07-24 19:11:02 +04:00
|
|
|
p = strrdirsep(name);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!p) {
|
2003-01-06 12:44:15 +03:00
|
|
|
#if defined(DOSISH_DRIVE_LETTER)
|
|
|
|
if (has_drive_letter(name)) {
|
|
|
|
name += 2;
|
|
|
|
if (NIL_P(fext)) {
|
|
|
|
f = strlen(name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
f = rmext(name, ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2000-06-12 11:48:31 +04:00
|
|
|
if (NIL_P(fext) || !(f = rmext(name, ext)))
|
2000-05-30 08:24:17 +04:00
|
|
|
return fname;
|
2000-06-12 11:48:31 +04:00
|
|
|
basename = rb_str_new(name, f);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-05-30 08:24:17 +04:00
|
|
|
else {
|
2002-01-23 10:30:43 +03:00
|
|
|
p++; /* skip last / */
|
2000-05-30 08:24:17 +04:00
|
|
|
if (NIL_P(fext) || !(f = rmext(p, ext))) {
|
|
|
|
basename = rb_str_new2(p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
basename = rb_str_new(p, f);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-05-30 08:24:17 +04:00
|
|
|
OBJ_INFECT(basename, fname);
|
1999-12-01 12:24:48 +03:00
|
|
|
return basename;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_dirname(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
char *name, *p;
|
1999-12-01 12:24:48 +03:00
|
|
|
VALUE dirname;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
name = StringValuePtr(fname);
|
2001-07-24 19:11:02 +04:00
|
|
|
p = strrdirsep(name);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!p) {
|
2003-01-06 12:44:15 +03:00
|
|
|
#if defined(DOSISH_DRIVE_LETTER)
|
|
|
|
if (has_drive_letter(name)) {
|
|
|
|
dirname = rb_str_new(name, 2);
|
|
|
|
dirname = rb_str_cat2(dirname, ".");
|
|
|
|
OBJ_INFECT(dirname, fname);
|
|
|
|
return dirname;
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_str_new2(".");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (p == name)
|
1998-01-16 15:13:05 +03:00
|
|
|
p++;
|
2003-01-06 12:44:15 +03:00
|
|
|
#ifdef DOSISH_DRIVE_LETTER
|
|
|
|
if (has_drive_letter(name) && p == &name[2])
|
|
|
|
p++;
|
|
|
|
#endif
|
|
|
|
#ifdef DOSISH
|
|
|
|
if (isdirsep(name[0]) && isdirsep(name[1]) && p == &name[1])
|
|
|
|
p++;
|
|
|
|
#endif
|
1999-12-01 12:24:48 +03:00
|
|
|
dirname = rb_str_new(name, p - name);
|
2002-04-10 12:45:26 +04:00
|
|
|
OBJ_INFECT(dirname, fname);
|
1999-12-01 12:24:48 +03:00
|
|
|
return dirname;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-04-10 12:45:26 +04:00
|
|
|
static VALUE
|
|
|
|
rb_file_s_extname(klass, fname)
|
|
|
|
VALUE klass, fname;
|
|
|
|
{
|
|
|
|
char *name, *p, *e;
|
|
|
|
VALUE extname;
|
|
|
|
|
|
|
|
name = StringValuePtr(fname);
|
|
|
|
p = strrdirsep(name); /* get the last path component */
|
|
|
|
if (!p)
|
|
|
|
p = name;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
|
|
|
e = strrchr(p, '.'); /* get the last dot of the last component */
|
|
|
|
if (!e || e == p) /* no dot, or the only dot is first? */
|
|
|
|
return rb_str_new2("");
|
|
|
|
extname = rb_str_new2(e); /* keep the dot, too! */
|
|
|
|
OBJ_INFECT(extname, fname);
|
|
|
|
return extname;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_split(klass, path)
|
|
|
|
VALUE klass, path;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_assoc_new(rb_file_s_dirname(Qnil, path), rb_file_s_basename(1,&path));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE separator;
|
|
|
|
|
2003-01-06 12:44:15 +03:00
|
|
|
static VALUE rb_file_join _((VALUE ary, VALUE sep));
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
file_inspect_join(ary, arg)
|
|
|
|
VALUE ary;
|
|
|
|
VALUE *arg;
|
|
|
|
{
|
|
|
|
return rb_file_join(arg[0], arg[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_file_join(ary, sep)
|
|
|
|
VALUE ary, sep;
|
|
|
|
{
|
|
|
|
long len, i;
|
|
|
|
int taint = 0;
|
|
|
|
VALUE result, tmp;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
|
|
|
|
if (OBJ_TAINTED(ary)) taint = 1;
|
|
|
|
if (OBJ_TAINTED(sep)) taint = 1;
|
|
|
|
|
|
|
|
len = 1;
|
|
|
|
for (i=0; i<RARRAY(ary)->len; i++) {
|
|
|
|
if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) {
|
|
|
|
len += RSTRING(RARRAY(ary)->ptr[i])->len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!NIL_P(sep) && TYPE(sep) == T_STRING) {
|
|
|
|
len += RSTRING(sep)->len * RARRAY(ary)->len - 1;
|
|
|
|
}
|
|
|
|
result = rb_str_buf_new(len);
|
|
|
|
for (i=0; i<RARRAY(ary)->len; i++) {
|
|
|
|
tmp = RARRAY(ary)->ptr[i];
|
|
|
|
switch (TYPE(tmp)) {
|
|
|
|
case T_STRING:
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
if (rb_inspecting_p(tmp)) {
|
|
|
|
tmp = rb_str_new2("[...]");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE args[2];
|
|
|
|
|
|
|
|
args[0] = tmp;
|
|
|
|
args[1] = sep;
|
|
|
|
tmp = rb_protect_inspect(file_inspect_join, ary, (VALUE)args);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tmp = rb_obj_as_string(tmp);
|
|
|
|
}
|
|
|
|
name = StringValuePtr(result);
|
|
|
|
if (i > 0 && !NIL_P(sep) && strrdirsep(name) != &name[strlen(name) - 1])
|
|
|
|
rb_str_buf_append(result, sep);
|
|
|
|
rb_str_buf_append(result, tmp);
|
|
|
|
if (OBJ_TAINTED(tmp)) taint = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taint) OBJ_TAINT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_join(klass, args)
|
|
|
|
VALUE klass, args;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-01-06 12:44:15 +03:00
|
|
|
return rb_file_join(args, separator);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_file_s_truncate(klass, path, len)
|
|
|
|
VALUE klass, path, len;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-05-12 13:07:57 +04:00
|
|
|
rb_secure(2);
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(path);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_TRUNCATE
|
2002-04-18 12:46:18 +04:00
|
|
|
if (truncate(RSTRING(path)->ptr, NUM2OFFT(len)) < 0)
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
# ifdef HAVE_CHSIZE
|
|
|
|
{
|
|
|
|
int tmpfd;
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
# ifdef _WIN32
|
1998-01-16 15:19:22 +03:00
|
|
|
if ((tmpfd = open(RSTRING(path)->ptr, O_RDWR)) < 0) {
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
# else
|
1998-01-16 15:19:22 +03:00
|
|
|
if ((tmpfd = open(RSTRING(path)->ptr, 0)) < 0) {
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
# endif
|
2002-04-18 12:46:18 +04:00
|
|
|
if (chsize(tmpfd, NUM2OFFT(len)) < 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
close(tmpfd);
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
close(tmpfd);
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
rb_notimplement();
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return INT2FIX(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_truncate(obj, len)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj, len;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
if (!(fptr->mode & FMODE_WRITABLE)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eIOError, "not opened for writing");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#ifdef HAVE_TRUNCATE
|
2002-04-18 12:46:18 +04:00
|
|
|
if (ftruncate(fileno(fptr->f), NUM2OFFT(len)) < 0)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_CHSIZE
|
2002-04-18 12:46:18 +04:00
|
|
|
if (chsize(fileno(fptr->f), NUM2OFFT(len)) < 0)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
# else
|
|
|
|
rb_notimplement();
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
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
|
|
|
|
|
2001-03-26 12:57:16 +04:00
|
|
|
#if 0
|
1999-01-20 07:59:39 +03:00
|
|
|
static int
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_thread_flock(fd, op, fptr)
|
1999-01-20 07:59:39 +03:00
|
|
|
int fd, op;
|
1999-08-13 09:45:20 +04:00
|
|
|
OpenFile *fptr;
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
if (rb_thread_alone() || (op & LOCK_NB)) {
|
|
|
|
return flock(fd, op);
|
|
|
|
}
|
|
|
|
op |= LOCK_NB;
|
|
|
|
while (flock(fd, op) < 0) {
|
|
|
|
switch (errno) {
|
2001-03-26 12:57:16 +04:00
|
|
|
case EAGAIN:
|
|
|
|
case EACCES:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
1999-01-20 07:59:39 +03:00
|
|
|
case EWOULDBLOCK:
|
2001-03-26 12:57:16 +04:00
|
|
|
#endif
|
2000-05-17 08:38:19 +04:00
|
|
|
rb_thread_polling(); /* busy wait */
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_io_check_closed(fptr);
|
2001-03-26 12:57:16 +04:00
|
|
|
continue;
|
1999-01-20 07:59:39 +03:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
#define flock(fd, op) rb_thread_flock(fd, op, fptr)
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_file_flock(obj, operation)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE obj;
|
|
|
|
VALUE operation;
|
|
|
|
{
|
2000-08-07 09:05:04 +04:00
|
|
|
#ifndef __CHECKER__
|
1998-01-16 15:13:05 +03:00
|
|
|
OpenFile *fptr;
|
2000-10-17 22:14:05 +04:00
|
|
|
int ret;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_secure(2);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
|
2000-01-08 08:00:25 +03:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
|
|
|
fflush(GetWriteFile(fptr));
|
|
|
|
}
|
2000-10-17 22:14:05 +04:00
|
|
|
TRAP_BEG;
|
|
|
|
ret = flock(fileno(fptr->f), NUM2INT(operation));
|
|
|
|
TRAP_END;
|
|
|
|
if (ret < 0) {
|
2001-03-26 12:57:16 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EAGAIN:
|
|
|
|
case EACCES:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2001-03-26 12:57:16 +04:00
|
|
|
return Qfalse;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
2000-08-07 09:05:04 +04:00
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return INT2FIX(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
#undef flock
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_check(n, argc, argv)
|
|
|
|
int n, argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
n+=1;
|
2001-11-19 08:03:03 +03:00
|
|
|
if (n != argc) rb_raise(rb_eArgError, "wrong number of arguments(%d for %d)", argc, n);
|
1998-01-16 15:13:05 +03:00
|
|
|
for (i=1; i<n; i++) {
|
1999-01-20 07:59:39 +03:00
|
|
|
switch (TYPE(argv[i])) {
|
|
|
|
case T_STRING:
|
2002-12-19 12:20:20 +03:00
|
|
|
default:
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(argv[i]);
|
1999-01-20 07:59:39 +03:00
|
|
|
break;
|
|
|
|
case T_FILE:
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK(n) test_check((n), argc, argv)
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_f_test(argc, argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
int cmd;
|
|
|
|
|
2001-11-19 08:03:03 +03:00
|
|
|
if (argc == 0) rb_raise(rb_eArgError, "wrong number of arguments");
|
2000-08-24 10:21:43 +04:00
|
|
|
#if 0 /* 1.7 behavior? */
|
|
|
|
if (argc == 1) {
|
|
|
|
return RTEST(argv[0]) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
cmd = NUM2CHR(argv[0]);
|
|
|
|
if (cmd == 0) return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (strchr("bcdefgGkloOprRsSuwWxXz", cmd)) {
|
|
|
|
CHECK(1);
|
|
|
|
switch (cmd) {
|
|
|
|
case 'b':
|
|
|
|
return test_b(0, argv[1]);
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
return test_c(0, argv[1]);
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
return test_d(0, argv[1]);
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
case 'e':
|
|
|
|
return test_e(0, argv[1]);
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
return test_f(0, argv[1]);
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
return test_sgid(0, argv[1]);
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
return test_grpowned(0, argv[1]);
|
|
|
|
|
|
|
|
case 'k':
|
|
|
|
return test_sticky(0, argv[1]);
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
return test_l(0, argv[1]);
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
return test_owned(0, argv[1]);
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
return test_rowned(0, argv[1]);
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
return test_p(0, argv[1]);
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
return test_r(0, argv[1]);
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
return test_R(0, argv[1]);
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
return test_s(0, argv[1]);
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
return test_S(0, argv[1]);
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
return test_suid(0, argv[1]);
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
return test_w(0, argv[1]);
|
|
|
|
|
|
|
|
case 'W':
|
|
|
|
return test_W(0, argv[1]);
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
return test_x(0, argv[1]);
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
return test_X(0, argv[1]);
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
return test_z(0, argv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr("MAC", cmd)) {
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
CHECK(1);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(argv[1], &st) == -1) {
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(RSTRING(argv[1])->ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case 'A':
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_atime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'M':
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_mtime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'C':
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_time_new(st.st_ctime, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr("-=<>", cmd)) {
|
|
|
|
struct stat st1, st2;
|
|
|
|
|
|
|
|
CHECK(2);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (rb_stat(argv[1], &st1) < 0) return Qfalse;
|
|
|
|
if (rb_stat(argv[2], &st2) < 0) return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case '-':
|
|
|
|
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
1999-10-12 08:53:36 +04:00
|
|
|
return Qfalse;
|
2001-07-16 08:22:46 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case '=':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (st1.st_mtime == st2.st_mtime) return Qtrue;
|
1999-10-12 08:53:36 +04:00
|
|
|
return Qfalse;
|
2001-07-16 08:22:46 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case '>':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (st1.st_mtime > st2.st_mtime) return Qtrue;
|
1999-10-12 08:53:36 +04:00
|
|
|
return Qfalse;
|
2001-07-16 08:22:46 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case '<':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (st1.st_mtime < st2.st_mtime) return Qtrue;
|
1999-10-12 08:53:36 +04:00
|
|
|
return Qfalse;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
/* unknown command */
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_raise(rb_eArgError, "unknown command ?%c", cmd);
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
* array.c (ary_alloc), dir.c (dir_s_alloc), eval.c (thgroup_s_alloc),
file.c (rb_stat_s_alloc), hash.c (hash_alloc), io.c (io_alloc),
object.c (rb_module_s_alloc, rb_class_allocate_instance),
re.c (match_alloc, rb_reg_s_alloc), string.c (str_alloc),
time.c (time_s_alloc), ext/digest/digest.c (rb_digest_base_alloc),
ext/tcltklib/tcltklib.c (ip_alloc),
ext/win32ole/win32ole.c (fole_s_allocate, fev_s_allocate)
: add prototype to get rid of VC++ warnings.
* ext/sdbm/init.c (fsdbm_alloc): allocator takes only one argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-21 21:02:01 +03:00
|
|
|
static VALUE rb_stat_s_alloc _((VALUE));
|
2001-05-02 08:22:21 +04:00
|
|
|
static VALUE
|
2001-10-03 11:19:19 +04:00
|
|
|
rb_stat_s_alloc(klass)
|
|
|
|
VALUE klass;
|
2001-05-02 08:22:21 +04:00
|
|
|
{
|
2001-10-03 11:19:19 +04:00
|
|
|
return stat_new_0(klass, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_init(obj, fname)
|
|
|
|
VALUE obj, fname;
|
|
|
|
{
|
|
|
|
struct stat st, *nst;
|
2001-05-02 08:22:21 +04:00
|
|
|
|
2001-12-18 11:47:06 +03:00
|
|
|
SafeStringValue(fname);
|
2001-10-03 11:19:19 +04:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
if (stat(RSTRING(fname)->ptr, &st) == -1) {
|
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
|
|
|
}
|
2002-08-28 13:25:07 +04:00
|
|
|
if (DATA_PTR(obj)) {
|
|
|
|
free(DATA_PTR(obj));
|
|
|
|
DATA_PTR(obj) = NULL;
|
|
|
|
}
|
2001-10-03 11:19:19 +04:00
|
|
|
nst = ALLOC(struct stat);
|
|
|
|
*nst = st;
|
|
|
|
DATA_PTR(obj) = nst;
|
2001-05-02 08:22:21 +04:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2001-10-10 12:21:13 +04:00
|
|
|
static VALUE
|
2002-12-10 09:23:44 +03:00
|
|
|
rb_stat_copy_object(copy, orig)
|
2002-09-03 09:20:14 +04:00
|
|
|
VALUE copy, orig;
|
2001-10-10 12:21:13 +04:00
|
|
|
{
|
2002-04-24 08:54:16 +04:00
|
|
|
struct stat *nst;
|
2001-10-10 12:21:13 +04:00
|
|
|
|
2002-09-03 09:20:14 +04:00
|
|
|
if (copy == orig) return orig;
|
|
|
|
rb_check_frozen(copy);
|
2002-08-27 12:31:08 +04:00
|
|
|
/* need better argument type check */
|
2002-09-03 09:20:14 +04:00
|
|
|
if (!rb_obj_is_instance_of(orig, rb_obj_class(copy))) {
|
2002-08-29 13:08:18 +04:00
|
|
|
rb_raise(rb_eTypeError, "wrong argument class");
|
|
|
|
}
|
2002-09-03 09:20:14 +04:00
|
|
|
if (DATA_PTR(copy)) {
|
|
|
|
free(DATA_PTR(copy));
|
|
|
|
DATA_PTR(copy) = 0;
|
2002-08-27 12:31:08 +04:00
|
|
|
}
|
|
|
|
if (DATA_PTR(orig)) {
|
2001-10-10 12:21:13 +04:00
|
|
|
nst = ALLOC(struct stat);
|
2002-08-27 12:31:08 +04:00
|
|
|
*nst = *(struct stat*)DATA_PTR(orig);
|
2002-09-03 09:20:14 +04:00
|
|
|
DATA_PTR(copy) = nst;
|
2001-10-10 12:21:13 +04:00
|
|
|
}
|
|
|
|
|
2002-09-03 09:20:14 +04:00
|
|
|
return copy;
|
2001-10-10 12:21:13 +04:00
|
|
|
}
|
|
|
|
|
1999-11-25 12:03:08 +03:00
|
|
|
static VALUE
|
|
|
|
rb_stat_ftype(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-07 12:25:55 +03:00
|
|
|
return rb_file_ftype(get_stat(obj));
|
1999-11-25 12:03:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_d(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 12:24:48 +03:00
|
|
|
if (S_ISDIR(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_p(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_IFIFO
|
1999-12-01 12:24:48 +03:00
|
|
|
if (S_ISFIFO(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_l(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISLNK
|
1999-12-01 12:24:48 +03:00
|
|
|
if (S_ISLNK(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_S(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISSOCK
|
1999-12-01 12:24:48 +03:00
|
|
|
if (S_ISSOCK(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_b(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISBLK
|
1999-12-01 12:24:48 +03:00
|
|
|
if (S_ISBLK(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_c(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-02-01 06:12:21 +03:00
|
|
|
if (S_ISCHR(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_owned(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_uid == geteuid()) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_rowned(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_uid == getuid()) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_grpowned(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#ifndef _WIN32
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_gid == getegid()) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_r(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 12:04:03 +03:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 12:03:08 +03:00
|
|
|
|
|
|
|
#ifdef S_IRUSR
|
|
|
|
if (rb_stat_owned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IRUSR ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
#ifdef S_IRGRP
|
|
|
|
if (rb_stat_grpowned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IRGRP ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
#ifdef S_IROTH
|
1999-12-06 12:04:03 +03:00
|
|
|
if (!(st->st_mode & S_IROTH)) return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_R(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 12:04:03 +03:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 12:03:08 +03:00
|
|
|
|
|
|
|
#ifdef S_IRUSR
|
|
|
|
if (rb_stat_rowned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IRUSR ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
#ifdef S_IRGRP
|
1999-12-01 12:24:48 +03:00
|
|
|
if (group_member(get_stat(obj)->st_gid))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IRGRP ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
#ifdef S_IROTH
|
1999-12-06 12:04:03 +03:00
|
|
|
if (!(st->st_mode & S_IROTH)) return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_w(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 12:04:03 +03:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 12:03:08 +03:00
|
|
|
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IWUSR
|
1999-11-25 12:03:08 +03:00
|
|
|
if (rb_stat_owned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IWUSR ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IWGRP
|
1999-11-25 12:03:08 +03:00
|
|
|
if (rb_stat_grpowned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IWGRP ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IWOTH
|
|
|
|
if (!(st->st_mode & S_IWOTH)) return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_W(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 12:04:03 +03:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 12:03:08 +03:00
|
|
|
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IWUSR
|
1999-11-25 12:03:08 +03:00
|
|
|
if (rb_stat_rowned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IWUSR ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IWGRP
|
1999-12-01 12:24:48 +03:00
|
|
|
if (group_member(get_stat(obj)->st_gid))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IWGRP ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IWOTH
|
|
|
|
if (!(st->st_mode & S_IWOTH)) return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_x(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 12:04:03 +03:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 12:03:08 +03:00
|
|
|
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IXUSR
|
1999-11-25 12:03:08 +03:00
|
|
|
if (rb_stat_owned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IXUSR ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IXGRP
|
1999-11-25 12:03:08 +03:00
|
|
|
if (rb_stat_grpowned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IXGRP ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IXOTH
|
|
|
|
if (!(st->st_mode & S_IXOTH)) return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_X(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 12:04:03 +03:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 12:03:08 +03:00
|
|
|
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IXUSR
|
1999-11-25 12:03:08 +03:00
|
|
|
if (rb_stat_rowned(obj))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IXUSR ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IXGRP
|
1999-12-01 12:24:48 +03:00
|
|
|
if (group_member(get_stat(obj)->st_gid))
|
1999-12-06 12:04:03 +03:00
|
|
|
return st->st_mode & S_IXGRP ? Qtrue : Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
1999-12-06 12:04:03 +03:00
|
|
|
#ifdef S_IXOTH
|
|
|
|
if (!(st->st_mode & S_IXOTH)) return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_f(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 12:24:48 +03:00
|
|
|
if (S_ISREG(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_z(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_size == 0) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_s(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2002-08-28 12:05:23 +04:00
|
|
|
off_t size = get_stat(obj)->st_size;
|
1999-11-25 12:03:08 +03:00
|
|
|
|
1999-12-01 12:24:48 +03:00
|
|
|
if (size == 0) return Qnil;
|
2002-08-28 12:05:23 +04:00
|
|
|
return OFFT2NUM(size);
|
1999-11-25 12:03:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_suid(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISUID
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_mode & S_ISUID) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_sgid(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-05-13 20:13:31 +04:00
|
|
|
#ifdef S_ISGID
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_mode & S_ISGID) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_sticky(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISVTX
|
1999-12-01 12:24:48 +03:00
|
|
|
if (get_stat(obj)->st_mode & S_ISVTX) return Qtrue;
|
1999-11-25 12:03:08 +03:00
|
|
|
#endif
|
2000-06-12 11:48:31 +04:00
|
|
|
return Qfalse;
|
1999-11-25 12:03:08 +03:00
|
|
|
}
|
|
|
|
|
2000-09-25 13:15:08 +04:00
|
|
|
static VALUE rb_mFConst;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_file_const(name, value)
|
|
|
|
const char *name;
|
|
|
|
VALUE value;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-09-25 13:15:08 +04:00
|
|
|
rb_define_const(rb_mFConst, name, value);
|
2002-01-23 10:30:43 +03:00
|
|
|
rb_define_const(rb_cIO, name, value);
|
|
|
|
rb_define_const(rb_cFile, name, value);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
static int
|
|
|
|
is_absolute_path(path)
|
|
|
|
const char *path;
|
|
|
|
{
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined DOSISH_DRIVE_LETTER || defined __CYGWIN__
|
2001-07-24 19:11:02 +04:00
|
|
|
if (ISALPHA(path[0]) && path[1] == ':' && isdirsep(path[2])) return 1;
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#endif
|
|
|
|
#if defined DOSISH || defined __CYGWIN__
|
2001-07-24 19:11:02 +04:00
|
|
|
if (isdirsep(path[0]) && isdirsep(path[1])) return 1;
|
2002-08-20 14:42:57 +04:00
|
|
|
#endif
|
|
|
|
#ifndef DOSISH
|
2000-01-05 07:41:21 +03:00
|
|
|
if (path[0] == '/') return 1;
|
2001-07-24 19:11:02 +04:00
|
|
|
#endif
|
2000-01-05 07:41:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:53:31 +04:00
|
|
|
#ifndef DOSISH
|
2000-01-05 07:41:21 +03:00
|
|
|
static int
|
|
|
|
path_check_1(path)
|
2001-11-08 09:43:14 +03:00
|
|
|
VALUE path;
|
2000-01-05 07:41:21 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
2001-11-08 09:43:14 +03:00
|
|
|
char *p0 = RSTRING(path)->ptr;
|
2001-11-08 12:21:59 +03:00
|
|
|
char *p = 0, *s;
|
2001-11-08 09:43:14 +03:00
|
|
|
|
|
|
|
if (!is_absolute_path(p0)) {
|
|
|
|
char *buf = my_getcwd();
|
|
|
|
VALUE newpath;
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2001-11-08 09:43:14 +03:00
|
|
|
newpath = rb_str_new2(buf);
|
|
|
|
free(buf);
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2001-11-08 09:43:14 +03:00
|
|
|
rb_str_cat2(newpath, "/");
|
|
|
|
rb_str_cat2(newpath, p0);
|
|
|
|
return path_check_1(newpath);
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
for (;;) {
|
2002-02-19 09:43:58 +03:00
|
|
|
#ifndef S_IWOTH
|
|
|
|
# define S_IWOTH 002
|
|
|
|
#endif
|
2002-02-19 11:13:26 +03:00
|
|
|
if (stat(p0, &st) == 0 && S_ISDIR(st.st_mode) && (st.st_mode & S_IWOTH)
|
2002-02-19 09:43:58 +03:00
|
|
|
#ifdef S_ISVTX
|
2002-02-19 11:13:26 +03:00
|
|
|
&& (!p || !(st.st_mode & S_ISVTX))
|
2002-02-19 09:43:58 +03:00
|
|
|
#endif
|
2002-02-19 11:13:26 +03:00
|
|
|
) {
|
2002-09-06 12:59:41 +04:00
|
|
|
rb_warn("Insecure world writable dir %s, mode 0%o", p0, st.st_mode);
|
2001-07-24 19:11:02 +04:00
|
|
|
if (p) *p = '/';
|
2000-01-05 07:41:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2001-11-08 09:43:14 +03:00
|
|
|
s = strrdirsep(p0);
|
2000-01-05 07:41:21 +03:00
|
|
|
if (p) *p = '/';
|
2001-11-08 09:43:14 +03:00
|
|
|
if (!s || s == p0) return 1;
|
2000-01-05 07:41:21 +03:00
|
|
|
p = s;
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
}
|
2002-09-06 00:53:31 +04:00
|
|
|
#endif
|
2000-01-05 07:41:21 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
rb_path_check(path)
|
|
|
|
char *path;
|
|
|
|
{
|
2002-09-06 00:53:31 +04:00
|
|
|
#ifndef DOSISH
|
2001-11-08 09:43:14 +03:00
|
|
|
char *p0, *p, *pend;
|
2000-01-05 07:41:21 +03:00
|
|
|
const char sep = PATH_SEP_CHAR;
|
|
|
|
|
|
|
|
if (!path) return 1;
|
|
|
|
|
2001-11-08 09:43:14 +03:00
|
|
|
pend = path + strlen(path);
|
|
|
|
p0 = path;
|
|
|
|
p = strchr(path, sep);
|
|
|
|
if (!p) p = pend;
|
2001-07-16 08:22:46 +04:00
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
for (;;) {
|
2001-11-08 09:43:14 +03:00
|
|
|
if (!path_check_1(rb_str_new(p0, p - p0))) {
|
|
|
|
return 0; /* not safe */
|
|
|
|
}
|
|
|
|
p0 = p + 1;
|
2001-11-08 12:21:59 +03:00
|
|
|
if (p0 > pend) break;
|
2001-11-08 09:43:14 +03:00
|
|
|
p = strchr(p0, sep);
|
|
|
|
if (!p) p = pend;
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
2002-09-06 00:53:31 +04:00
|
|
|
#endif
|
2000-01-05 07:41:21 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-02-17 10:11:22 +03:00
|
|
|
#if defined(__MACOS__) || defined(riscos)
|
2000-01-05 07:41:21 +03:00
|
|
|
static int
|
|
|
|
is_macos_native_path(path)
|
|
|
|
const char *path;
|
|
|
|
{
|
|
|
|
if (strchr(path, ':')) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
static int
|
2001-06-19 08:35:17 +04:00
|
|
|
file_load_ok(file)
|
|
|
|
char *file;
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
2001-07-16 08:22:46 +04:00
|
|
|
if (!file) return 0;
|
2001-06-19 08:35:17 +04:00
|
|
|
f = fopen(file, "r");
|
|
|
|
if (f == NULL) return 0;
|
|
|
|
fclose(f);
|
2001-07-14 19:17:19 +04:00
|
|
|
return 1;
|
2001-06-19 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern VALUE rb_load_path;
|
|
|
|
|
|
|
|
int
|
2001-09-03 09:37:42 +04:00
|
|
|
rb_find_file_ext(filep, ext)
|
2001-07-14 19:17:19 +04:00
|
|
|
VALUE *filep;
|
2001-09-08 18:17:53 +04:00
|
|
|
const char * const *ext;
|
2001-06-19 08:35:17 +04:00
|
|
|
{
|
2002-04-24 08:54:16 +04:00
|
|
|
char *path, *found;
|
2001-07-14 19:17:19 +04:00
|
|
|
char *f = RSTRING(*filep)->ptr;
|
2001-06-19 08:35:17 +04:00
|
|
|
VALUE fname;
|
2002-08-21 19:47:54 +04:00
|
|
|
long i, j;
|
2001-06-19 08:35:17 +04:00
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
if (f[0] == '~') {
|
2001-11-13 11:19:52 +03:00
|
|
|
fname = rb_file_s_expand_path(1, filep);
|
2001-07-14 19:17:19 +04:00
|
|
|
if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) {
|
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
|
|
|
}
|
2001-07-27 13:12:12 +04:00
|
|
|
f = StringValuePtr(fname);
|
2001-07-26 07:54:48 +04:00
|
|
|
*filep = fname;
|
2001-06-19 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
if (is_absolute_path(f)) {
|
2001-06-19 08:35:17 +04:00
|
|
|
for (i=0; ext[i]; i++) {
|
2001-07-14 19:17:19 +04:00
|
|
|
fname = rb_str_dup(*filep);
|
|
|
|
rb_str_cat2(fname, ext[i]);
|
|
|
|
if (file_load_ok(RSTRING(fname)->ptr)) {
|
|
|
|
*filep = fname;
|
|
|
|
return i+1;
|
|
|
|
}
|
2001-06-19 08:35:17 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rb_load_path) return 0;
|
|
|
|
|
|
|
|
Check_Type(rb_load_path, T_ARRAY);
|
|
|
|
for (i=0;i<RARRAY(rb_load_path)->len;i++) {
|
|
|
|
VALUE str = RARRAY(rb_load_path)->ptr[i];
|
|
|
|
|
|
|
|
SafeStringValue(str);
|
2002-11-22 12:14:24 +03:00
|
|
|
if (RSTRING(str)->len == 0) continue;
|
2001-06-19 08:35:17 +04:00
|
|
|
path = RSTRING(str)->ptr;
|
|
|
|
for (j=0; ext[j]; j++) {
|
2001-07-14 19:17:19 +04:00
|
|
|
fname = rb_str_dup(*filep);
|
|
|
|
rb_str_cat2(fname, ext[j]);
|
|
|
|
found = dln_find_file(RSTRING(fname)->ptr, path);
|
|
|
|
if (found && file_load_ok(found)) {
|
|
|
|
*filep = fname;
|
|
|
|
return j+1;
|
|
|
|
}
|
2001-06-19 08:35:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
VALUE
|
|
|
|
rb_find_file(path)
|
|
|
|
VALUE path;
|
2000-01-05 07:41:21 +03:00
|
|
|
{
|
2002-04-24 08:54:16 +04:00
|
|
|
VALUE tmp;
|
2001-07-14 19:17:19 +04:00
|
|
|
char *f = RSTRING(path)->ptr;
|
|
|
|
char *lpath;
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
if (f[0] == '~') {
|
2001-07-26 07:54:48 +04:00
|
|
|
path = rb_file_s_expand_path(1, &path);
|
|
|
|
if (rb_safe_level() >= 2 && OBJ_TAINTED(path)) {
|
2001-07-14 19:17:19 +04:00
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
2001-06-19 08:35:17 +04:00
|
|
|
}
|
2001-07-27 13:12:12 +04:00
|
|
|
f = StringValuePtr(path);
|
2001-06-19 08:35:17 +04:00
|
|
|
}
|
|
|
|
|
2000-02-17 10:11:22 +03:00
|
|
|
#if defined(__MACOS__) || defined(riscos)
|
2001-07-14 19:17:19 +04:00
|
|
|
if (is_macos_native_path(f)) {
|
|
|
|
if (rb_safe_level() >= 2 && !rb_path_check(f)) {
|
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
2001-07-14 19:17:19 +04:00
|
|
|
if (file_load_ok(f)) return path;
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
if (is_absolute_path(f)) {
|
|
|
|
if (rb_safe_level() >= 2 && !rb_path_check(f)) {
|
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
2001-07-14 19:17:19 +04:00
|
|
|
if (file_load_ok(f)) return path;
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
|
2002-05-01 13:41:50 +04:00
|
|
|
if (rb_safe_level() >= 4) {
|
|
|
|
rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f);
|
|
|
|
}
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
if (rb_load_path) {
|
2002-08-21 19:47:54 +04:00
|
|
|
long i;
|
2000-01-05 07:41:21 +03:00
|
|
|
|
|
|
|
Check_Type(rb_load_path, T_ARRAY);
|
2001-07-14 19:17:19 +04:00
|
|
|
tmp = rb_ary_new();
|
2000-01-05 07:41:21 +03:00
|
|
|
for (i=0;i<RARRAY(rb_load_path)->len;i++) {
|
|
|
|
VALUE str = RARRAY(rb_load_path)->ptr[i];
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(str);
|
2000-01-05 07:41:21 +03:00
|
|
|
if (RSTRING(str)->len > 0) {
|
2001-07-14 19:17:19 +04:00
|
|
|
rb_ary_push(tmp, str);
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
}
|
2001-07-14 19:17:19 +04:00
|
|
|
tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP));
|
2002-08-27 12:31:08 +04:00
|
|
|
if (RSTRING(tmp)->len == 0) {
|
|
|
|
lpath = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lpath = RSTRING(tmp)->ptr;
|
|
|
|
if (rb_safe_level() >= 2 && !rb_path_check(lpath)) {
|
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe path %s", lpath);
|
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-07-14 19:17:19 +04:00
|
|
|
lpath = 0;
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
|
2002-08-27 12:31:08 +04:00
|
|
|
if (!lpath) {
|
|
|
|
return 0; /* no path, no load */
|
|
|
|
}
|
2001-07-14 19:17:19 +04:00
|
|
|
f = dln_find_file(f, lpath);
|
|
|
|
if (file_load_ok(f)) {
|
|
|
|
return rb_str_new2(f);
|
|
|
|
}
|
2001-07-24 13:07:33 +04:00
|
|
|
return 0;
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
|
2000-09-18 12:47:10 +04:00
|
|
|
static void
|
|
|
|
define_filetest_function(name, func, argc)
|
|
|
|
const char *name;
|
|
|
|
VALUE (*func)();
|
|
|
|
int argc;
|
|
|
|
{
|
|
|
|
rb_define_module_function(rb_mFileTest, name, func, argc);
|
|
|
|
rb_define_singleton_method(rb_cFile, name, func, argc);
|
|
|
|
}
|
|
|
|
|
2001-01-10 10:52:46 +03:00
|
|
|
void
|
1999-08-13 09:45:20 +04:00
|
|
|
Init_File()
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_mFileTest = rb_define_module("FileTest");
|
|
|
|
rb_cFile = rb_define_class("File", rb_cIO);
|
2000-09-18 12:47:10 +04:00
|
|
|
|
|
|
|
define_filetest_function("directory?", test_d, 1);
|
|
|
|
define_filetest_function("exist?", test_e, 1);
|
|
|
|
define_filetest_function("exists?", test_e, 1); /* temporary */
|
|
|
|
define_filetest_function("readable?", test_r, 1);
|
|
|
|
define_filetest_function("readable_real?", test_R, 1);
|
|
|
|
define_filetest_function("writable?", test_w, 1);
|
|
|
|
define_filetest_function("writable_real?", test_W, 1);
|
|
|
|
define_filetest_function("executable?", test_x, 1);
|
|
|
|
define_filetest_function("executable_real?", test_X, 1);
|
|
|
|
define_filetest_function("file?", test_f, 1);
|
|
|
|
define_filetest_function("zero?", test_z, 1);
|
|
|
|
define_filetest_function("size?", test_s, 1);
|
2000-10-10 11:03:36 +04:00
|
|
|
define_filetest_function("size", rb_file_s_size, 1);
|
2000-09-18 12:47:10 +04:00
|
|
|
define_filetest_function("owned?", test_owned, 1);
|
|
|
|
define_filetest_function("grpowned?", test_grpowned, 1);
|
|
|
|
|
|
|
|
define_filetest_function("pipe?", test_p, 1);
|
|
|
|
define_filetest_function("symlink?", test_l, 1);
|
|
|
|
define_filetest_function("socket?", test_S, 1);
|
|
|
|
|
|
|
|
define_filetest_function("blockdev?", test_b, 1);
|
|
|
|
define_filetest_function("chardev?", test_c, 1);
|
|
|
|
|
|
|
|
define_filetest_function("setuid?", test_suid, 1);
|
|
|
|
define_filetest_function("setgid?", test_sgid, 1);
|
|
|
|
define_filetest_function("sticky?", test_sticky, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
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, "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);
|
2001-02-16 10:53:21 +03:00
|
|
|
rb_define_singleton_method(rb_cFile, "lchmod", rb_file_s_lchmod, -1);
|
|
|
|
rb_define_singleton_method(rb_cFile, "lchown", rb_file_s_lchown, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
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);
|
2002-04-10 12:45:26 +04:00
|
|
|
rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2001-10-29 08:07:26 +03:00
|
|
|
separator = rb_obj_freeze(rb_str_new2("/"));
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_const(rb_cFile, "Separator", separator);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_const(rb_cFile, "SEPARATOR", separator);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_singleton_method(rb_cFile, "split", rb_file_s_split, 1);
|
|
|
|
rb_define_singleton_method(rb_cFile, "join", rb_file_s_join, -2);
|
|
|
|
|
2000-06-07 19:49:37 +04:00
|
|
|
#if defined DOSISH && !defined __CYGWIN__
|
2001-10-29 08:07:26 +03:00
|
|
|
rb_define_const(rb_cFile, "ALT_SEPARATOR", rb_obj_freeze(rb_str_new2("\\")));
|
1999-08-13 09:45:20 +04:00
|
|
|
#else
|
|
|
|
rb_define_const(rb_cFile, "ALT_SEPARATOR", Qnil);
|
|
|
|
#endif
|
2001-10-29 08:07:26 +03:00
|
|
|
rb_define_const(rb_cFile, "PATH_SEPARATOR", rb_obj_freeze(rb_str_new2(PATH_SEP)));
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2000-09-25 13:15:08 +04:00
|
|
|
rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
|
|
|
|
rb_include_module(rb_cFile, rb_mFConst);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
|
|
|
|
rb_file_const("LOCK_EX", INT2FIX(LOCK_EX));
|
|
|
|
rb_file_const("LOCK_UN", INT2FIX(LOCK_UN));
|
|
|
|
rb_file_const("LOCK_NB", INT2FIX(LOCK_NB));
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cFile, "path", rb_file_path, 0);
|
|
|
|
rb_define_global_function("test", rb_f_test, -1);
|
|
|
|
|
1999-12-01 12:24:48 +03:00
|
|
|
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_define_alloc_func(rb_cStat, rb_stat_s_alloc);
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_define_method(rb_cStat, "initialize", rb_stat_init, 1);
|
2002-12-10 09:23:44 +03:00
|
|
|
rb_define_method(rb_cStat, "copy_object", rb_stat_copy_object, 1);
|
1999-12-01 12:24:48 +03:00
|
|
|
|
|
|
|
rb_include_module(rb_cStat, rb_mComparable);
|
|
|
|
|
|
|
|
rb_define_method(rb_cStat, "<=>", rb_stat_cmp, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cStat, "dev", rb_stat_dev, 0);
|
|
|
|
rb_define_method(rb_cStat, "ino", rb_stat_ino, 0);
|
|
|
|
rb_define_method(rb_cStat, "mode", rb_stat_mode, 0);
|
|
|
|
rb_define_method(rb_cStat, "nlink", rb_stat_nlink, 0);
|
|
|
|
rb_define_method(rb_cStat, "uid", rb_stat_uid, 0);
|
|
|
|
rb_define_method(rb_cStat, "gid", rb_stat_gid, 0);
|
|
|
|
rb_define_method(rb_cStat, "rdev", rb_stat_rdev, 0);
|
2002-01-29 10:16:09 +03:00
|
|
|
rb_define_method(rb_cStat, "rdev_major", rb_stat_rdev_major, 0);
|
|
|
|
rb_define_method(rb_cStat, "rdev_minor", rb_stat_rdev_minor, 0);
|
1999-12-01 12:24:48 +03:00
|
|
|
rb_define_method(rb_cStat, "size", rb_stat_size, 0);
|
|
|
|
rb_define_method(rb_cStat, "blksize", rb_stat_blksize, 0);
|
|
|
|
rb_define_method(rb_cStat, "blocks", rb_stat_blocks, 0);
|
|
|
|
rb_define_method(rb_cStat, "atime", rb_stat_atime, 0);
|
|
|
|
rb_define_method(rb_cStat, "mtime", rb_stat_mtime, 0);
|
|
|
|
rb_define_method(rb_cStat, "ctime", rb_stat_ctime, 0);
|
|
|
|
|
2000-06-19 12:38:11 +04:00
|
|
|
rb_define_method(rb_cStat, "inspect", rb_stat_inspect, 0);
|
|
|
|
|
1999-12-01 12:24:48 +03:00
|
|
|
rb_define_method(rb_cStat, "ftype", rb_stat_ftype, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cStat, "directory?", rb_stat_d, 0);
|
|
|
|
rb_define_method(rb_cStat, "readable?", rb_stat_r, 0);
|
|
|
|
rb_define_method(rb_cStat, "readable_real?", rb_stat_R, 0);
|
|
|
|
rb_define_method(rb_cStat, "writable?", rb_stat_w, 0);
|
|
|
|
rb_define_method(rb_cStat, "writable_real?", rb_stat_W, 0);
|
|
|
|
rb_define_method(rb_cStat, "executable?", rb_stat_x, 0);
|
|
|
|
rb_define_method(rb_cStat, "executable_real?", rb_stat_X, 0);
|
|
|
|
rb_define_method(rb_cStat, "file?", rb_stat_f, 0);
|
|
|
|
rb_define_method(rb_cStat, "zero?", rb_stat_z, 0);
|
|
|
|
rb_define_method(rb_cStat, "size?", rb_stat_s, 0);
|
|
|
|
rb_define_method(rb_cStat, "owned?", rb_stat_owned, 0);
|
|
|
|
rb_define_method(rb_cStat, "grpowned?", rb_stat_grpowned, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cStat, "pipe?", rb_stat_p, 0);
|
|
|
|
rb_define_method(rb_cStat, "symlink?", rb_stat_l, 0);
|
|
|
|
rb_define_method(rb_cStat, "socket?", rb_stat_S, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cStat, "blockdev?", rb_stat_b, 0);
|
|
|
|
rb_define_method(rb_cStat, "chardev?", rb_stat_c, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cStat, "setuid?", rb_stat_suid, 0);
|
|
|
|
rb_define_method(rb_cStat, "setgid?", rb_stat_sgid, 0);
|
|
|
|
rb_define_method(rb_cStat, "sticky?", rb_stat_sticky, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|