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

dir.c File Reference

#include "ruby.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <ctype.h>
#include "util.h"

Go to the source code of this file.

Data Structures

struct  chdir_data
struct  dir_data
struct  glob_args

Defines

#define NAMLEN(dirent)   strlen((dirent)->d_name)
#define FNM_NOESCAPE   0x01
#define FNM_PATHNAME   0x02
#define FNM_DOTMATCH   0x04
#define FNM_CASEFOLD   0x08
#define FNM_NOMATCH   1
#define FNM_ERROR   2
#define downcase(c)   (nocase && ISUPPER(c) ? tolower(c) : (c))
#define CharNext(p)   ((p) + 1)
#define isdirsep(c)   ((c) == '/')
#define ISDIRSEP(c)   (pathname && isdirsep(c))
#define PERIOD(s)
#define GetDIR(obj, dirp)
#define GLOB_VERBOSE   (1 << (sizeof(int) * CHAR_BIT - 1))
#define sys_warning(val)   ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)(val), 0))
#define S_ISDIR(m)   ((m & S_IFMT) == S_IFDIR)
#define glob_call_func(func, path, arg)   (*func)(path, arg)
#define BASE   (*base && !(isdirsep(*base) && !base[1]))
#define isdelim(c)   ((c)=='\0')

Functions

char * range (char *pat, int test, int flags) const
int fnmatch (char *pat, const char *string, int flags) const
void free_dir (struct dir_data *dir)
VALUE dir_close (VALUE)
VALUE dir_s_alloc (VALUE)
VALUE dir_initialize (VALUE dir, VALUE dirname)
VALUE dir_s_open (VALUE klass, VALUE dirname)
void dir_closed ()
VALUE dir_path (VALUE dir)
VALUE dir_read (VALUE dir)
VALUE dir_each (VALUE dir)
VALUE dir_tell (VALUE dir)
VALUE dir_seek (VALUE dir, VALUE pos)
VALUE dir_set_pos (VALUE dir, VALUE pos)
VALUE dir_rewind (VALUE dir)
void dir_chdir (VALUE path)
VALUE chdir_yield (struct chdir_data *args)
VALUE chdir_restore (struct chdir_data *args)
VALUE dir_s_chdir (int argc, VALUE *argv, VALUE obj)
VALUE dir_s_getwd (VALUE dir)
void check_dirname (volatile VALUE *)
void check_dirname (VALUE *dir) volatile
VALUE dir_s_chroot (VALUE dir, VALUE path)
VALUE dir_s_mkdir (int argc, VALUE *argv, VALUE obj)
VALUE dir_s_rmdir (VALUE obj, VALUE dir)
int has_magic (char *s, char *send, int flags) const
char * extract_path (char *p, char *pend) const
char * extract_elem (char *path) const
void remove_backslashes (char *p)
VALUE glob_func_caller (VALUE)
int glob_helper (const char *path, const char *sub, int flags, int(*func(const char *, VALUE), VALUE arg))
int glob_helper (char *path, const char *sub, int flags, func, VALUE arg) const
int ruby_glob (char *path, int flags, func, VALUE arg) const
int ruby_globi (char *path, int flags, func, VALUE arg) const
int rb_glob_caller (const char *, VALUE)
int rb_glob_caller (char *path, VALUE a) const
int rb_glob2 (char *path, int flags, func, VALUE arg) const
void rb_glob (char *path, func, VALUE arg) const
void rb_globi (char *path, func, VALUE arg) const
void push_pattern (char *path, VALUE ary) const
int push_globs (VALUE ary, const char *s, int flags)
int push_braces (VALUE ary, const char *str, int flags)
VALUE rb_push_glob (VALUE str, int flags)
VALUE dir_s_aref (VALUE obj, VALUE str)
VALUE dir_s_glob (int argc, VALUE *argv, VALUE obj)
VALUE dir_open_dir (VALUE path)
VALUE dir_foreach (VALUE io, VALUE dirname)
VALUE dir_entries (VALUE io, VALUE dirname)
VALUE file_s_fnmatch (int argc, VALUE *argv, VALUE obj)
void Init_Dir ()

Variables

VALUE rb_cDir
int chdir_blocking = 0
VALUE chdir_thread = Qnil


Define Documentation

#define BASE   (*base && !(isdirsep(*base) && !base[1]))
 

Referenced by glob_helper().

#define CharNext  )     ((p) + 1)
 

Definition at line 84 of file dir.c.

