Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

file.c File Reference

#include "ruby.h"
#include "rubyio.h"
#include "rubysig.h"
#include "util.h"
#include "dln.h"
#include <unistd.h>
#include <sys/file.h>
#include <sys/param.h>
#include <time.h>
#include <utime.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>

Go to the source code of this file.

Data Structures

struct  chown_args

Defines

#define MAXPATHLEN   1024
#define NGROUPS   32
#define S_IXUGO   (S_IXUSR | S_IXGRP | S_IXOTH)
#define S_ISDIR(m)   ((m & S_IFMT) == S_IFDIR)
#define S_ISBLK(m)   (0)
#define S_ISCHR(m)   ((m & S_IFMT) == S_IFCHR)
#define S_ISREG(m)   ((m & S_IFMT) == S_IFREG)
#define isdirsep(x)   ((x) == '/')
#define CharNext(p)   ((p) + 1)
#define nextdirsep   rb_path_next
#define skipprefix(path)   (path)
#define strrdirsep   rb_path_last_separator
#define chompdirsep   rb_path_end
#define BUFCHECK(cond)
#define BUFINIT()
#define TOLOWER(c)   (ISUPPER(c) ? tolower(c) : (c))
#define LOCK_SH   1
#define LOCK_EX   2
#define LOCK_NB   4
#define LOCK_UN   8
#define flock(fd, op)   rb_thread_flock(fd, op, fptr)
#define CHECK(n)   test_check((n), argc, argv)
#define S_IWOTH   002

Functions

