Ruby  3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
dir.c File Reference

(b76ad15ed0da636161de0243c547ee1e6fc95681)

#include "ruby/internal/config.h"
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "encindex.h"
#include "id.h"
#include "internal.h"
#include "internal/array.h"
#include "internal/dir.h"
#include "internal/encoding.h"
#include "internal/error.h"
#include "internal/file.h"
#include "internal/gc.h"
#include "internal/io.h"
#include "internal/vm.h"
#include "ruby/encoding.h"
#include "ruby/ruby.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "builtin.h"
#include "dir.rbinc"
Include dependency graph for dir.c:

Go to the source code of this file.

Data Structures

struct  dir_data
 
struct  chdir_data
 
struct  mkdir_arg
 
struct  warning_args
 
struct  ruby_glob_funcs_t
 
struct  opendir_at_arg
 
struct  glob_pattern
 
struct  glob_args
 
struct  glob_error_args
 
struct  rb_dirent
 
struct  push_glob_args
 
struct  dirent_brace_args
 
union  ruby_glob_entries_t
 
struct  push_glob0_args
 
struct  brace_args
 

Macros

#define O_CLOEXEC   0
 
#define USE_OPENDIR_AT   0
 
#define dirent   direct
 
#define NAMLEN(dirent)   (dirent)->d_namlen
 
#define HAVE_DIRENT_NAMLEN   1
 
#define USE_NAME_ON_FS_REAL_BASENAME
 
#define USE_NAME_ON_FS_BY_FNMATCH
 
#define USE_NAME_ON_FS   0
 
#define NORMALIZE_UTF8PATH   0
 
#define AT_FDCWD   -1
 
#define vm_initialized   rb_cThread
 
#define IS_WIN32   0
 
#define IF_NORMALIZE_UTF8PATH(something)   /* nothing */
 
#define IFTODT(m)   (((m) & S_IFMT) / ((~S_IFMT & (S_IFMT-1)) + 1))
 
#define FNM_NOESCAPE   0x01
 
#define FNM_PATHNAME   0x02
 
#define FNM_DOTMATCH   0x04
 
#define FNM_CASEFOLD   0x08
 
#define FNM_EXTGLOB   0x10
 
#define FNM_SYSCASE   0
 
#define FNM_SHORTNAME   0
 
#define FNM_GLOB_NOSORT   0x40
 
#define FNM_GLOB_SKIPDOT   0x80
 
#define FNM_NOMATCH   1
 
#define FNM_ERROR   2
 
#define Next(p, e, enc)   ((p)+ rb_enc_mbclen((p), (e), (enc)))
 
#define Inc(p, e, enc)   ((p) = Next((p), (e), (enc)))
 
#define UNESCAPE(p)   (escape && *(p) == '\\' ? (p) + 1 : (p))
 
#define ISEND(p)   (!*(p) || (pathname && *(p) == '/'))
 
#define RETURN(val)   return *pcur = p, *scur = s, (val);
 
#define GetDIR(obj, dirp)   ((dirp) = dir_check(obj))
 
#define dir_fileno   rb_f_notimplement
 
#define READDIR(dir, enc)   readdir((dir))
 
#define dir_tell   rb_f_notimplement
 
#define dir_seek   rb_f_notimplement
 
#define dir_set_pos   rb_f_notimplement
 
#define RUBY_UNTYPED_DATA_WARNING   0
 
#define dir_s_chroot   rb_f_notimplement
 
#define sys_enc_warning_in(func, mesg, enc)   sys_enc_warning(mesg, enc)
 
#define GLOB_VERBOSE   (1U << (sizeof(int) * CHAR_BIT - 1))
 
#define sys_warning(val, enc)   ((flags & GLOB_VERBOSE) ? sys_enc_warning_in(RUBY_FUNCTION_NAME_STRING, (val), (enc)) :(void)0)
 
#define GLOB_ALLOC(type)   ((type *)malloc(sizeof(type)))
 