Referenced by file_expand_path(), rb_path_end(), rb_path_last_separator(), and rb_path_next().

#define downcase  )     (nocase && ISUPPER(c) ? tolower(c) : (c))
 

Definition at line 78 of file dir.c.

Referenced by fnmatch(), and range().

#define FNM_CASEFOLD   0x08
 

Definition at line 73 of file dir.c.

Referenced by fnmatch(), Init_Dir(), and range().

#define FNM_DOTMATCH   0x04
 

Definition at line 72 of file dir.c.

Referenced by fnmatch(), and Init_Dir().

#define FNM_ERROR   2
 

Definition at line 76 of file dir.c.

#define FNM_NOESCAPE   0x01
 

Definition at line 70 of file dir.c.

Referenced by fnmatch(), glob_helper(), has_magic(), Init_Dir(), and range().

#define FNM_NOMATCH   1
 

Definition at line 75 of file dir.c.

Referenced by fnmatch().

#define FNM_PATHNAME   0x02
 

Definition at line 71 of file dir.c.

Referenced by fnmatch(), and Init_Dir().

#define GetDIR obj,
dirp   ) 
 

Value:

do {\
    Data_Get_Struct(obj, struct dir_data, dirp);\
    if (dirp->dir == NULL) dir_closed();\
} while (0)

Definition at line 328 of file dir.c.

Referenced by dir_close(), dir_each(), dir_path(), dir_read(), dir_rewind(), dir_seek(), and dir_tell().

#define glob_call_func func,
path,
arg   )     (*func)(path, arg)
 

Definition at line 902 of file dir.c.

Referenced by glob_helper().

#define GLOB_VERBOSE   (1 << (sizeof(int) * CHAR_BIT - 1))
 

Definition at line 789 of file dir.c.

#define isdelim  )     ((c)=='\0')
 

Definition at line 1232 of file dir.c.

#define ISDIRSEP  )     (pathname && isdirsep(c))
 

Definition at line 131 of file dir.c.

Referenced by fnmatch().

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

Definition at line 91 of file dir.c.

Referenced by file_expand_path(), fnmatch(), is_absolute_path(), rb_file_join(), rb_file_s_basename(), rb_file_s_dirname(), rb_path_end(), rb_path_last_separator(), rb_path_next(), rb_path_skip_prefix(), and skiproot().

#define NAMLEN dirent   )     strlen((dirent)->d_name)
 

Definition at line 26 of file dir.c.

Referenced by dir_each(), dir_read(), and glob_helper().

#define PERIOD  ) 
 

Value:

(period && *(s) == '.' && \
                  ((s) == string || ISDIRSEP((s)[-1])))

Definition at line 132 of file dir.c.

Referenced by fnmatch().

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

Definition at line 881 of file dir.c.

Referenced by dln_find_1(), glob_helper(), path_check_0(), rb_file_ftype(), rb_stat_d(), and test_d().

#define sys_warning val   )     ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)(val), 0))
 

Definition at line 790 of file dir.c.

Referenced by glob_helper().


Function Documentation

VALUE chdir_restore struct chdir_data args  )  [static]
 

Definition at line 575 of file dir.c.

References args, chdir_blocking, chdir_thread, dir_chdir(), and Qnil.

Referenced by dir_s_chdir().

VALUE chdir_yield struct chdir_data args  )  [static]
 

Definition at line 563 of file dir.c.

References args, chdir_blocking, chdir_thread, dir_chdir(), Qnil, Qtrue, rb_thread_current(), and rb_yield().

Referenced by dir_s_chdir().

void check_dirname VALUE dir  )  volatile [static]
 

Definition at line 694 of file dir.c.

References rb_path_end(), rb_path_skip_prefix(), rb_secure(), rb_str_new(), RSTRING, SafeStringValue, and VALUE.

Referenced by dir_s_chroot(), dir_s_mkdir(), and dir_s_rmdir().

void check_dirname volatile VALUE  )  [static]
 

void dir_chdir VALUE  path  )  [static]
 

Definition at line 547 of file dir.c.

References rb_sys_fail(), RSTRING, and VALUE.

Referenced by chdir_restore(), chdir_yield(), and dir_s_chdir().

VALUE dir_close VALUE   )  [static]
 

Definition at line 534 of file dir.c.

References GetDIR, NULL, Qnil, and VALUE.

Referenced by dir_s_open().

void dir_closed  )  [static]
 

Definition at line 323 of file dir.c.