VALUE rb_time_new (time_t, time_t)
long apply2files (void(*(const char *, void *), VALUE, void *))
long apply2files (func, VALUE vargs, void *arg)
VALUE rb_file_path (VALUE obj)
VALUE stat_new_0 (VALUE klass, struct stat *st)
VALUE stat_new (struct stat *st)
stat * get_stat (VALUE self)
VALUE rb_stat_cmp (VALUE self, VALUE other)
VALUE rb_stat_dev (VALUE)
VALUE rb_stat_ino (VALUE)
VALUE rb_stat_mode (VALUE)
VALUE rb_stat_nlink (VALUE)
VALUE rb_stat_uid (VALUE)
VALUE rb_stat_gid (VALUE)
VALUE rb_stat_rdev (VALUE)
VALUE rb_stat_size (VALUE)
VALUE rb_stat_blksize (VALUE)
VALUE rb_stat_blocks (VALUE)
VALUE rb_stat_atime (VALUE)
VALUE rb_stat_mtime (VALUE)
VALUE rb_stat_ctime (VALUE)
VALUE rb_stat_dev_major (VALUE self)
VALUE rb_stat_dev_minor (VALUE self)
VALUE rb_stat_rdev_major (VALUE self)
VALUE rb_stat_rdev_minor (VALUE self)
VALUE rb_stat_inspect (VALUE self)
int rb_stat (VALUE file, struct stat *st)
VALUE rb_file_s_stat (VALUE klass, VALUE fname)
VALUE rb_io_stat (VALUE obj)
VALUE rb_file_s_lstat (VALUE klass, VALUE fname)
VALUE rb_file_lstat (VALUE obj)
int group_member (GETGROUPS_T gid)
int eaccess (char *path, int mode) const
VALUE test_d (VALUE obj, VALUE fname)
VALUE test_p (VALUE obj, VALUE fname)
VALUE test_l (VALUE obj, VALUE fname)
VALUE test_S (VALUE obj, VALUE fname)
VALUE test_b (VALUE obj, VALUE fname)
VALUE test_c (VALUE obj, VALUE fname)
VALUE test_e (VALUE obj, VALUE fname)
VALUE test_r (VALUE obj, VALUE fname)
VALUE test_R (VALUE obj, VALUE fname)
VALUE test_w (VALUE obj, VALUE fname)
VALUE test_W (VALUE obj, VALUE fname)
VALUE test_x (VALUE obj, VALUE fname)
VALUE test_X (VALUE obj, VALUE fname)
VALUE test_f (VALUE obj, VALUE fname)
VALUE test_z (VALUE obj, VALUE fname)
VALUE test_s (VALUE obj, VALUE fname)
VALUE test_owned (VALUE obj, VALUE fname)
VALUE test_rowned (VALUE obj, VALUE fname)
VALUE test_grpowned (VALUE obj, VALUE fname)
VALUE test_suid (VALUE obj, VALUE fname)
VALUE test_sgid (VALUE obj, VALUE fname)
VALUE test_sticky (VALUE obj, VALUE fname)
VALUE test_identical (VALUE obj, VALUE fname1, VALUE fname2)
VALUE rb_file_s_size (VALUE klass, VALUE fname)
VALUE rb_file_ftype (struct stat *st)
VALUE rb_file_s_ftype (VALUE klass, VALUE fname)
VALUE rb_file_s_atime (VALUE klass, VALUE fname)
VALUE rb_file_atime (VALUE obj)
VALUE rb_file_s_mtime (VALUE klass, VALUE fname)
VALUE rb_file_mtime (VALUE obj)
VALUE rb_file_s_ctime (VALUE klass, VALUE fname)
VALUE rb_file_ctime (VALUE obj)
void chmod_internal (const char *, void *)
void chmod_internal (char *path, void *mode) const
VALUE rb_file_s_chmod (int argc, VALUE *argv)
VALUE rb_file_chmod (VALUE obj, VALUE vmode)
VALUE rb_file_s_lchmod (int argc, VALUE *argv)
void chown_internal (const char *, void *)
void chown_internal (char *path, void *argp) const
VALUE rb_file_s_chown (int argc, VALUE *argv)
VALUE rb_file_chown (VALUE obj, VALUE owner, VALUE group)
void lchown_internal (const char *, void *)
void lchown_internal (char *path, void *argp) const
VALUE rb_file_s_lchown (int argc, VALUE *argv)
timeval rb_time_timeval ()
void utime_internal (const char *, void *)
void utime_internal (char *path, void *arg) const
VALUE rb_file_s_utime (int argc, VALUE *argv)
void sys_fail2 (VALUE, VALUE)
VALUE rb_file_s_link (VALUE klass, VALUE from, VALUE to)
VALUE rb_file_s_symlink (VALUE klass, VALUE from, VALUE to)
VALUE rb_file_s_readlink (VALUE klass, VALUE path)
void unlink_internal (const char *, void *)
void unlink_internal (char *path, void *arg) const
VALUE rb_file_s_unlink (VALUE klass, VALUE args)
VALUE rb_file_s_rename (VALUE klass, VALUE from, VALUE to)
VALUE rb_file_s_umask (int argc, VALUE *argv)
char * skiproot (char *path) const
char * rb_path_next (char *s) const
char * rb_path_skip_prefix (char *path) const
char * rb_path_last_separator (char *path) const
char * rb_path_end (char *path) const
int is_absolute_path (const char *)
VALUE file_expand_path (VALUE fname, VALUE dname, VALUE result)
VALUE rb_file_expand_path (VALUE fname, VALUE dname)
VALUE rb_file_s_expand_path (int argc, VALUE *argv)
int rmext (char *p, char *e) const
VALUE rb_file_s_basename (int argc, VALUE *argv)
VALUE rb_file_s_dirname (VALUE klass, VALUE fname)
VALUE rb_file_s_extname (VALUE klass, VALUE fname)
VALUE rb_file_s_split (VALUE klass, VALUE path)
VALUE rb_file_join (VALUE ary, VALUE sep)
VALUE file_inspect_join (VALUE ary, VALUE *arg)
VALUE rb_file_s_join (VALUE klass, VALUE args)
VALUE rb_file_s_truncate (VALUE klass, VALUE path, VALUE len)
VALUE rb_file_truncate (VALUE obj, VALUE len)
int rb_thread_flock (int fd, int op, OpenFile *fptr)
VALUE rb_file_flock (VALUE obj, VALUE operation)
void test_check (int n, int argc, VALUE *argv)
VALUE rb_f_test (int argc, VALUE *argv)
VALUE rb_stat_s_alloc (VALUE)
VALUE rb_stat_init (VALUE obj, VALUE fname)
VALUE rb_stat_init_copy (VALUE copy, VALUE orig)
VALUE rb_stat_ftype (VALUE obj)
VALUE rb_stat_d (VALUE obj)
VALUE rb_stat_p (VALUE obj)
VALUE rb_stat_l (VALUE obj)
VALUE rb_stat_S (VALUE obj)
VALUE rb_stat_b (VALUE obj)
VALUE rb_stat_c (VALUE obj)
VALUE rb_stat_owned (VALUE obj)
VALUE rb_stat_rowned (VALUE obj)
VALUE rb_stat_grpowned (VALUE obj)
VALUE rb_stat_r (VALUE obj)
VALUE rb_stat_R (VALUE obj)
VALUE rb_stat_w (VALUE obj)
VALUE rb_stat_W (VALUE obj)
VALUE rb_stat_x (VALUE obj)
VALUE rb_stat_X (VALUE obj)
VALUE rb_stat_f (VALUE obj)
VALUE rb_stat_z (VALUE obj)
VALUE rb_stat_s (VALUE obj)
VALUE rb_stat_suid (VALUE obj)
VALUE rb_stat_sgid (VALUE obj)
VALUE rb_stat_sticky (VALUE obj)
void rb_file_const (char *name, VALUE value) const
int is_absolute_path (char *path) const
int path_check_0 (VALUE fpath, int loadpath)
int fpath_check (char *path)
int rb_path_check (char *path)
int file_load_ok (char *file)
int rb_find_file_ext (VALUE *filep, const char *const *ext)
VALUE rb_find_file (VALUE path)
void define_filetest_function (char *name, func, int argc) const
void Init_File ()