#define GLOB_ALLOC_N(type, n)   ((type *)glob_alloc_n(sizeof(type), n))
 
#define GLOB_REALLOC(ptr, size)   realloc((ptr), (size))
 
#define GLOB_REALLOC_N(ptr, n)   glob_realloc_n(ptr, sizeof(*(ptr)), n)
 
#define GLOB_FREE(ptr)   free(ptr)
 
#define GLOB_JUMP_TAG(status)   (((status) == -1) ? rb_memerror() : rb_jump_tag(status))
 
#define STAT(p, s)   stat((p), (s))
 
#define do_lstat   do_stat
 
#define S_ISDIR(m)   (((m) & S_IFMT) == S_IFDIR)
 
#define S_ISLNK(m)   (0)
 
#define glob_call_func(func, path, arg, enc)   (*(func))((path), (arg), (void *)(enc))
 

Typedefs

typedef int ruby_glob_errfunc(const char *, VALUE, const void *, int)
 
typedef struct rb_dirent rb_dirent_t
 

Enumerations

enum  rb_pathtype_t {
  path_exist, path_directory = IFTODT(S_IFDIR), path_regular = IFTODT(S_IFREG), path_symlink = IFTODT(S_IFLNK),
  path_noent = -1, path_unknown = -2
}
 
enum  glob_pattern_type {
  PLAIN, ALPHA, BRACE, MAGICAL,
  RECURSIVE, MATCH_ALL, MATCH_DIR
}
 

Functions

char * getenv ()
 
char * strchr (char *, char)
 
VALUE rb_dir_getwd_ospath (void)
 
VALUE rb_dir_getwd (void)
 
int ruby_glob (const char *path, int flags, ruby_glob_func *func, VALUE arg)
 
void rb_glob (const char *path, void(*func)(const char *, VALUE, void *), VALUE arg)
 
int ruby_brace_glob_with_enc (const char *str, int flags, ruby_glob_func *func, VALUE arg, rb_encoding *enc)
 
int ruby_brace_glob (const char *str, int flags, ruby_glob_func *func, VALUE arg)
 
void Init_Dir (void)
 

Variables

VALUE rb_cDir
 

Macro Definition Documentation

◆ AT_FDCWD

#define AT_FDCWD   -1

Definition at line 123 of file dir.c.

◆ dir_fileno

#define dir_fileno   rb_f_notimplement

Definition at line 677 of file dir.c.

◆ dir_s_chroot

#define dir_s_chroot   rb_f_notimplement

Definition at line 1196 of file dir.c.

◆ dir_seek

#define dir_seek   rb_f_notimplement

Definition at line 891 of file dir.c.

◆ dir_set_pos

#define dir_set_pos   rb_f_notimplement

Definition at line 915 of file dir.c.

◆ dir_tell

#define dir_tell   rb_f_notimplement

Definition at line 862 of file dir.c.

◆ dirent

#define dirent   direct

Definition at line 50 of file dir.c.

◆ do_lstat

#define do_lstat   do_stat

Definition at line 1419 of file dir.c.

◆ FNM_CASEFOLD

#define FNM_CASEFOLD   0x08

Definition at line 212 of file dir.c.

◆ FNM_DOTMATCH

#define FNM_DOTMATCH   0x04

Definition at line 211 of file dir.c.

◆ FNM_ERROR

#define FNM_ERROR   2

Definition at line 228 of file dir.c.

◆ FNM_EXTGLOB

#define FNM_EXTGLOB   0x10

Definition at line 213 of file dir.c.

◆ FNM_GLOB_NOSORT

#define FNM_GLOB_NOSORT   0x40

Definition at line 224 of file dir.c.

◆ FNM_GLOB_SKIPDOT

#define FNM_GLOB_SKIPDOT   0x80

Definition at line 225 of file dir.c.

◆ FNM_NOESCAPE

#define FNM_NOESCAPE   0x01

