2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
file.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Mon Nov 15 12:24:34 JST 1993
|
|
|
|
|
2001-01-29 00:10:42 -05:00
|
|
|
Copyright (C) 1993-2001 Yukihiro Matsumoto
|
2000-05-01 05:42:38 -04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 00:53:16 -04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifdef NT
|
|
|
|
#include "missing/file.h"
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#include "ruby.h"
|
1999-01-19 23:59:39 -05:00
|
|
|
#include "rubyio.h"
|
|
|
|
#include "rubysig.h"
|
2000-01-04 23:41:21 -05:00
|
|
|
#include "dln.h"
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2000-05-12 05:07:57 -04:00
|
|
|
#ifdef HAVE_SYS_FILE_H
|
|
|
|
# include <sys/file.h>
|
|
|
|
#else
|
|
|
|
int flock _((int, int));
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
|
|
|
#else
|
|
|
|
# define MAXPATHLEN 1024
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#include <time.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#else
|
|
|
|
#ifndef NT
|
|
|
|
struct timeval {
|
|
|
|
long tv_sec; /* seconds */
|
|
|
|
long tv_usec; /* and microseconds */
|
|
|
|
};
|
|
|
|
#endif /* NT */
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
VALUE rb_time_new _((time_t, time_t));
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_UTIME_H
|
|
|
|
#include <utime.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
#ifndef HAVE_STRING_H
|
1999-08-13 01:45:20 -04:00
|
|
|
char *strrchr _((const char*,const char));
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#include <sys/types.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2000-09-21 05:31:00 -04:00
|
|
|
#ifndef HAVE_LSTAT
|
2001-03-20 22:51:23 -05:00
|
|
|
#define lstat(path,st) stat(path,st)
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
2001-07-16 00:22:46 -04:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_cFile;
|
|
|
|
VALUE rb_mFileTest;
|
1999-12-01 04:24:48 -05:00
|
|
|
static VALUE rb_cStat;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static int
|
1998-01-16 07:19:22 -05:00
|
|
|
apply2files(func, vargs, arg)
|
1998-01-16 07:13:05 -05:00
|
|
|
int (*func)();
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE vargs;
|
1998-01-16 07:13:05 -05:00
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
VALUE path;
|
1998-01-16 07:19:22 -05:00
|
|
|
struct RArray *args = RARRAY(vargs);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
for (i=0; i<args->len; i++) {
|
|
|
|
path = args->ptr[i];
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(path);
|
1998-01-16 07:13:05 -05:00
|
|
|
if ((*func)(RSTRING(path)->ptr, arg) < 0)
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return args->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_path(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
1999-12-14 01:50:43 -05:00
|
|
|
if (!fptr->path) return Qnil;
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2(fptr->path);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-03-07 03:37:59 -05:00
|
|
|
#ifdef NT
|
1998-01-16 07:13:05 -05:00
|
|
|
#include "missing/file.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
stat_new_0(klass, st)
|
|
|
|
VALUE klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
struct stat *st;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
struct stat *nst;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (!st) rb_bug("stat_new() called with bad value");
|
1999-12-01 04:24:48 -05:00
|
|
|
|
|
|
|
nst = ALLOC(struct stat);
|
|
|
|
*nst = *st;
|
2001-05-02 00: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 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct stat*
|
|
|
|
get_stat(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
struct stat* st;
|
|
|
|
Data_Get_Struct(self, struct stat, st);
|
|
|
|
if (!st) rb_bug("collapsed File::Stat");
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_cmp(self, other)
|
|
|
|
VALUE self, other;
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_dev(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return INT2NUM(get_stat(self)->st_dev);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_ino(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_ino);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_mode(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return UINT2NUM(get_stat(self)->st_mode);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_nlink(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return UINT2NUM(get_stat(self)->st_nlink);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_uid(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return UINT2NUM(get_stat(self)->st_uid);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_gid(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return UINT2NUM(get_stat(self)->st_gid);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_rdev(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_ST_RDEV
|
2001-05-02 00:22:21 -04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_rdev);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-12-01 04:24:48 -05:00
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_size(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
return LONG2NUM(get_stat(self)->st_size);
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_blksize(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
2001-05-02 00:22:21 -04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_blksize);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-12-01 04:24:48 -05:00
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-12-01 04:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_blocks(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_ST_BLOCKS
|
2001-05-02 00:22:21 -04:00
|
|
|
return ULONG2NUM(get_stat(self)->st_blocks);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-12-01 04:24:48 -05:00
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-12-01 04:24:48 -05: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-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2000-06-19 04:38:11 -04:00
|
|
|
static VALUE
|
|
|
|
rb_stat_inspect(self)
|
|
|
|
VALUE self;
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
int i;
|
|
|
|
struct {
|
|
|
|
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 05: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 04:38:11 -04:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) {
|
|
|
|
VALUE str2;
|
|
|
|
|
|
|
|
if (i > 0) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, ", ");
|
2000-06-19 04:38:11 -04:00
|
|
|
}
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, member[i].name);
|
|
|
|
rb_str_buf_cat2(str, "=");
|
2000-06-19 04:38:11 -04:00
|
|
|
str2 = rb_inspect((*member[i].func)(self));
|
|
|
|
rb_str_append(str, str2);
|
|
|
|
}
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, ">");
|
2000-06-19 04:38:11 -04:00
|
|
|
OBJ_INFECT(str, self);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static int
|
|
|
|
rb_stat(file, st)
|
|
|
|
VALUE file;
|
|
|
|
struct stat *st;
|
|
|
|
{
|
|
|
|
if (TYPE(file) == T_FILE) {
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1999-01-19 23:59:39 -05:00
|
|
|
GetOpenFile(file, fptr);
|
|
|
|
return fstat(fileno(fptr->f), st);
|
|
|
|
}
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(file);
|
1999-08-13 01:45:20 -04:00
|
|
|
#if defined DJGPP
|
|
|
|
if (RSTRING(file)->len == 0) return -1;
|
|
|
|
#endif
|
2001-03-20 22:51:23 -05:00
|
|
|
return stat(RSTRING(file)->ptr, st);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_stat(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
2001-03-20 22:51:23 -05:00
|
|
|
if (stat(RSTRING(fname)->ptr, &st) == -1) {
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_io_stat(obj)
|
1998-01-16 07:13:05 -05: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 00:22:21 -04:00
|
|
|
rb_file_s_lstat(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-09-21 05:31:00 -04:00
|
|
|
#ifdef HAVE_LSTAT
|
1998-01-16 07:13:05 -05:00
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1998-01-16 07:19:22 -05:00
|
|
|
if (lstat(RSTRING(fname)->ptr, &st) == -1) {
|
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
#else
|
2001-05-02 00:22:21 -04:00
|
|
|
return rb_file_s_stat(klass, fname);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_lstat(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-09-21 05:31:00 -04:00
|
|
|
#ifdef HAVE_LSTAT
|
1998-01-16 07:13:05 -05:00
|
|
|
OpenFile *fptr;
|
|
|
|
struct stat st;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
GetOpenFile(obj, fptr);
|
1999-12-14 01:50:43 -05:00
|
|
|
if (!fptr->path) return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (lstat(fptr->path, &st) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
return stat_new(&st);
|
|
|
|
#else
|
2000-09-21 05:31:00 -04:00
|
|
|
return rb_io_stat(obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
group_member(gid)
|
|
|
|
GETGROUPS_T gid;
|
|
|
|
{
|
2000-03-07 03:37:59 -05:00
|
|
|
#if !defined(NT)
|
2001-08-23 02:02:15 -04:00
|
|
|
if (getgid() == gid)
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
# ifdef HAVE_GETGROUPS
|
|
|
|
# ifndef NGROUPS
|
|
|
|
# define NGROUPS 32
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
GETGROUPS_T gary[NGROUPS];
|
|
|
|
int anum;
|
|
|
|
|
|
|
|
anum = getgroups(NGROUPS, gary);
|
|
|
|
while (--anum >= 0)
|
|
|
|
if (gary[anum] == gid)
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef S_IXUGO
|
|
|
|
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
eaccess(path, mode)
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *path;
|
1998-01-16 07:13:05 -05:00
|
|
|
int mode;
|
|
|
|
{
|
2000-05-13 12:13:31 -04:00
|
|
|
#ifdef S_IXGRP
|
2001-08-23 02:02:15 -04:00
|
|
|
struct stat st;
|
|
|
|
int euid;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-08-23 02:02:15 -04:00
|
|
|
if (stat(path, &st) < 0) return -1;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-08-23 02:02:15 -04:00
|
|
|
euid = geteuid();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-08-23 02: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 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-08-23 02: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 07:13:05 -05:00
|
|
|
|
2001-08-23 02:02:15 -04:00
|
|
|
if ((st.st_mode & mode) == mode) return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-08-23 02:02:15 -04:00
|
|
|
return -1;
|
2001-05-30 05:12:34 -04:00
|
|
|
#else
|
2001-08-23 02:02:15 -04:00
|
|
|
return access(path, mode);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_d(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISDIR(st.st_mode)) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_p(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifdef S_IFIFO
|
|
|
|
# ifndef S_ISFIFO
|
|
|
|
# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
|
|
|
|
# endif
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISFIFO(st.st_mode)) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_l(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
# ifdef _S_ISLNK
|
|
|
|
# define S_ISLNK(m) _S_ISLNK(m)
|
|
|
|
# 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 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (lstat(RSTRING(fname)->ptr, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISLNK(st.st_mode)) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-12-14 01:50:43 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_S(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifndef S_ISSOCK
|
|
|
|
# ifdef _S_ISSOCK
|
|
|
|
# define S_ISSOCK(m) _S_ISSOCK(m)
|
|
|
|
# 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-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISSOCK(st.st_mode)) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_b(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05: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-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISBLK(st.st_mode)) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_c(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifndef S_ISCHR
|
|
|
|
# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
2000-01-31 22:12:21 -05:00
|
|
|
if (S_ISCHR(st.st_mode)) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_e(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_r(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (eaccess(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_R(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (access(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_w(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (eaccess(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_W(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (access(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_x(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (eaccess(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_X(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (access(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef S_ISREG
|
|
|
|
# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_f(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (S_ISREG(st.st_mode)) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_z(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_size == 0) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_s(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qnil;
|
|
|
|
if (st.st_size == 0) return Qnil;
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_int2inum(st.st_size);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_owned(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_uid == geteuid()) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_rowned(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_uid == getuid()) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_grpowned(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifndef NT
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0) return Qfalse;
|
|
|
|
if (st.st_gid == getegid()) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX)
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
check3rdbyte(fname, mode)
|
|
|
|
VALUE fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
|
|
|
if (stat(RSTRING(fname)->ptr, &st) < 0) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (st.st_mode & mode) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_suid(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifdef S_ISUID
|
2001-05-02 00:22:21 -04:00
|
|
|
return check3rdbyte(fname, S_ISUID);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_sgid(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-13 12:13:31 -04:00
|
|
|
#ifdef S_ISGID
|
2001-05-02 00:22:21 -04:00
|
|
|
return check3rdbyte(fname, S_ISGID);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
test_sticky(obj, fname)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifdef S_ISVTX
|
2001-05-02 00:22:21 -04:00
|
|
|
return check3rdbyte(fname, S_ISVTX);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-08-13 01:45:20 -04:00
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_size(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_int2inum(st.st_size);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-12-07 04:25:55 -05:00
|
|
|
rb_file_ftype(st)
|
|
|
|
struct stat *st;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
1999-12-07 04:25:55 -05:00
|
|
|
if (S_ISREG(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "file";
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else if (S_ISDIR(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "directory";
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else if (S_ISCHR(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "characterSpecial";
|
|
|
|
}
|
|
|
|
#ifdef S_ISBLK
|
1999-12-07 04:25:55 -05:00
|
|
|
else if (S_ISBLK(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "blockSpecial";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef S_ISFIFO
|
1999-12-07 04:25:55 -05:00
|
|
|
else if (S_ISFIFO(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "fifo";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef S_ISLNK
|
1999-12-07 04:25:55 -05:00
|
|
|
else if (S_ISLNK(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "link";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef S_ISSOCK
|
1999-12-07 04:25:55 -05:00
|
|
|
else if (S_ISSOCK(st->st_mode)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
t = "socket";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
t = "unknown";
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2(t);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-11-25 04:03:08 -05:00
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_ftype(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1999-11-25 04:03:08 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(fname);
|
1999-11-25 04:03:08 -05:00
|
|
|
if (lstat(RSTRING(fname)->ptr, &st) == -1) {
|
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
|
|
|
}
|
|
|
|
|
1999-12-07 04:25:55 -05:00
|
|
|
return rb_file_ftype(&st);
|
1999-11-25 04:03:08 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_atime(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_atime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_atime(obj)
|
1998-01-16 07:13:05 -05: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-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_atime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_mtime(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_mtime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_mtime(obj)
|
1998-01-16 07:13:05 -05: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-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_mtime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_ctime(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(fname, &st) < 0)
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_ctime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_ctime(obj)
|
1998-01-16 07:13:05 -05: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-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_ctime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chmod_internal(path, mode)
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *path;
|
1998-01-16 07:13:05 -05:00
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
if (chmod(path, mode) == -1)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_s_chmod(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE vmode;
|
|
|
|
VALUE rest;
|
|
|
|
int mode, n;
|
|
|
|
|
2000-05-12 05:07:57 -04:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_scan_args(argc, argv, "1*", &vmode, &rest);
|
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
|
|
|
|
n = apply2files(chmod_internal, rest, mode);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_chmod(obj, vmode)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj, vmode;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
int mode;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
|
|
|
|
GetOpenFile(obj, fptr);
|
2000-11-13 00:39:35 -05:00
|
|
|
#ifdef HAVE_FCHMOD
|
|
|
|
if (fchmod(fileno(fptr->f), mode) == -1)
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#else
|
2000-11-13 00:39:35 -05:00
|
|
|
if (!fptr->path) return Qnil;
|
|
|
|
if (chmod(fptr->path, mode) == -1)
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2001-02-16 02:53:21 -05:00
|
|
|
#if defined(HAVE_LCHMOD)
|
|
|
|
static void
|
|
|
|
lchmod_internal(path, mode)
|
|
|
|
const char *path;
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
if (lchmod(path, mode) == -1)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchmod(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE vmode;
|
|
|
|
VALUE rest;
|
|
|
|
int mode, n;
|
|
|
|
|
|
|
|
rb_secure(2);
|
|
|
|
rb_scan_args(argc, argv, "1*", &vmode, &rest);
|
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
|
|
|
|
n = apply2files(lchmod_internal, rest, mode);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchmod(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
struct chown_args {
|
|
|
|
int owner, group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
chown_internal(path, args)
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *path;
|
1998-01-16 07:13:05 -05:00
|
|
|
struct chown_args *args;
|
|
|
|
{
|
|
|
|
if (chown(path, args->owner, args->group) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_s_chown(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE o, g, rest;
|
|
|
|
struct chown_args arg;
|
|
|
|
int n;
|
|
|
|
|
2000-05-12 05:07:57 -04:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05: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);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_chown(obj, owner, group)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj, owner, group;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
GetOpenFile(obj, fptr);
|
2000-03-07 03:37:59 -05:00
|
|
|
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT) || defined(__EMX__)
|
1999-12-14 01:50:43 -05:00
|
|
|
if (!fptr->path) return Qnil;
|
1998-01-16 07:13:05 -05: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 00:22:21 -04:00
|
|
|
#if defined(HAVE_LCHOWN) && !defined(__CHECKER__)
|
2001-02-16 02:53:21 -05: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;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
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);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static VALUE
|
|
|
|
rb_file_s_lchown(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
struct timeval rb_time_timeval();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-08-07 01:05:04 -04:00
|
|
|
#if defined(HAVE_UTIMES) && !defined(__CHECKER__)
|
1998-01-16 07:13:05 -05: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-19 23:59:39 -05:00
|
|
|
rb_file_s_utime(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE atime, mtime, rest;
|
|
|
|
struct timeval tvp[2];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
tvp[0] = rb_time_timeval(atime);
|
|
|
|
tvp[1] = rb_time_timeval(mtime);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
n = apply2files(utime_internal, rest, tvp);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#ifndef HAVE_UTIME_H
|
|
|
|
# ifdef NT
|
1999-01-19 23:59:39 -05:00
|
|
|
# if defined(__BORLANDC__)
|
|
|
|
# include <utime.h>
|
|
|
|
# else
|
1998-01-16 07:13:05 -05:00
|
|
|
# include <sys/utime.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
# endif
|
2000-05-13 12:13:31 -04:00
|
|
|
# if defined(_MSC_VER) || defined __MINGW32__
|
1998-01-16 07:13:05 -05:00
|
|
|
# define utimbuf _utimbuf
|
1999-01-19 23:59:39 -05:00
|
|
|
# endif
|
1998-01-16 07:13:05 -05:00
|
|
|
# else
|
|
|
|
struct utimbuf {
|
|
|
|
long actime;
|
|
|
|
long modtime;
|
|
|
|
};
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
utime_internal(path, utp)
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *path;
|
1998-01-16 07:13:05 -05:00
|
|
|
struct utimbuf *utp;
|
|
|
|
{
|
|
|
|
if (utime(path, utp) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_s_utime(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE atime, mtime, rest;
|
|
|
|
int n;
|
|
|
|
struct timeval tv;
|
|
|
|
struct utimbuf utbuf;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
tv = rb_time_timeval(atime);
|
1998-01-16 07:13:05 -05:00
|
|
|
utbuf.actime = tv.tv_sec;
|
1999-01-19 23:59:39 -05:00
|
|
|
tv = rb_time_timeval(mtime);
|
1998-01-16 07:13:05 -05:00
|
|
|
utbuf.modtime = tv.tv_sec;
|
|
|
|
|
|
|
|
n = apply2files(utime_internal, rest, &utbuf);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_link(klass, from, to)
|
|
|
|
VALUE klass, from, to;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(from);
|
|
|
|
SafeStringValue(to);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (link(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0)
|
|
|
|
rb_sys_fail(RSTRING(from)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_symlink(klass, from, to)
|
|
|
|
VALUE klass, from, to;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-09-21 05:31:00 -04:00
|
|
|
#ifdef HAVE_SYMLINK
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(from);
|
|
|
|
SafeStringValue(to);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (symlink(RSTRING(from)->ptr, RSTRING(to)->ptr) < 0)
|
|
|
|
rb_sys_fail(RSTRING(from)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_notimplement();
|
|
|
|
return Qnil; /* not reached */
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_readlink(klass, path)
|
|
|
|
VALUE klass, path;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-09-21 23:37:27 -04:00
|
|
|
#ifdef HAVE_READLINK
|
1998-01-16 07:13:05 -05:00
|
|
|
char buf[MAXPATHLEN];
|
|
|
|
int cc;
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(path);
|
1998-01-16 07:19:22 -05:00
|
|
|
if ((cc = readlink(RSTRING(path)->ptr, buf, MAXPATHLEN)) < 0)
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_tainted_str_new(buf, cc);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
rb_notimplement();
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unlink_internal(path)
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *path;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (unlink(path) < 0)
|
|
|
|
rb_sys_fail(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_unlink(klass, args)
|
|
|
|
VALUE klass, args;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
2001-06-01 02:47:32 -04:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
n = apply2files(unlink_internal, args, 0);
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_rename(klass, from, to)
|
|
|
|
VALUE klass, from, to;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(from);
|
|
|
|
SafeStringValue(to);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-02-24 12:51:02 -05: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 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(from)->ptr);
|
2001-02-24 12:51:02 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_s_umask(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
int omask = 0;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (argc == 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
omask = umask(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
umask(omask);
|
|
|
|
}
|
|
|
|
else if (argc == 1) {
|
|
|
|
omask = umask(NUM2INT(argv[0]));
|
|
|
|
}
|
|
|
|
else {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eArgError, "wrong # of argument");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return INT2FIX(omask);
|
|
|
|
}
|
|
|
|
|
2001-07-24 11:11:02 -04:00
|
|
|
#ifndef HAVE_GETCWD
|
|
|
|
#define getcwd(buf, len) ((void)(len), getwd(buf))
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#if defined DOSISH
|
|
|
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
|
|
|
#else
|
|
|
|
#define isdirsep(x) ((x) == '/')
|
|
|
|
#endif
|
2001-07-24 11: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
|
|
|
|
|
|
|
|
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 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_s_expand_path(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE fname, dname;
|
2001-07-30 18:41:59 -04:00
|
|
|
char *s, *p, *b;
|
1999-01-19 23:59:39 -05:00
|
|
|
char buf[MAXPATHLEN+2];
|
2001-07-18 01:56:05 -04:00
|
|
|
char *bend = buf + sizeof(buf) - 2;
|
2000-01-04 23:41:21 -05:00
|
|
|
int tainted;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_scan_args(argc, argv, "11", &fname, &dname);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
tainted = OBJ_TAINTED(fname);
|
2001-07-30 18:41:59 -04:00
|
|
|
s = StringValuePtr(fname);
|
1998-01-16 07:13:05 -05:00
|
|
|
p = buf;
|
|
|
|
if (s[0] == '~') {
|
1999-08-13 01:45:20 -04:00
|
|
|
if (isdirsep(s[1]) || s[1] == '\0') {
|
1998-01-16 07:13:05 -05:00
|
|
|
char *dir = getenv("HOME");
|
|
|
|
|
|
|
|
if (!dir) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `%s'", s);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2001-07-18 01:56:05 -04:00
|
|
|
if (strlen(dir) > MAXPATHLEN) goto toolong;
|
1998-01-16 07:13:05 -05:00
|
|
|
strcpy(buf, dir);
|
|
|
|
p = &buf[strlen(buf)];
|
|
|
|
s++;
|
1999-12-07 04:25:55 -05:00
|
|
|
tainted = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
struct passwd *pwPtr;
|
|
|
|
s++;
|
|
|
|
#endif
|
2001-07-27 05:12:12 -04:00
|
|
|
b = s;
|
1999-08-13 01:45:20 -04:00
|
|
|
while (*s && !isdirsep(*s)) {
|
2001-07-27 05:12:12 -04:00
|
|
|
s = CharNext(s);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2001-07-27 05:12:12 -04:00
|
|
|
if (p + (s-b) >= bend) goto toolong;
|
|
|
|
memcpy(p, b, s-b);
|
|
|
|
p += s-b;
|
1998-01-16 07:13:05 -05:00
|
|
|
*p = '\0';
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
pwPtr = getpwnam(buf);
|
|
|
|
if (!pwPtr) {
|
|
|
|
endpwent();
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eArgError, "user %s doesn't exist", buf);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2001-07-18 01:56:05 -04:00
|
|
|
if (strlen(pwPtr->pw_dir) > MAXPATHLEN) goto toolong;
|
1998-01-16 07:13:05 -05:00
|
|
|
strcpy(buf, pwPtr->pw_dir);
|
|
|
|
p = &buf[strlen(buf)];
|
|
|
|
endpwent();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
#if defined DOSISH
|
|
|
|
/* skip drive letter */
|
2001-02-08 04:19:27 -05:00
|
|
|
else if (ISALPHA(s[0]) && s[1] == ':' && isdirsep(s[2])) {
|
2001-07-27 05:12:12 -04:00
|
|
|
b = s;
|
1999-08-13 01:45:20 -04:00
|
|
|
while (*s && !isdirsep(*s)) {
|
2001-07-27 05:12:12 -04:00
|
|
|
s = CharNext(s);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
2001-07-27 05:12:12 -04:00
|
|
|
if (p + (s-b) >= bend) goto toolong;
|
|
|
|
memcpy(p, b, s-b);
|
|
|
|
p += s-b;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
#endif
|
1999-09-16 05:40:33 -04:00
|
|
|
else if (!isdirsep(*s)) {
|
2000-10-13 05:01:58 -04:00
|
|
|
if (!NIL_P(dname)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
dname = rb_file_s_expand_path(1, &dname);
|
1999-12-06 04:04:03 -05:00
|
|
|
if (OBJ_TAINTED(dname)) tainted = 1;
|
2001-07-18 01:56:05 -04:00
|
|
|
if (strlen(RSTRING(dname)->ptr) > MAXPATHLEN) goto toolong;
|
1999-01-19 23:59:39 -05:00
|
|
|
strcpy(buf, RSTRING(dname)->ptr);
|
|
|
|
}
|
|
|
|
else {
|
1999-12-06 04:04:03 -05:00
|
|
|
tainted = 1;
|
1999-01-19 23:59:39 -05:00
|
|
|
getcwd(buf, MAXPATHLEN);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
p = &buf[strlen(buf)];
|
1999-01-19 23:59:39 -05:00
|
|
|
while (p > buf && *(p - 1) == '/') p--;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-01-17 03:37:53 -05:00
|
|
|
else {
|
1999-09-16 05:40:33 -04:00
|
|
|
while (*s && isdirsep(*s)) {
|
|
|
|
*p++ = '/';
|
2001-07-18 01:56:05 -04:00
|
|
|
if (p >= bend) goto toolong;
|
1999-09-16 05:40:33 -04:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (p > buf && *s) p--;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
*p = '/';
|
|
|
|
|
2001-07-30 18:41:59 -04:00
|
|
|
b = s;
|
2001-07-27 05:12:12 -04:00
|
|
|
while (*s) {
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (*s) {
|
|
|
|
case '.':
|
2001-07-30 18:41:59 -04:00
|
|
|
if (b == s++) { /* beginning of path element */
|
|
|
|
switch (*s) {
|
|
|
|
case '\0':
|
|
|
|
b = s;
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
case '.':
|
2001-07-16 00:22:46 -04:00
|
|
|
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
|
1998-01-16 07:13:05 -05:00
|
|
|
/* We must go back to the parent */
|
2001-07-30 18:41:59 -04:00
|
|
|
*p = '\0';
|
|
|
|
if (!(b = strrdirsep(buf))) {
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = b;
|
|
|
|
}
|
|
|
|
b = ++s;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
1999-08-13 01:45:20 -04:00
|
|
|
#if defined DOSISH
|
|
|
|
case '\\':
|
|
|
|
#endif
|
2001-07-30 18:41:59 -04:00
|
|
|
b = ++s;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
default:
|
2001-07-30 18:41:59 -04:00
|
|
|
/* ordinary path element, beginning don't move */
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
1999-08-13 01:45:20 -04:00
|
|
|
#if defined DOSISH
|
|
|
|
case '\\':
|
|
|
|
#endif
|
2001-07-30 18:41:59 -04:00
|
|
|
if (s > b) {
|
|
|
|
if (p + (s-b+1) >= bend) goto toolong;
|
|
|
|
memcpy(++p, b, s-b);
|
|
|
|
p += s-b;
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
b = ++s;
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
2001-07-27 05:12:12 -04:00
|
|
|
s = CharNext(s);
|
2001-07-30 18:41:59 -04:00
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
2001-07-16 00:22:46 -04:00
|
|
|
|
2001-07-30 18:41:59 -04:00
|
|
|
if (s > b) {
|
|
|
|
if (p + (s-b) >= bend) goto toolong;
|
|
|
|
memcpy(++p, b, s-b);
|
|
|
|
p += s-b;
|
|
|
|
}
|
|
|
|
else if (p == buf) {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
#if defined(DOSISH)
|
|
|
|
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 07:13:05 -05:00
|
|
|
|
2001-07-30 18:41:59 -04:00
|
|
|
fname = rb_str_new(buf, p - buf);
|
1999-12-06 04:04:03 -05:00
|
|
|
if (tainted) OBJ_TAINT(fname);
|
|
|
|
return fname;
|
2001-07-18 01:56:05 -04:00
|
|
|
|
|
|
|
toolong:
|
|
|
|
rb_raise(rb_eArgError, "argument too long (size=%d)", RSTRING(fname)->len);
|
|
|
|
return Qnil; /* not reached */
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rmext(p, e)
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *p, *e;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int l1, l2;
|
|
|
|
|
|
|
|
l1 = strlen(p);
|
|
|
|
if (!e) return 0;
|
|
|
|
|
|
|
|
l2 = strlen(e);
|
1998-01-16 07:19:22 -05:00
|
|
|
if (l2 == 2 && e[1] == '*') {
|
|
|
|
e = strrchr(p, *e);
|
|
|
|
if (!e) return 0;
|
|
|
|
return e - p;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
if (l1 < l2) return l1;
|
|
|
|
|
|
|
|
if (strcmp(p+l1-l2, e) == 0) {
|
|
|
|
return l1-l2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_s_basename(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
VALUE fname, fext, basename;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *name, *p, *ext;
|
1998-01-16 07:13:05 -05:00
|
|
|
int f;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
|
2001-05-02 00:22:21 -04:00
|
|
|
ext = StringValuePtr(fext);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2001-05-02 00:22:21 -04:00
|
|
|
name = StringValuePtr(fname);
|
2001-07-24 11:11:02 -04:00
|
|
|
p = strrdirsep(name);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (!p) {
|
2000-06-12 03:48:31 -04:00
|
|
|
if (NIL_P(fext) || !(f = rmext(name, ext)))
|
2000-05-30 00:24:17 -04:00
|
|
|
return fname;
|
2000-06-12 03:48:31 -04:00
|
|
|
basename = rb_str_new(name, f);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-30 00:24:17 -04:00
|
|
|
else {
|
|
|
|
p++; /* skip last `/' */
|
|
|
|
if (NIL_P(fext) || !(f = rmext(p, ext))) {
|
|
|
|
basename = rb_str_new2(p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
basename = rb_str_new(p, f);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-30 00:24:17 -04:00
|
|
|
OBJ_INFECT(basename, fname);
|
1999-12-01 04:24:48 -05:00
|
|
|
return basename;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_dirname(klass, fname)
|
|
|
|
VALUE klass, fname;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
char *name, *p;
|
1999-12-01 04:24:48 -05:00
|
|
|
VALUE dirname;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
name = StringValuePtr(fname);
|
2001-07-24 11:11:02 -04:00
|
|
|
p = strrdirsep(name);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (!p) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2(".");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (p == name)
|
1998-01-16 07:13:05 -05:00
|
|
|
p++;
|
1999-12-01 04:24:48 -05:00
|
|
|
dirname = rb_str_new(name, p - name);
|
|
|
|
if (OBJ_TAINTED(fname)) OBJ_TAINT(dirname);
|
|
|
|
return dirname;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_split(klass, path)
|
|
|
|
VALUE klass, path;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_assoc_new(rb_file_s_dirname(Qnil, path), rb_file_s_basename(1,&path));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE separator;
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_join(klass, args)
|
|
|
|
VALUE klass, args;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_ary_join(args, separator);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_file_s_truncate(klass, path, len)
|
|
|
|
VALUE klass, path, len;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-12 05:07:57 -04:00
|
|
|
rb_secure(2);
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(path);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#ifdef HAVE_TRUNCATE
|
1998-01-16 07:19:22 -05:00
|
|
|
if (truncate(RSTRING(path)->ptr, NUM2INT(len)) < 0)
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
# ifdef HAVE_CHSIZE
|
|
|
|
{
|
|
|
|
int tmpfd;
|
|
|
|
|
|
|
|
# if defined(NT)
|
1998-01-16 07:19:22 -05:00
|
|
|
if ((tmpfd = open(RSTRING(path)->ptr, O_RDWR)) < 0) {
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
# else
|
1998-01-16 07:19:22 -05:00
|
|
|
if ((tmpfd = open(RSTRING(path)->ptr, 0)) < 0) {
|
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
if (chsize(tmpfd, NUM2INT(len)) < 0) {
|
|
|
|
close(tmpfd);
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_sys_fail(RSTRING(path)->ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
close(tmpfd);
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
rb_notimplement();
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_truncate(obj, len)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj, len;
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
if (!(fptr->mode & FMODE_WRITABLE)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eIOError, "not opened for writing");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#ifdef HAVE_TRUNCATE
|
|
|
|
if (ftruncate(fileno(fptr->f), NUM2INT(len)) < 0)
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_CHSIZE
|
|
|
|
if (chsize(fileno(fptr->f), NUM2INT(len)) < 0)
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
# else
|
|
|
|
rb_notimplement();
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05: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 03:57:16 -05:00
|
|
|
#if 0
|
1999-01-19 23:59:39 -05:00
|
|
|
static int
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_thread_flock(fd, op, fptr)
|
1999-01-19 23:59:39 -05:00
|
|
|
int fd, op;
|
1999-08-13 01:45:20 -04:00
|
|
|
OpenFile *fptr;
|
1999-01-19 23:59:39 -05: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 03:57:16 -05:00
|
|
|
case EAGAIN:
|
|
|
|
case EACCES:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
1999-01-19 23:59:39 -05:00
|
|
|
case EWOULDBLOCK:
|
2001-03-26 03:57:16 -05:00
|
|
|
#endif
|
2000-05-17 00:38:19 -04:00
|
|
|
rb_thread_polling(); /* busy wait */
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_io_check_closed(fptr);
|
2001-03-26 03:57:16 -05:00
|
|
|
continue;
|
1999-01-19 23:59:39 -05:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
#define flock(fd, op) rb_thread_flock(fd, op, fptr)
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_file_flock(obj, operation)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
VALUE operation;
|
|
|
|
{
|
2000-08-07 01:05:04 -04:00
|
|
|
#ifndef __CHECKER__
|
1998-01-16 07:13:05 -05:00
|
|
|
OpenFile *fptr;
|
2000-10-17 14:14:05 -04:00
|
|
|
int ret;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(2);
|
1998-01-16 07:13:05 -05:00
|
|
|
GetOpenFile(obj, fptr);
|
|
|
|
|
2000-01-08 00:00:25 -05:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
|
|
|
fflush(GetWriteFile(fptr));
|
|
|
|
}
|
2000-10-17 14:14:05 -04:00
|
|
|
TRAP_BEG;
|
|
|
|
ret = flock(fileno(fptr->f), NUM2INT(operation));
|
|
|
|
TRAP_END;
|
|
|
|
if (ret < 0) {
|
2001-03-26 03:57:16 -05:00
|
|
|
switch (errno) {
|
|
|
|
case EAGAIN:
|
|
|
|
case EACCES:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
2001-03-26 03:57:16 -05:00
|
|
|
return Qfalse;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
2000-08-07 01:05:04 -04:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
#undef flock
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_check(n, argc, argv)
|
|
|
|
int n, argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
n+=1;
|
2000-04-10 01:48:43 -04:00
|
|
|
if (n != argc) rb_raise(rb_eArgError, "wrong # of arguments(%d for %d)", argc, n);
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=1; i<n; i++) {
|
1999-01-19 23:59:39 -05:00
|
|
|
switch (TYPE(argv[i])) {
|
|
|
|
case T_STRING:
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(argv[i]);
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
case T_FILE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Check_Type(argv[i], T_STRING);
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK(n) test_check((n), argc, argv)
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_f_test(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
int cmd;
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (argc == 0) rb_raise(rb_eArgError, "wrong # of arguments");
|
2000-08-24 02:21:43 -04:00
|
|
|
#if 0 /* 1.7 behavior? */
|
|
|
|
if (argc == 1) {
|
|
|
|
return RTEST(argv[0]) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
cmd = NUM2CHR(argv[0]);
|
|
|
|
if (cmd == 0) return Qfalse;
|
1998-01-16 07:13:05 -05: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-19 23:59:39 -05:00
|
|
|
if (rb_stat(argv[1], &st) == -1) {
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_sys_fail(RSTRING(argv[1])->ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case 'A':
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_atime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
case 'M':
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_mtime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
case 'C':
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_time_new(st.st_ctime, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr("-=<>", cmd)) {
|
|
|
|
struct stat st1, st2;
|
|
|
|
|
|
|
|
CHECK(2);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_stat(argv[1], &st1) < 0) return Qfalse;
|
|
|
|
if (rb_stat(argv[2], &st2) < 0) return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case '-':
|
|
|
|
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1999-10-12 00:53:36 -04:00
|
|
|
return Qfalse;
|
2001-07-16 00:22:46 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case '=':
|
1999-01-19 23:59:39 -05:00
|
|
|
if (st1.st_mtime == st2.st_mtime) return Qtrue;
|
1999-10-12 00:53:36 -04:00
|
|
|
return Qfalse;
|
2001-07-16 00:22:46 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case '>':
|
1999-01-19 23:59:39 -05:00
|
|
|
if (st1.st_mtime > st2.st_mtime) return Qtrue;
|
1999-10-12 00:53:36 -04:00
|
|
|
return Qfalse;
|
2001-07-16 00:22:46 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case '<':
|
1999-01-19 23:59:39 -05:00
|
|
|
if (st1.st_mtime < st2.st_mtime) return Qtrue;
|
1999-10-12 00:53:36 -04:00
|
|
|
return Qfalse;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
/* unknown command */
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_raise(rb_eArgError, "unknown command ?%c", cmd);
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
static VALUE
|
|
|
|
rb_stat_s_new(klass, fname)
|
|
|
|
VALUE klass, fname;
|
|
|
|
{
|
|
|
|
VALUE s;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
Check_SafeStr(fname);
|
|
|
|
if (stat(RSTRING(fname)->ptr, &st) == -1) {
|
|
|
|
rb_sys_fail(RSTRING(fname)->ptr);
|
|
|
|
}
|
|
|
|
s = stat_new_0(klass, &st);
|
|
|
|
rb_obj_call_init(s, 1, &fname);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_init(klass, fname)
|
|
|
|
VALUE klass, fname;
|
|
|
|
{
|
|
|
|
/* do nothing */
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1999-11-25 04:03:08 -05:00
|
|
|
static VALUE
|
|
|
|
rb_stat_ftype(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-07 04:25:55 -05:00
|
|
|
return rb_file_ftype(get_stat(obj));
|
1999-11-25 04:03:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_d(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
if (S_ISDIR(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_p(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_IFIFO
|
1999-12-01 04:24:48 -05:00
|
|
|
if (S_ISFIFO(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_l(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISLNK
|
1999-12-01 04:24:48 -05:00
|
|
|
if (S_ISLNK(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_S(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISSOCK
|
1999-12-01 04:24:48 -05:00
|
|
|
if (S_ISSOCK(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_b(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISBLK
|
1999-12-01 04:24:48 -05:00
|
|
|
if (S_ISBLK(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_c(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-01-31 22:12:21 -05:00
|
|
|
if (S_ISCHR(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_owned(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_uid == geteuid()) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_rowned(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_uid == getuid()) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_grpowned(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifndef NT
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_gid == getegid()) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_r(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 04:04:03 -05:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 04:03:08 -05:00
|
|
|
|
|
|
|
#ifdef S_IRUSR
|
|
|
|
if (rb_stat_owned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IRUSR ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
#ifdef S_IRGRP
|
|
|
|
if (rb_stat_grpowned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IRGRP ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
#ifdef S_IROTH
|
1999-12-06 04:04:03 -05:00
|
|
|
if (!(st->st_mode & S_IROTH)) return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_R(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 04:04:03 -05:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 04:03:08 -05:00
|
|
|
|
|
|
|
#ifdef S_IRUSR
|
|
|
|
if (rb_stat_rowned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IRUSR ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
#ifdef S_IRGRP
|
1999-12-01 04:24:48 -05:00
|
|
|
if (group_member(get_stat(obj)->st_gid))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IRGRP ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
#ifdef S_IROTH
|
1999-12-06 04:04:03 -05:00
|
|
|
if (!(st->st_mode & S_IROTH)) return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_w(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 04:04:03 -05:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 04:03:08 -05:00
|
|
|
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IWUSR
|
1999-11-25 04:03:08 -05:00
|
|
|
if (rb_stat_owned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IWUSR ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IWGRP
|
1999-11-25 04:03:08 -05:00
|
|
|
if (rb_stat_grpowned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IWGRP ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IWOTH
|
|
|
|
if (!(st->st_mode & S_IWOTH)) return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_W(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 04:04:03 -05:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 04:03:08 -05:00
|
|
|
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IWUSR
|
1999-11-25 04:03:08 -05:00
|
|
|
if (rb_stat_rowned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IWUSR ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IWGRP
|
1999-12-01 04:24:48 -05:00
|
|
|
if (group_member(get_stat(obj)->st_gid))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IWGRP ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IWOTH
|
|
|
|
if (!(st->st_mode & S_IWOTH)) return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_x(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 04:04:03 -05:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 04:03:08 -05:00
|
|
|
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IXUSR
|
1999-11-25 04:03:08 -05:00
|
|
|
if (rb_stat_owned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IXUSR ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IXGRP
|
1999-11-25 04:03:08 -05:00
|
|
|
if (rb_stat_grpowned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IXGRP ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IXOTH
|
|
|
|
if (!(st->st_mode & S_IXOTH)) return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_X(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-06 04:04:03 -05:00
|
|
|
struct stat *st = get_stat(obj);
|
1999-11-25 04:03:08 -05:00
|
|
|
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IXUSR
|
1999-11-25 04:03:08 -05:00
|
|
|
if (rb_stat_rowned(obj))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IXUSR ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IXGRP
|
1999-12-01 04:24:48 -05:00
|
|
|
if (group_member(get_stat(obj)->st_gid))
|
1999-12-06 04:04:03 -05:00
|
|
|
return st->st_mode & S_IXGRP ? Qtrue : Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
1999-12-06 04:04:03 -05:00
|
|
|
#ifdef S_IXOTH
|
|
|
|
if (!(st->st_mode & S_IXOTH)) return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_f(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
if (S_ISREG(get_stat(obj)->st_mode)) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_z(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_size == 0) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_s(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-01 04:24:48 -05:00
|
|
|
int size = get_stat(obj)->st_size;
|
1999-11-25 04:03:08 -05:00
|
|
|
|
1999-12-01 04:24:48 -05:00
|
|
|
if (size == 0) return Qnil;
|
|
|
|
return INT2FIX(size);
|
1999-11-25 04:03:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_suid(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISUID
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_mode & S_ISUID) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_sgid(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-05-13 12:13:31 -04:00
|
|
|
#ifdef S_ISGID
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_mode & S_ISGID) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_stat_sticky(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
#ifdef S_ISVTX
|
1999-12-01 04:24:48 -05:00
|
|
|
if (get_stat(obj)->st_mode & S_ISVTX) return Qtrue;
|
1999-11-25 04:03:08 -05:00
|
|
|
#endif
|
2000-06-12 03:48:31 -04:00
|
|
|
return Qfalse;
|
1999-11-25 04:03:08 -05:00
|
|
|
}
|
|
|
|
|
2000-09-25 05:15:08 -04:00
|
|
|
static VALUE rb_mFConst;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_file_const(name, value)
|
|
|
|
const char *name;
|
|
|
|
VALUE value;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-09-25 05:15:08 -04:00
|
|
|
rb_define_const(rb_mFConst, name, value);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
static int
|
|
|
|
is_absolute_path(path)
|
|
|
|
const char *path;
|
|
|
|
{
|
2001-07-24 11:11:02 -04:00
|
|
|
#ifdef DOSISH
|
|
|
|
if (ISALPHA(path[0]) && path[1] == ':' && isdirsep(path[2])) return 1;
|
|
|
|
if (isdirsep(path[0]) && isdirsep(path[1])) return 1;
|
|
|
|
#else
|
2000-01-04 23:41:21 -05:00
|
|
|
if (path[0] == '/') return 1;
|
2001-07-24 11:11:02 -04:00
|
|
|
#endif
|
2000-01-04 23:41:21 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
path_check_1(path)
|
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *p = 0;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (!is_absolute_path(path)) {
|
|
|
|
char buf[MAXPATHLEN+1];
|
|
|
|
|
2000-03-13 02:18:45 -05:00
|
|
|
if (getcwd(buf, MAXPATHLEN) == 0) return 0;
|
2000-03-17 03:58:21 -05:00
|
|
|
strncat(buf, "/", MAXPATHLEN);
|
2000-01-04 23:41:21 -05:00
|
|
|
strncat(buf, path, MAXPATHLEN);
|
|
|
|
buf[MAXPATHLEN] = '\0';
|
|
|
|
return path_check_1(buf);
|
|
|
|
}
|
|
|
|
for (;;) {
|
2001-03-20 22:51:23 -05:00
|
|
|
if (stat(path, &st) == 0 && (st.st_mode & 002)) {
|
2001-07-24 11:11:02 -04:00
|
|
|
if (p) *p = '/';
|
2000-01-04 23:41:21 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2001-07-24 11:11:02 -04:00
|
|
|
s = strrdirsep(path);
|
2000-01-04 23:41:21 -05:00
|
|
|
if (p) *p = '/';
|
|
|
|
if (!s || s == path) return 1;
|
|
|
|
p = s;
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_path_check(path)
|
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
char *p, *pend;
|
|
|
|
const char sep = PATH_SEP_CHAR;
|
|
|
|
|
|
|
|
if (!path) return 1;
|
|
|
|
|
|
|
|
p = path;
|
|
|
|
pend = strchr(path, sep);
|
2001-07-16 00:22:46 -04:00
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
for (;;) {
|
|
|
|
int safe;
|
|
|
|
|
|
|
|
if (pend) *pend = '\0';
|
|
|
|
safe = path_check_1(p);
|
2001-01-09 03:04:39 -05:00
|
|
|
if (!safe) {
|
|
|
|
if (pend) *pend = sep;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-01-04 23:41:21 -05:00
|
|
|
if (!pend) break;
|
|
|
|
*pend = sep;
|
|
|
|
p = pend + 1;
|
|
|
|
pend = strchr(p, sep);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-02-17 02:11:22 -05:00
|
|
|
#if defined(__MACOS__) || defined(riscos)
|
2000-01-04 23:41:21 -05:00
|
|
|
static int
|
|
|
|
is_macos_native_path(path)
|
|
|
|
const char *path;
|
|
|
|
{
|
|
|
|
if (strchr(path, ':')) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
static int
|
2001-06-19 00:35:17 -04:00
|
|
|
file_load_ok(file)
|
|
|
|
char *file;
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
2001-07-16 00:22:46 -04:00
|
|
|
if (!file) return 0;
|
2001-06-19 00:35:17 -04:00
|
|
|
f = fopen(file, "r");
|
|
|
|
if (f == NULL) return 0;
|
|
|
|
fclose(f);
|
2001-07-14 11:17:19 -04:00
|
|
|
return 1;
|
2001-06-19 00:35:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern VALUE rb_load_path;
|
|
|
|
|
|
|
|
int
|
2001-09-03 01:37:42 -04:00
|
|
|
rb_find_file_ext(filep, ext)
|
2001-07-14 11:17:19 -04:00
|
|
|
VALUE *filep;
|
2001-09-03 01:37:42 -04:00
|
|
|
char **ext;
|
2001-06-19 00:35:17 -04:00
|
|
|
{
|
|
|
|
char *path, *e, *found;
|
2001-07-14 11:17:19 -04:00
|
|
|
char *f = RSTRING(*filep)->ptr;
|
2001-06-19 00:35:17 -04:00
|
|
|
VALUE fname;
|
|
|
|
int i, j;
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
if (f[0] == '~') {
|
|
|
|
fname = *filep;
|
2001-06-19 00:35:17 -04:00
|
|
|
fname = rb_file_s_expand_path(1, &fname);
|
2001-07-14 11: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 05:12:12 -04:00
|
|
|
f = StringValuePtr(fname);
|
2001-07-25 23:54:48 -04:00
|
|
|
*filep = fname;
|
2001-06-19 00:35:17 -04:00
|
|
|
}
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
if (is_absolute_path(f)) {
|
2001-06-19 00:35:17 -04:00
|
|
|
for (i=0; ext[i]; i++) {
|
2001-07-14 11: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 00: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);
|
|
|
|
path = RSTRING(str)->ptr;
|
|
|
|
for (j=0; ext[j]; j++) {
|
2001-07-14 11: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 00:35:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
VALUE
|
|
|
|
rb_find_file(path)
|
|
|
|
VALUE path;
|
2000-01-04 23:41:21 -05:00
|
|
|
{
|
2001-07-14 11:17:19 -04:00
|
|
|
VALUE tmp, fname;
|
|
|
|
char *f = RSTRING(path)->ptr;
|
|
|
|
char *lpath;
|
2000-05-24 00:34:26 -04:00
|
|
|
struct stat st;
|
2000-01-04 23:41:21 -05:00
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
if (f[0] == '~') {
|
2001-07-25 23:54:48 -04:00
|
|
|
path = rb_file_s_expand_path(1, &path);
|
|
|
|
if (rb_safe_level() >= 2 && OBJ_TAINTED(path)) {
|
2001-07-14 11:17:19 -04:00
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
2001-06-19 00:35:17 -04:00
|
|
|
}
|
2001-07-27 05:12:12 -04:00
|
|
|
f = StringValuePtr(path);
|
2001-06-19 00:35:17 -04:00
|
|
|
}
|
|
|
|
|
2000-02-17 02:11:22 -05:00
|
|
|
#if defined(__MACOS__) || defined(riscos)
|
2001-07-14 11: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-04 23:41:21 -05:00
|
|
|
}
|
2001-07-14 11:17:19 -04:00
|
|
|
if (file_load_ok(f)) return path;
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-07-14 11: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-04 23:41:21 -05:00
|
|
|
}
|
2001-07-14 11:17:19 -04:00
|
|
|
if (file_load_ok(f)) return path;
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rb_load_path) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Check_Type(rb_load_path, T_ARRAY);
|
2001-07-14 11:17:19 -04:00
|
|
|
tmp = rb_ary_new();
|
2000-01-04 23:41:21 -05:00
|
|
|
for (i=0;i<RARRAY(rb_load_path)->len;i++) {
|
|
|
|
VALUE str = RARRAY(rb_load_path)->ptr[i];
|
2001-05-02 00:22:21 -04:00
|
|
|
SafeStringValue(str);
|
2000-01-04 23:41:21 -05:00
|
|
|
if (RSTRING(str)->len > 0) {
|
2001-07-14 11:17:19 -04:00
|
|
|
rb_ary_push(tmp, str);
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
}
|
2001-07-14 11:17:19 -04:00
|
|
|
tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP));
|
|
|
|
lpath = StringValuePtr(tmp);
|
|
|
|
if (rb_safe_level() >= 2 && !rb_path_check(lpath)) {
|
|
|
|
rb_raise(rb_eSecurityError, "loading from unsafe path %s", lpath);
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-07-14 11:17:19 -04:00
|
|
|
lpath = 0;
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
f = dln_find_file(f, lpath);
|
|
|
|
if (file_load_ok(f)) {
|
|
|
|
return rb_str_new2(f);
|
|
|
|
}
|
2001-07-24 05:07:33 -04:00
|
|
|
return 0;
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
|
2000-09-18 04: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 02:52:46 -05:00
|
|
|
void
|
1999-08-13 01:45:20 -04:00
|
|
|
Init_File()
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mFileTest = rb_define_module("FileTest");
|
|
|
|
rb_cFile = rb_define_class("File", rb_cIO);
|
2000-09-18 04: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 03:03:36 -04:00
|
|
|
define_filetest_function("size", rb_file_s_size, 1);
|
2000-09-18 04: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-19 23:59:39 -05: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 02:53:21 -05: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-19 23:59:39 -05: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);
|
|
|
|
|
|
|
|
separator = rb_str_new2("/");
|
|
|
|
rb_define_const(rb_cFile, "Separator", separator);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_const(rb_cFile, "SEPARATOR", separator);
|
1999-01-19 23:59:39 -05: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 11:49:37 -04:00
|
|
|
#if defined DOSISH && !defined __CYGWIN__
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_const(rb_cFile, "ALT_SEPARATOR", rb_str_new2("\\"));
|
|
|
|
#else
|
|
|
|
rb_define_const(rb_cFile, "ALT_SEPARATOR", Qnil);
|
|
|
|
#endif
|
|
|
|
rb_define_const(rb_cFile, "PATH_SEPARATOR", rb_str_new2(PATH_SEP));
|
1999-01-19 23:59:39 -05: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 05:15:08 -04:00
|
|
|
rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
|
|
|
|
rb_include_module(rb_cFile, rb_mFConst);
|
1999-08-13 01: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-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_cFile, "path", rb_file_path, 0);
|
|
|
|
|
|
|
|
rb_define_global_function("test", rb_f_test, -1);
|
|
|
|
|
1999-12-01 04:24:48 -05:00
|
|
|
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_define_singleton_method(rb_cStat, "new", rb_stat_s_new, 1);
|
|
|
|
rb_define_method(rb_cStat, "initialize", rb_stat_init, 1);
|
1999-12-01 04:24:48 -05: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);
|
|
|
|
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 04:38:11 -04:00
|
|
|
rb_define_method(rb_cStat, "inspect", rb_stat_inspect, 0);
|
|
|
|
|
1999-12-01 04:24:48 -05: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 07:13:05 -05:00
|
|
|
}
|