Variables

VALUE rb_cFile
VALUE rb_mFileTest
VALUE rb_cStat
VALUE separator
VALUE rb_mFConst
VALUE rb_load_path


Define Documentation

#define BUFCHECK cond   ) 
 

Value:

do {\
    long bdiff = p - buf;\
    while (cond) {\
        buflen *= 2;\
    }\
    rb_str_resize(result, buflen);\
    buf = RSTRING(result)->ptr;\
    p = buf + bdiff;\
    pend = buf + buflen;\
} while (0)

Definition at line 2434 of file file.c.

Referenced by file_expand_path().

 
#define BUFINIT  ) 
 

Value:

(\
    p = buf = RSTRING(result)->ptr,\
    buflen = RSTRING(result)->len,\
    pend = p + buflen)

Definition at line 2445 of file file.c.

Referenced by file_expand_path().

#define CharNext  )     ((p) + 1)
 

Definition at line 2295 of file file.c.

#define CHECK  )     test_check((n), argc, argv)
 

Definition at line 3227 of file file.c.

Referenced by rb_f_sprintf(), and rb_f_test().

#define chompdirsep   rb_path_end
 

Definition at line 2416 of file file.c.

Referenced by file_expand_path(), rb_file_join(), rb_file_s_basename(), rb_file_s_extname(), and rmext().

#define flock fd,
op   )     rb_thread_flock(fd, op, fptr)
 

Definition at line 3136 of file file.c.

Referenced by rb_file_flock(), and rb_thread_flock().

#define isdirsep  )     ((x) == '/')
 

Definition at line 2289 of file file.c.

#define LOCK_EX   2
 

Definition at line 3097 of file file.c.

Referenced by Init_File().

#define LOCK_NB   4
 

Definition at line 3100 of file file.c.

Referenced by Init_File(), and rb_thread_flock().

#define LOCK_SH   1
 

Definition at line 3094 of file file.c.

Referenced by Init_File().

#define LOCK_UN   8
 

Definition at line 3103 of file file.c.

Referenced by Init_File().

#define MAXPATHLEN   1024
 

Definition at line 39 of file file.c.

#define nextdirsep   rb_path_next
 

Definition at line 2358 of file file.c.

Referenced by file_expand_path(), and rb_path_skip_prefix().

#define NGROUPS   32
 

Referenced by group_member().

#define S_ISBLK  )     (0)
 

Referenced by rb_file_ftype(), rb_stat_b(), and test_b().

#define S_ISCHR  )     ((m & S_IFMT) == S_IFCHR)
 