Definition at line 209 of file dir.c.

◆ FNM_NOMATCH

#define FNM_NOMATCH   1

Definition at line 227 of file dir.c.

◆ FNM_PATHNAME

#define FNM_PATHNAME   0x02

Definition at line 210 of file dir.c.

◆ FNM_SHORTNAME

#define FNM_SHORTNAME   0

Definition at line 222 of file dir.c.

◆ FNM_SYSCASE

#define FNM_SYSCASE   0

Definition at line 217 of file dir.c.

◆ GetDIR

#define GetDIR (   obj,
  dirp 
)    ((dirp) = dir_check(obj))

Definition at line 610 of file dir.c.

◆ GLOB_ALLOC

#define GLOB_ALLOC (   type)    ((type *)malloc(sizeof(type)))

Definition at line 1345 of file dir.c.

◆ GLOB_ALLOC_N

#define GLOB_ALLOC_N (   type,
 
)    ((type *)glob_alloc_n(sizeof(type), n))

Definition at line 1346 of file dir.c.

◆ glob_call_func

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

Definition at line 1936 of file dir.c.

◆ GLOB_FREE

#define GLOB_FREE (   ptr)    free(ptr)

Definition at line 1349 of file dir.c.

◆ GLOB_JUMP_TAG

#define GLOB_JUMP_TAG (   status)    (((status) == -1) ? rb_memerror() : rb_jump_tag(status))

Definition at line 1350 of file dir.c.

◆ GLOB_REALLOC

#define GLOB_REALLOC (   ptr,
  size 
)    realloc((ptr), (size))

Definition at line 1347 of file dir.c.

◆ GLOB_REALLOC_N

#define GLOB_REALLOC_N (   ptr,
 
)    glob_realloc_n(ptr, sizeof(*(ptr)), n)

Definition at line 1348 of file dir.c.

◆ GLOB_VERBOSE

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

Definition at line 1317 of file dir.c.

◆ HAVE_DIRENT_NAMLEN

#define HAVE_DIRENT_NAMLEN   1

Definition at line 52 of file dir.c.

◆ IF_NORMALIZE_UTF8PATH

#define IF_NORMALIZE_UTF8PATH (   something)    /* nothing */

Definition at line 186 of file dir.c.

◆ IFTODT

#define IFTODT (   m)    (((m) & S_IFMT) / ((~S_IFMT & (S_IFMT-1)) + 1))

Definition at line 190 of file dir.c.

◆ Inc

#define Inc (   p,
  e,
  enc 
)    ((p) = Next((p), (e), (enc)))

Definition at line 231 of file dir.c.

◆ IS_WIN32

#define IS_WIN32   0

Definition at line 141 of file dir.c.

◆ ISEND

#define ISEND (   p)    (!*(p) || (pathname && *(p) == '/'))

Definition at line 308 of file dir.c.

◆ NAMLEN

#define NAMLEN (   dirent)    (dirent)->d_namlen

Definition at line 51 of file dir.c.

◆ Next

#define Next (   p,
  e,
  enc 
)    ((p)+ rb_enc_mbclen((p), (e), (enc)))

Definition at line 230 of file dir.c.

◆ NORMALIZE_UTF8PATH

#define NORMALIZE_UTF8PATH   0

Definition at line 100 of file dir.c.

◆ O_CLOEXEC

#define O_CLOEXEC   0

Definition at line 26 of file dir.c.

◆ READDIR

#define READDIR (   dir,
  enc 
)    readdir((dir))

Definition at line 715 of file dir.c.

◆ RETURN

#define RETURN (   val)    return *pcur = p, *scur = s, (val);

Definition at line 309 of file dir.c.

◆ RUBY_UNTYPED_DATA_WARNING

#define RUBY_UNTYPED_DATA_WARNING   0

◆ S_ISDIR

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

Definition at line 1916 of file dir.c.

◆ S_ISLNK