References rb_eIOError, and rb_raise().

Referenced by dir_each().

VALUE dir_each VALUE  dir  )  [static]
 

Definition at line 405 of file dir.c.

References dir_closed(), GetDIR, NAMLEN, NULL, rb_tainted_str_new(), rb_yield(), and VALUE.

VALUE dir_entries VALUE  io,
VALUE  dirname
[static]
 

Definition at line 1425 of file dir.c.

VALUE dir_foreach VALUE  io,
VALUE  dirname
[static]
 

Definition at line 1403 of file dir.c.

References main().

VALUE dir_initialize VALUE  dir,
VALUE  dirname
[static]
 

Definition at line 269 of file dir.c.

References Data_Get_Struct, free, NULL, rb_gc(), rb_sys_fail(), RSTRING, SafeStringValue, strdup, and VALUE.

Referenced by dir_s_open().

VALUE dir_open_dir VALUE  path  )  [static]
 

Definition at line 1371 of file dir.c.

VALUE dir_path VALUE  dir  )  [static]
 

Definition at line 343 of file dir.c.

References GetDIR, Qnil, rb_str_new2(), and VALUE.

VALUE dir_read VALUE  dir  )  [static]
 

Definition at line 366 of file dir.c.

References GetDIR, NAMLEN, Qnil, rb_sys_fail(), rb_tainted_str_new(), and VALUE.

VALUE dir_rewind VALUE  dir  )  [static]
 

Definition at line 513 of file dir.c.

References GetDIR, and VALUE.

VALUE dir_s_alloc VALUE   )  [static]
 

Definition at line 250 of file dir.c.

References Data_Make_Struct, free_dir(), NULL, and VALUE.

VALUE dir_s_aref VALUE  obj,
VALUE  str
[static]
 

Definition at line 1289 of file dir.c.

References main().

VALUE dir_s_chdir int  argc,
VALUE argv,
VALUE  obj
[static]
 

Definition at line 627 of file dir.c.

References args, chdir_blocking, chdir_restore(), chdir_thread, chdir_yield(), dir_chdir(), free, getenv(), INT2FIX, my_getcwd, Qfalse, Qnil, rb_block_given_p(), rb_eArgError, rb_ensure(), rb_raise(), rb_scan_args(), rb_secure(), rb_str_new2(), rb_tainted_str_new2(), rb_thread_current(), rb_warn(), SafeStringValue, and VALUE.

VALUE dir_s_chroot VALUE  dir,
VALUE  path
[static]
 

Definition at line 717 of file dir.c.

References check_dirname(), INT2FIX, Qnil, rb_notimplement(), rb_sys_fail(), RSTRING, and VALUE.

VALUE dir_s_getwd VALUE  dir  )  [static]
 

Definition at line 678 of file dir.c.

References free, my_getcwd, rb_secure(), rb_tainted_str_new2(), and VALUE.

VALUE dir_s_glob int  argc,
VALUE argv,
VALUE  obj
[static]
 

Definition at line 1354 of file dir.c.

VALUE dir_s_mkdir int  argc,
VALUE argv,
VALUE  obj
[static]
 

Definition at line 747 of file dir.c.

References check_dirname(), INT2FIX, NUM2INT, rb_scan_args(), rb_sys_fail(), RSTRING, and VALUE.

VALUE dir_s_open VALUE  klass,
VALUE  dirname
[static]
 

Definition at line 308 of file dir.c.

References Data_Make_Struct, dir_close(), dir_initialize(), free_dir(), rb_block_given_p(), rb_ensure(), rb_yield(), and VALUE.

VALUE dir_s_rmdir VALUE  obj,
VALUE  dir
[static]
 

Definition at line 779 of file dir.c.

References check_dirname(), INT2FIX, rb_sys_fail(), RSTRING, and VALUE.

VALUE dir_seek VALUE  dir,
VALUE  pos
[static]
 

Definition at line 464 of file dir.c.

References GetDIR, NUM2OFFT, rb_notimplement(), and VALUE.

Referenced by dir_set_pos().

VALUE dir_set_pos VALUE  dir,
VALUE  pos
[static]
 

Definition at line 494 of file dir.c.

References dir_seek(), and VALUE.

VALUE dir_tell VALUE  dir  )  [static]
 

Definition at line 434 of file dir.c.

References GetDIR, rb_int2inum(), rb_notimplement(), and VALUE.

char* extract_elem char *  path  )  const [static]
 