Referenced by random_seed(), rb_file_ftype(), rb_stat_c(), and test_c().

#define S_ISDIR  )     ((m & S_IFMT) == S_IFDIR)
 

#define S_ISREG  )     ((m & S_IFMT) == S_IFREG)
 

Definition at line 1214 of file file.c.

Referenced by rb_file_ftype(), rb_stat_f(), remain_size(), test_f(), and wsplit_p().

#define S_IWOTH   002
 

Referenced by path_check_0(), rb_stat_W(), and rb_stat_w().

#define S_IXUGO   (S_IXUSR | S_IXGRP | S_IXOTH)
 

Definition at line 849 of file file.c.

Referenced by eaccess().

#define skipprefix path   )     (path)
 

Definition at line 2372 of file file.c.

Referenced by file_expand_path(), rb_file_s_basename(), and rb_file_s_dirname().

#define strrdirsep   rb_path_last_separator
 

Definition at line 2396 of file file.c.

Referenced by file_expand_path(), path_check_0(), rb_file_s_basename(), rb_file_s_dirname(), and rb_file_s_extname().

#define TOLOWER  )     (ISUPPER(c) ? tolower(c) : (c))
 

Definition at line 2451 of file file.c.

Referenced by file_expand_path().


Function Documentation

long apply2files func  ,
VALUE  vargs,
void *  arg
[static]
 

Definition at line 107 of file file.c.

References args, RARRAY, SafeStringValue, StringValueCStr, and VALUE.

Referenced by rb_file_s_chmod(), rb_file_s_chown(), rb_file_s_lchown(), rb_file_s_unlink(), and rb_file_s_utime().

long apply2files void(*(const char *, void *), VALUE, void *)   )  [static]
 

void chmod_internal char *  path,
void *  mode
const [static]
 

Definition at line 1691 of file file.c.

References rb_sys_fail().

void chmod_internal const char *  ,
void * 
[static]
 

Referenced by rb_file_s_chmod().

void chown_internal char *  path,
void *  argp
const [static]
 

Definition at line 1820 of file file.c.

References args, and rb_sys_fail().

void chown_internal const char *  ,
void * 
[static]
 

Referenced by rb_file_s_chown().

void define_filetest_function char *  name,
func  ,
int  argc
const [static]
 

Definition at line 4290 of file file.c.

References name, rb_cFile, rb_define_module_function(), rb_define_singleton_method(), and rb_mFileTest.

Referenced by Init_File().

int eaccess char *  path,
int  mode
const
 

Definition at line 853 of file file.c.

References group_member(), and S_IXUGO.

VALUE file_expand_path VALUE  fname,
VALUE  dname,
VALUE  result
[static]
 

Definition at line 2457 of file file.c.

References BUFCHECK, BUFINIT, CharNext, chompdirsep, free, getenv(), is_absolute_path(), isdirsep, my_getcwd, nextdirsep, NIL_P, OBJ_TAINT, OBJ_TAINTED, Qnil, rb_eArgError, rb_raise(), RSTRING, skipprefix, skiproot(), StringValuePtr, strrdirsep, TOLOWER, and VALUE.

Referenced by rb_file_expand_path().

VALUE file_inspect_join VALUE  ary,
VALUE arg
[static]
 

Definition at line 2904 of file file.c.

References rb_file_join(), and VALUE.

Referenced by rb_file_join().

int file_load_ok char *  file  )  [static]
 

Definition at line 4140 of file file.c.

References NULL.

Referenced by rb_find_file(), and rb_find_file_ext().

int fpath_check char *  path  )  [static]
 

Definition at line 4091 of file file.c.

References path_check_0(), Qfalse, and rb_str_new2().

Referenced by rb_find_file().

struct stat* get_stat VALUE  self  )  [static]
 

Definition at line 171 of file file.c.

References Data_Get_Struct, rb_eTypeError, rb_raise(), and VALUE.