#define S_ISLNK (   m)    (0)

Definition at line 1921 of file dir.c.

◆ STAT

#define STAT (   p,
 
)    stat((p), (s))

Definition at line 1368 of file dir.c.

◆ sys_enc_warning_in

#define sys_enc_warning_in (   func,
  mesg,
  enc 
)    sys_enc_warning(mesg, enc)

Definition at line 1290 of file dir.c.

◆ sys_warning

#define sys_warning (   val,
  enc 
)    ((flags & GLOB_VERBOSE) ? sys_enc_warning_in(RUBY_FUNCTION_NAME_STRING, (val), (enc)) :(void)0)

Definition at line 1318 of file dir.c.

◆ UNESCAPE

#define UNESCAPE (   p)    (escape && *(p) == '\\' ? (p) + 1 : (p))

Definition at line 307 of file dir.c.

◆ USE_NAME_ON_FS

#define USE_NAME_ON_FS   0

Definition at line 91 of file dir.c.

◆ USE_NAME_ON_FS_BY_FNMATCH

#define USE_NAME_ON_FS_BY_FNMATCH
Value:
2 /* select the matching
* basename by fnmatch */

Definition at line 80 of file dir.c.

◆ USE_NAME_ON_FS_REAL_BASENAME

#define USE_NAME_ON_FS_REAL_BASENAME
Value:
1 /* platform dependent APIs to
* get real basenames */

Definition at line 79 of file dir.c.

◆ USE_OPENDIR_AT

#define USE_OPENDIR_AT   0

Definition at line 34 of file dir.c.

◆ vm_initialized

#define vm_initialized   rb_cThread

Definition at line 126 of file dir.c.

Typedef Documentation

◆ rb_dirent_t

typedef struct rb_dirent rb_dirent_t

◆ ruby_glob_errfunc

typedef int ruby_glob_errfunc(const char *, VALUE, const void *, int)

Definition at line 1371 of file dir.c.

Enumeration Type Documentation

◆ glob_pattern_type

Enumerator
PLAIN 
ALPHA 
BRACE 
MAGICAL 
RECURSIVE 
MATCH_ALL 
MATCH_DIR 

Definition at line 1533 of file dir.c.

◆ rb_pathtype_t

Enumerator
path_exist 
path_directory 
path_regular 
path_symlink 
path_noent 
path_unknown 

Definition at line 193 of file dir.c.

Function Documentation

◆ getenv()

char* getenv ( )

◆ Init_Dir()

void Init_Dir ( void  )

◆ rb_dir_getwd()

VALUE rb_dir_getwd ( void  )

◆ rb_dir_getwd_ospath()

VALUE rb_dir_getwd_ospath ( void  )

Definition at line 1095 of file dir.c.

Referenced by rb_dir_getwd().

◆ rb_glob()

void rb_glob ( const char *  path,
void(*)(const char *, VALUE, void *)  func,
VALUE  arg 
)

Definition at line 2719 of file dir.c.

References glob_args::enc, glob_args::func, rb_ascii8bit_encoding(), and glob_args::value.

◆ ruby_brace_glob()

int ruby_brace_glob ( const char *  str,
int  flags,
ruby_glob_func func,
VALUE  arg 
)

Definition at line 2834 of file dir.c.

References brace_args::flags, rb_ascii8bit_encoding(), ruby_brace_glob_with_enc(), and str.

◆ ruby_brace_glob_with_enc()

int ruby_brace_glob_with_enc ( const char *  str,
int  flags,
ruby_glob_func func,
VALUE  arg,
rb_encoding enc 
)

◆ ruby_glob()

int ruby_glob ( const char *  path,
int  flags,
ruby_glob_func func,
VALUE  arg 
)

◆ strchr()

char* strchr ( char *  ,
char   
)

Variable Documentation

◆ rb_cDir

VALUE rb_cDir

Definition at line 453 of file dir.c.

Referenced by Init_Dir().