Definition at line 853 of file dir.c.

References extract_path(), and strchr().

Referenced by glob_helper().

char* extract_path char *  p,
char *  pend
const [static]
 

Definition at line 829 of file dir.c.

References alloc, and ALLOC_N.

Referenced by extract_elem(), and glob_helper().

VALUE file_s_fnmatch int  argc,
VALUE argv,
VALUE  obj
[static]
 

Definition at line 1493 of file dir.c.

int fnmatch char *  pat,
const char *  string,
int  flags
const [static]
 

Definition at line 135 of file dir.c.

References downcase, FNM_CASEFOLD, FNM_DOTMATCH, FNM_NOESCAPE, FNM_NOMATCH, FNM_PATHNAME, isdirsep, ISDIRSEP, NULL, PERIOD, range(), rb_path_next(), and strchr().

Referenced by glob_helper(), and Init_Dir().

void free_dir struct dir_data dir  )  [static]
 

Definition at line 236 of file dir.c.

References free.

Referenced by dir_s_alloc(), and dir_s_open().

VALUE glob_func_caller VALUE   )  [static]
 

Definition at line 893 of file dir.c.

References args, Qnil, and VALUE.

int glob_helper char *  path,
const char *  sub,
int  flags,
func  ,
VALUE  arg
const [static]
 

Definition at line 907 of file dir.c.

References BASE, extract_elem(), extract_path(), FNM_NOESCAPE, fnmatch(), free, glob_call_func, has_magic(), NAMLEN, NULL, REALLOC_N, remove_backslashes(), S_ISDIR, strchr(), strdup, sys_warning, TRUE, VALUE, and xfree.

int glob_helper const char *  path,
const char *  sub,
int  flags,
int(**,  VALUE,
VALUE  arg
[static]
 

int has_magic char *  s,
char *  send,
int  flags
const [static]
 

Definition at line 795 of file dir.c.

References FNM_NOESCAPE, Qfalse, and Qtrue.

Referenced by glob_helper().

void Init_Dir void   ) 
 

Definition at line 1528 of file dir.c.

References FNM_CASEFOLD, FNM_DOTMATCH, FNM_NOESCAPE, FNM_PATHNAME, and fnmatch().

Referenced by rb_call_inits().

int push_braces VALUE  ary,
const char *  str,
int  flags
[static]
 

Definition at line 1171 of file dir.c.

int push_globs VALUE  ary,
const char *  s,
int  flags
[static]
 

Definition at line 1162 of file dir.c.

void push_pattern char *  path,
VALUE  ary
const [static]
 

Definition at line 1154 of file dir.c.

char* range char *  pat,
int  test,
int  flags
const [static]
 

Definition at line 95 of file dir.c.

References downcase, FNM_CASEFOLD, FNM_NOESCAPE, and NULL.

Referenced by fnmatch().

void rb_glob char *  path,
func  ,
VALUE  arg
const
 

Definition at line 1134 of file dir.c.

int rb_glob2 char *  path,
int  flags,
func  ,
VALUE  arg
const [static]
 

Definition at line 1119 of file dir.c.

int rb_glob_caller char *  path,
VALUE  a
const [static]
 

Definition at line 1106 of file dir.c.

int rb_glob_caller const char *  ,
VALUE 
[static]
 

void rb_globi char *  path,
func  ,
VALUE  arg
const
 

Definition at line 1144 of file dir.c.

VALUE rb_push_glob VALUE  str,
int  flags
[static]
 

Definition at line 1235 of file dir.c.

void remove_backslashes char *  p  )  [static]
 

Definition at line 865 of file dir.c.

Referenced by glob_helper().

int ruby_glob char *  path,
int  flags,
func  ,
VALUE  arg
const
 

Definition at line 1084 of file dir.c.

int ruby_globi char *  path,
int  flags,
func  ,
VALUE  arg
const
 

Definition at line 1094 of file dir.c.


Variable Documentation

int chdir_blocking = 0 [static]
 

Definition at line 554 of file dir.c.

Referenced by chdir_restore(), chdir_yield(), and dir_s_chdir().

VALUE chdir_thread = Qnil [static]
 

Definition at line 555 of file dir.c.

Referenced by chdir_restore(), chdir_yield(), and dir_s_chdir().

VALUE rb_cDir
 

Definition at line 228 of file dir.c.


Generated on Wed Jan 18 23:32:08 2006 for Ruby by doxygen 1.3.5