Referenced by rb_stat_atime(), rb_stat_b(), rb_stat_blksize(), rb_stat_blocks(), rb_stat_c(), rb_stat_cmp(), rb_stat_ctime(), rb_stat_d(), rb_stat_dev(), rb_stat_dev_major(), rb_stat_dev_minor(), rb_stat_f(), rb_stat_ftype(), rb_stat_gid(), rb_stat_grpowned(), rb_stat_ino(), rb_stat_l(), rb_stat_mode(), rb_stat_mtime(), rb_stat_nlink(), rb_stat_owned(), rb_stat_p(), rb_stat_R(), rb_stat_r(), rb_stat_rdev(), rb_stat_rdev_major(), rb_stat_rdev_minor(), rb_stat_rowned(), rb_stat_s(), rb_stat_S(), rb_stat_sgid(), rb_stat_size(), rb_stat_sticky(), rb_stat_suid(), rb_stat_uid(), rb_stat_W(), rb_stat_w(), rb_stat_X(), rb_stat_x(), and rb_stat_z().

int group_member GETGROUPS_T  gid  )  [static]
 

Definition at line 819 of file file.c.

References GETGROUPS_T, NGROUPS, Qfalse, and Qtrue.

Referenced by eaccess(), rb_stat_R(), rb_stat_W(), and rb_stat_X().

void Init_File void   ) 
 

Definition at line 4333 of file file.c.

References define_filetest_function(), INT2FIX, LOCK_EX, LOCK_NB, LOCK_SH, LOCK_UN, PATH_SEP, Qnil, rb_cFile, rb_cIO, rb_cObject, rb_cStat, rb_define_alloc_func(), rb_define_class(), rb_define_class_under(), rb_define_const(), rb_define_global_function(), rb_define_method(), rb_define_module(), rb_define_module_under(), rb_define_singleton_method(), rb_f_test(), rb_file_atime(), rb_file_chmod(), rb_file_chown(), rb_file_const(), rb_file_ctime(), rb_file_flock(), rb_file_lstat(), rb_file_mtime(), rb_file_path(), rb_file_s_atime(), rb_file_s_basename(), rb_file_s_chmod(), rb_file_s_chown(), rb_file_s_ctime(), rb_file_s_dirname(), rb_file_s_expand_path(), rb_file_s_extname(), rb_file_s_ftype(), rb_file_s_join(), rb_file_s_lchmod(), rb_file_s_lchown(), rb_file_s_link(), rb_file_s_lstat(), rb_file_s_mtime(), rb_file_s_readlink(), rb_file_s_rename(), rb_file_s_size(), rb_file_s_split(), rb_file_s_stat(), rb_file_s_symlink(), rb_file_s_truncate(), rb_file_s_umask(), rb_file_s_unlink(), rb_file_s_utime(), rb_file_truncate(), rb_include_module(), rb_io_stat(), rb_mComparable, rb_mFConst, rb_mFileTest, rb_obj_freeze(), rb_stat_atime(), rb_stat_b(), rb_stat_blksize(), rb_stat_blocks(), rb_stat_c(), rb_stat_cmp(), rb_stat_ctime(), rb_stat_d(), rb_stat_dev(), rb_stat_dev_major(), rb_stat_dev_minor(), rb_stat_f(), rb_stat_ftype(), rb_stat_gid(), rb_stat_grpowned(), rb_stat_init(), rb_stat_init_copy(), rb_stat_ino(), rb_stat_inspect(), rb_stat_l(), rb_stat_mode(), rb_stat_mtime(), rb_stat_nlink(), rb_stat_owned(), rb_stat_p(), rb_stat_r(), rb_stat_R(), rb_stat_rdev(), rb_stat_rdev_major(), rb_stat_rdev_minor(), rb_stat_s(), rb_stat_S(), rb_stat_s_alloc(), rb_stat_sgid(), rb_stat_size(), rb_stat_sticky(), rb_stat_suid(), rb_stat_uid(), rb_stat_w(), rb_stat_W(), rb_stat_x(), rb_stat_X(), rb_stat_z(), rb_str_new2(), separator, test_b(), test_c(), test_d(), test_e(), test_f(), test_grpowned(), test_identical(), test_l(), test_owned(), test_p(), test_r(), test_R(), test_s(), test_S(), test_sgid(), test_sticky(), test_suid(), test_w(), test_W(), test_x(), test_X(), and test_z().

Referenced by Init_IO().

int is_absolute_path char *  path  )  const [static]
 

Definition at line 4032 of file file.c.

References isdirsep.

Referenced by file_expand_path(), path_check_0(), rb_find_file(), and rb_find_file_ext().

int is_absolute_path const char *   )  [static]
 

void lchown_internal char *  path,
void *  argp
const [static]
 

Definition at line 1913 of file file.c.

References args, and rb_sys_fail().

void lchown_internal const char *  ,
void * 
[static]
 

Referenced by rb_file_s_lchown().

int path_check_0 VALUE  fpath,
int  loadpath
[static]
 

Definition at line 4049 of file file.c.

References free, is_absolute_path(), my_getcwd, rb_str_cat2(), rb_str_new2(), rb_warn(), S_ISDIR, S_IWOTH, StringValueCStr, strrdirsep, and VALUE.

Referenced by fpath_check(), and rb_path_check().

VALUE rb_f_test int  argc,
VALUE argv
[static]
 

Definition at line 3289 of file file.c.

References CHECK, cmd, NUM2CHR, Qfalse, Qnil, Qtrue, rb_eArgError, rb_raise(), rb_stat(), rb_sys_fail(), rb_time_new(), RSTRING, RTEST, strchr(), test_b(), test_c(), test_d(), test_e(), test_f(), test_grpowned(), test_identical(), test_l(), test_owned(), test_p(), test_R(), test_r(), test_rowned(), test_S(), test_s(), test_sgid(), test_sticky(), test_suid(), test_W(), test_w(), test_X(), test_x(), test_z(), and VALUE.

Referenced by Init_File().

VALUE rb_file_atime VALUE  obj  )  [static]
 

Definition at line 1583 of file file.c.

References OpenFile::f, GetOpenFile, OpenFile::path, rb_sys_fail(), rb_time_new(), and VALUE.

Referenced by Init_File().

VALUE rb_file_chmod VALUE  obj,
VALUE  vmode
[static]
 

Definition at line 1744 of file file.c.

References OpenFile::f, GetOpenFile, INT2FIX, NUM2INT, OpenFile::path, Qnil, rb_secure(), rb_sys_fail(), and VALUE.

Referenced by Init_File().

VALUE rb_file_chown VALUE  obj,
VALUE  owner,
VALUE  group
[static]
 

Definition at line 1888 of file file.c.

References OpenFile::f, GetOpenFile, INT2FIX, NIL_P, NUM2INT, OpenFile::path, Qnil, rb_secure(), rb_sys_fail(), and VALUE.

Referenced by Init_File().

void rb_file_const char *  name,
VALUE  value
const
 

Definition at line 4024 of file file.c.

References name, rb_define_const(), rb_mFConst, and VALUE.

VALUE rb_file_ctime VALUE  obj  )  [static]
 

Definition at line 1676 of file file.c.

References OpenFile::f, GetOpenFile, OpenFile::path, rb_sys_fail(), rb_time_new(), and VALUE.

Referenced by Init_File().

VALUE rb_file_expand_path VALUE  fname,
VALUE  dname
 

Definition at line 2657 of file file.c.

References file_expand_path(), MAXPATHLEN, rb_str_new(), and VALUE.

Referenced by rb_file_s_expand_path(), rb_find_file(), rb_find_file_ext(), and test_identical().

VALUE rb_file_flock VALUE  obj,
VALUE  operation
[static]
 

Definition at line 3169 of file file.c.

References OpenFile::f, flock, FMODE_WRITABLE, GetOpenFile, GetWriteFile, INT2FIX, OpenFile::mode, NUM2INT, OpenFile::path, Qfalse, rb_secure(), rb_sys_fail(), and VALUE.

Referenced by Init_File().

VALUE rb_file_ftype struct stat *  st  )  [static]
 

Definition at line 1480 of file file.c.

References rb_str_new2(), S_ISBLK, S_ISCHR, S_ISDIR, and S_ISREG.

Referenced by rb_file_s_ftype(), and rb_stat_ftype().

VALUE rb_file_join VALUE  ary,
VALUE