19 #include <sys/cygwin.h> 23 #include <CoreFoundation/CFString.h> 35 #ifdef HAVE_SYS_TIME_H 36 # include <sys/time.h> 39 #ifdef HAVE_SYS_FILE_H 40 # include <sys/file.h> 45 #ifdef HAVE_SYS_PARAM_H 46 # include <sys/param.h> 49 # define MAXPATHLEN 1024 58 #elif defined HAVE_SYS_UTIME_H 59 #include <sys/utime.h> 66 #ifdef HAVE_SYS_SYSMACROS_H 67 #include <sys/sysmacros.h> 70 #include <sys/types.h> 73 #if defined(__native_client__) 74 # if defined(NACL_NEWLIB) 79 # undef HAVE_UTIMENSAT 83 #ifdef HAVE_SYS_MKDEV_H 84 #include <sys/mkdev.h> 87 #if defined(HAVE_FCNTL_H) 91 #if defined(HAVE_SYS_TIME_H) 95 #if !defined HAVE_LSTAT && !defined lstat 102 #define STAT(p, s) rb_w32_ustati64((p), (s)) 104 #define lstat(p, s) rb_w32_ulstati64((p), (s)) 106 #define access(p, m) rb_w32_uaccess((p), (m)) 108 #define truncate(p, n) rb_w32_utruncate((p), (n)) 110 #define chmod(p, m) rb_w32_uchmod((p), (m)) 112 #define chown(p, o, g) rb_w32_uchown((p), (o), (g)) 114 #define lchown(p, o, g) rb_w32_ulchown((p), (o), (g)) 116 #define utime(p, t) rb_w32_uutime((p), (t)) 118 #define link(f, t) rb_w32_ulink((f), (t)) 120 #define unlink(p) rb_w32_uunlink(p) 122 #define rename(f, t) rb_w32_urename((f), (t)) 124 #define symlink(s, l) rb_w32_usymlink((s), (l)) 126 #define STAT(p, s) stat((p), (s)) 133 #define insecure_obj_p(obj, level) ((level) > 0 && OBJ_TAINTED(obj)) 225 #if defined _WIN32 || defined __APPLE__ 242 # define NORMALIZE_UTF8PATH 1 244 rb_str_append_normalized_ospath(
VALUE str,
const char *ptr,
long len)
248 CFStringRef s = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
249 (
const UInt8 *)ptr, len,
250 kCFStringEncodingUTF8,
FALSE,
252 CFMutableStringRef m = CFStringCreateMutableCopy(kCFAllocatorDefault, len, s);
255 CFStringNormalize(m, kCFStringNormalizationFormC);
256 all = CFRangeMake(0, CFStringGetLength(m));
257 CFStringGetBytes(m, all, kCFStringEncodingUTF8,
'?',
FALSE,
NULL, 0, &buflen);
259 CFStringGetBytes(m, all, kCFStringEncodingUTF8,
'?',
FALSE,
260 (UInt8 *)(
RSTRING_PTR(str) + oldlen), buflen, &buflen);
268 rb_str_normalize_ospath(
const char *ptr,
long len)
271 const char *e = ptr +
len;
282 static const char invalid[3] =
"\xEF\xBF\xBD";
283 rb_str_append_normalized_ospath(str, p1, p-p1);
291 if ((0x2000 <= c && c <= 0x2FFF) || (0xF900 <= c && c <= 0xFAFF) ||
292 (0x2F800 <= c && c <= 0x2FAFF)) {
294 rb_str_append_normalized_ospath(str, p1, p-p1);
305 rb_str_append_normalized_ospath(str, p1, p-p1);
315 if (p+3 > e)
return 0;
316 switch ((
unsigned char)*p) {
318 switch ((
unsigned char)p[1]) {
320 c = (
unsigned char)p[2];
322 if (c >= 0x8c && c <= 0x8f)
return 3;
324 if (c >= 0xaa && c <= 0xae)
return 3;
327 c = (
unsigned char)p[2];
329 if (c >= 0xaa && c <= 0xaf)
return 3;
335 if ((
unsigned char)p[1] == 0xbb &&
336 (
unsigned char)p[2] == 0xbf)
343 # define NORMALIZE_UTF8PATH 0 346 #define apply2args(n) (rb_check_arity(argc, n, UNLIMITED_ARGUMENTS), argc-=n) 354 for (i=0; i<
argc; i++) {
359 (*func)(s,
path, arg);
392 return sizeof(
struct stat);
404 struct stat *nst = 0;
430 static struct timespec stat_mtimespec(struct stat *st);
464 #define ST2UINT(val) ((val) & ~(~1UL << (sizeof(val) * CHAR_BIT - 1))) 467 # define NUM2DEVT(v) NUM2UINT(v) 470 # define DEVT2NUM(v) UINT2NUM(v) 472 #ifndef PRI_DEVT_PREFIX 473 # define PRI_DEVT_PREFIX "" 549 unsigned short *p2 = (
unsigned short *)st;
550 unsigned int *p4 = (
unsigned int *)st;
558 #elif SIZEOF_STRUCT_STAT_ST_INO > SIZEOF_LONG 559 return ULL2NUM(
get_stat(
self)->st_ino);
649 #ifdef HAVE_STRUCT_STAT_ST_RDEV 670 #if defined(HAVE_STRUCT_STAT_ST_RDEV) && defined(major) 691 #if defined(HAVE_STRUCT_STAT_ST_RDEV) && defined(minor) 727 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE 748 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS 749 # if SIZEOF_STRUCT_STAT_ST_BLOCKS > SIZEOF_LONG 750 return ULL2NUM(
get_stat(
self)->st_blocks);
764 #if defined(HAVE_STRUCT_STAT_ST_ATIM) 765 ts.
tv_nsec = st->st_atim.tv_nsec;
766 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC) 767 ts.
tv_nsec = st->st_atimespec.tv_nsec;
768 #elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC) 769 ts.
tv_nsec = (long)st->st_atimensec;
784 stat_mtimespec(struct stat *st)
788 #if defined(HAVE_STRUCT_STAT_ST_MTIM) 789 ts.
tv_nsec = st->st_mtim.tv_nsec;
790 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC) 791 ts.
tv_nsec = st->st_mtimespec.tv_nsec;
792 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) 793 ts.
tv_nsec = (long)st->st_mtimensec;
812 #if defined(HAVE_STRUCT_STAT_ST_CTIM) 813 ts.
tv_nsec = st->st_ctim.tv_nsec;
814 #elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC) 815 ts.
tv_nsec = st->st_ctimespec.tv_nsec;
816 #elif defined(HAVE_STRUCT_STAT_ST_CTIMENSEC) 817 ts.
tv_nsec = (long)st->st_ctimensec;
831 #define HAVE_STAT_BIRTHTIME 832 #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC) 834 stat_birthtime(
struct stat *st)
836 struct timespec *ts = &st->st_birthtimespec;
839 #elif defined(_WIN32) 840 # define stat_birthtime stat_ctime 842 # undef HAVE_STAT_BIRTHTIME 898 #if defined(HAVE_STAT_BIRTHTIME) 924 return stat_birthtime(
get_stat(
self));
927 # define rb_stat_birthtime rb_f_notimplement 950 static const struct {
967 #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC) 982 for (i = 0; i <
sizeof(member)/
sizeof(member[0]); i++) {
990 v = (*member[i].func)(
self);
994 else if (i == 0 || i == 6) {
1026 w32_io_info(
VALUE *file, BY_HANDLE_FILE_INFORMATION *st)
1037 if (f == (HANDLE)-1)
return INVALID_HANDLE_VALUE;
1049 MultiByteToWideChar(CP_UTF8, 0,
RSTRING_PTR(tmp), -1, ptr, len);
1050 f = CreateFileW(ptr, 0,
1051 FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
1052 FILE_FLAG_BACKUP_SEMANTICS,
NULL);
1054 if (f == INVALID_HANDLE_VALUE)
return f;
1057 if (GetFileType(f) == FILE_TYPE_DISK) {
1058 ZeroMemory(st,
sizeof(*st));
1059 if (GetFileInformationByHandle(f, st))
return ret;
1061 if (ret) CloseHandle(ret);
1062 return INVALID_HANDLE_VALUE;
1066 close_handle(
VALUE h)
1068 CloseHandle((HANDLE)h);
1072 struct w32_io_info_args {
1074 BY_HANDLE_FILE_INFORMATION *st;
1078 call_w32_io_info(
VALUE arg)
1080 struct w32_io_info_args *p = (
void *)arg;
1081 return (
VALUE)w32_io_info(p->fname, p->st);
1102 if (
rb_stat(fname, &st) < 0) {
1130 if (
fstat(fptr->
fd, &st) == -1) {
1204 #if defined(_WIN32) || !defined(HAVE_GETGROUPS) 1222 gary =
ALLOCV_N(GETGROUPS_T, v, groups);
1223 anum = getgroups(groups, gary);
1224 if (anum != -1 && anum != groups)
1235 while (--anum >= 0) {
1236 if (gary[anum] == gid) {
1249 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) 1252 #if defined(S_IXGRP) && !defined(_WIN32) && !defined(__CYGWIN__) 1253 #define USE_GETEUID 1 1256 #ifdef __native_client__ 1261 # undef HAVE_EACCESS 1265 #ifndef HAVE_EACCESS 1277 return access(path, mode);
1279 if (
STAT(path, &st) < 0)
1295 if (st.st_uid == euid)
1300 if ((
int)(st.st_mode & mode) == mode)
return 0;
1304 return access(path, mode);
1339 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 1363 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 1369 if (S_ISFIFO(st.st_mode))
return Qtrue;
1387 # define S_ISLNK(m) _S_ISLNK(m) 1390 # define S_ISLNK(m) (((m) & S_IFMT) == _S_IFLNK) 1393 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 1425 # define S_ISSOCK(m) _S_ISSOCK(m) 1428 # define S_ISSOCK(m) (((m) & S_IFMT) == _S_IFSOCK) 1431 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) 1441 if (S_ISSOCK(st.st_mode))
return Qtrue;
1461 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 1463 # define S_ISBLK(m) (0) 1489 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 1529 const char *s =
"FileTest#";
1538 rb_warning(
"%sexists? is a deprecated name, use %sexist? instead", s, s);
1577 # define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 1581 # define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 1713 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 1754 if (st.st_size == 0)
return Qtrue;
1774 if (st.st_size == 0)
return Qnil;
1832 #if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX) 1834 check3rdbyte(
VALUE fname,
int mode)
1841 if (st.st_mode & mode)
return Qtrue;
1857 return check3rdbyte(fname, S_ISUID);
1874 return check3rdbyte(fname, S_ISGID);
1891 return check3rdbyte(fname, S_ISVTX);
1920 struct stat st1, st2;
1924 if (st1.st_dev != st2.st_dev)
return Qfalse;
1925 if (st1.st_ino != st2.st_ino)
return Qfalse;
1928 BY_HANDLE_FILE_INFORMATION st1, st2;
1929 HANDLE f1 = 0, f2 = 0;
1931 f1 = w32_io_info(&fname1, &st1);
1932 if (f1 == INVALID_HANDLE_VALUE)
return Qfalse;
1934 struct w32_io_info_args arg;
1935 arg.fname = &fname2;
1940 f2 = w32_io_info(&fname2, &st2);
1942 if (f2 == INVALID_HANDLE_VALUE)
return Qfalse;
1943 if (f2) CloseHandle(f2);
1945 if (st1.dwVolumeSerialNumber == st2.dwVolumeSerialNumber &&
1946 st1.nFileIndexHigh == st2.nFileIndexHigh &&
1947 st1.nFileIndexLow == st2.nFileIndexLow)
1967 if (
rb_stat(fname, &st) < 0) {
1983 else if (
S_ISDIR(st->st_mode)) {
1986 else if (
S_ISCHR(st->st_mode)) {
1987 t =
"characterSpecial";
1990 else if (
S_ISBLK(st->st_mode)) {
1995 else if (S_ISFIFO(st->st_mode)) {
2000 else if (
S_ISLNK(st->st_mode)) {
2005 else if (S_ISSOCK(st->st_mode)) {
2062 if (
rb_stat(fname, &st) < 0) {
2088 if (
fstat(fptr->
fd, &st) == -1) {
2111 if (
rb_stat(fname, &st) < 0) {
2136 if (
fstat(fptr->
fd, &st) == -1) {
2163 if (
rb_stat(fname, &st) < 0) {
2191 if (
fstat(fptr->
fd, &st) == -1) {
2197 #if defined(HAVE_STAT_BIRTHTIME) 2217 if (
rb_stat(fname, &st) < 0) {
2222 return stat_birthtime(&st);
2225 # define rb_file_s_birthtime rb_f_notimplement 2228 #if defined(HAVE_STAT_BIRTHTIME) 2248 if (
fstat(fptr->
fd, &st) == -1) {
2251 return stat_birthtime(&st);
2254 # define rb_file_birthtime rb_f_notimplement 2277 if (
fstat(fptr->
fd, &st) == -1) {
2286 if (chmod(path, *(
int *)mode) < 0)
2332 #if !defined HAVE_FCHMOD || !HAVE_FCHMOD 2340 if (
fchmod(fptr->
fd, mode) == -1) {
2348 #if !defined HAVE_FCHMOD || !HAVE_FCHMOD 2358 #if defined(HAVE_LCHMOD) 2360 lchmod_internal(
const char *path,
VALUE pathv,
void *mode)
2362 if (lchmod(path, (
int)(
VALUE)mode) < 0)
2384 return apply2files(lchmod_internal, argc, argv, (
void *)(
long)mode);
2387 #define rb_file_s_lchmod rb_f_notimplement 2390 static inline rb_uid_t
2394 return (rb_uid_t)-1;
2399 static inline rb_gid_t
2403 return (rb_gid_t)-1;
2482 if (fchown(fptr->
fd, o, g) == -1)
2489 #if defined(HAVE_LCHOWN) 2491 lchown_internal(
const char *path,
VALUE pathv,
void *arg)
2518 return apply2files(lchown_internal, argc, argv, &arg);
2521 #define rb_file_s_lchown rb_f_notimplement 2529 #if defined DOSISH || defined __CYGWIN__ 2536 if (tsp && e == EINVAL) {
2539 if (!
NIL_P(atime)) {
2542 if (!
NIL_P(mtime) && mtime != atime && !
rb_equal(atime, mtime)) {
2545 if (
NIL_P(a)) e[0] = m;
2564 #define utime_failed(path, tsp, atime, mtime) rb_sys_fail_path(path) 2567 #if defined(HAVE_UTIMES) 2576 #if defined(HAVE_UTIMENSAT) 2577 static int try_utimensat = 1;
2579 if (try_utimensat) {
2580 if (utimensat(AT_FDCWD, path, tsp, 0) < 0) {
2581 if (
errno == ENOSYS) {
2599 if (
utimes(path, tvp) < 0)
2605 #if !defined HAVE_UTIME_H && !defined HAVE_SYS_UTIME_H 2623 if (
utime(path, utp) < 0)
2645 args.
atime = *argv++;
2646 args.
mtime = *argv++;
2661 #ifdef RUBY_FUNCTION_NAME_STRING 2662 # define syserr_fail2(e, s1, s2) syserr_fail2_in(RUBY_FUNCTION_NAME_STRING, e, s1, s2) 2664 # define syserr_fail2_in(func, e, s1, s2) syserr_fail2(e, s1, s2) 2666 #define sys_fail2(s1, s2) syserr_fail2(errno, s1, s2) 2673 const int max_pathlen = MAX_PATH;
2686 #ifdef RUBY_FUNCTION_NAME_STRING 2687 rb_syserr_fail_path_in(func, e, str);
2720 #define rb_file_s_link rb_f_notimplement 2750 #define rb_file_s_symlink rb_f_notimplement 2753 #ifdef HAVE_READLINK 2784 || (rv < 0 &&
errno == ERANGE)
2802 #define rb_file_s_readlink rb_f_notimplement 2808 if (unlink(path) < 0)
2841 const char *src, *dst;
2850 #if defined __CYGWIN__ 2853 if (rename(src, dst) < 0) {
2858 if (chmod(dst, 0666) == 0 &&
2860 rename(src, dst) == 0)
2864 syserr_fail2(e, from, to);
2894 else if (argc == 1) {
2906 #if defined __CYGWIN__ || defined DOSISH 2908 #define DOSISH_DRIVE_LETTER 2909 #define FILE_ALT_SEPARATOR '\\' 2911 #ifdef FILE_ALT_SEPARATOR 2912 #define isdirsep(x) ((x) == '/' || (x) == FILE_ALT_SEPARATOR) 2913 static const char file_alt_separator[] = {FILE_ALT_SEPARATOR,
'\0'};
2915 #define isdirsep(x) ((x) == '/') 2925 #ifndef USE_NTFS_ADS 2927 # define USE_NTFS_ADS 1 2929 # define USE_NTFS_ADS 0 2934 #define istrailinggarbage(x) ((x) == '.' || (x) == ' ') 2936 #define istrailinggarbage(x) 0 2939 # define isADS(x) ((x) == ':') 2944 #define Next(p, e, enc) ((p) + rb_enc_mbclen((p), (e), (enc))) 2945 #define Inc(p, e, enc) ((p) = Next((p), (e), (enc))) 2947 #if defined(DOSISH_UNC) 2948 #define has_unc(buf) (isdirsep((buf)[0]) && isdirsep((buf)[1])) 2950 #define has_unc(buf) 0 2953 #ifdef DOSISH_DRIVE_LETTER 2955 has_drive_letter(
const char *
buf)
2957 if (
ISALPHA(buf[0]) && buf[1] ==
':') {
2967 getcwdofdrv(
int drv)
2970 char *drvcwd, *oldcwd;
2981 if (chdir(drive) == 0) {
2995 not_same_drive(
VALUE path,
int drive)
2999 if (has_drive_letter(p)) {
3008 static inline char *
3011 #ifdef DOSISH_DRIVE_LETTER 3012 if (path + 2 <= end && has_drive_letter(path)) path += 2;
3014 while (path < end &&
isdirsep(*path)) path++;
3015 return (
char *)path;
3018 #define nextdirsep rb_enc_path_next 3028 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) 3029 #define skipprefix rb_enc_path_skip_prefix 3031 #define skipprefix(path, end, enc) (path) 3036 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) 3040 while (path < end &&
isdirsep(*path)) path++;
3043 return (
char *)path;
3046 #ifdef DOSISH_DRIVE_LETTER 3047 if (has_drive_letter(path))
3048 return (
char *)(path + 2);
3051 return (
char *)path;
3054 static inline char *
3057 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) 3066 #define strrdirsep rb_enc_path_last_separator 3071 while (path < end) {
3073 const char *tmp = path++;
3074 while (path < end &&
isdirsep(*path)) path++;
3075 if (path >= end)
break;
3079 Inc(path, end, enc);
3088 while (path < end) {
3090 const char *
last = path++;
3091 while (path < end &&
isdirsep(*path)) path++;
3092 if (path >= end)
return (
char *)
last;
3095 Inc(path, end, enc);
3098 return (
char *)path;
3104 if (path < end &&
isdirsep(*path)) path++;
3110 ntfs_tail(
const char *path,
const char *end,
rb_encoding *enc)
3112 while (path < end && *path ==
'.') path++;
3113 while (path < end && !
isADS(*path)) {
3115 const char *
last = path++;
3117 if (path >= end ||
isADS(*path))
return (
char *)
last;
3120 const char *
last = path++;
3121 while (path < end &&
isdirsep(*path)) path++;
3122 if (path >= end)
return (
char *)
last;
3123 if (
isADS(*path)) path++;
3126 Inc(path, end, enc);
3129 return (
char *)path;
3133 #define BUFCHECK(cond) do {\ 3136 do {buflen *= 2;} while (cond);\ 3137 rb_str_resize(result, buflen);\ 3138 buf = RSTRING_PTR(result);\ 3140 pend = buf + buflen;\ 3144 #define BUFINIT() (\ 3145 p = buf = RSTRING_PTR(result),\ 3146 buflen = RSTRING_LEN(result),\ 3150 # define SKIPPATHSEP(p) ((*(p)) ? 1 : 0) 3152 # define SKIPPATHSEP(p) 1 3155 #define BUFCOPY(srcptr, srclen) do { \ 3156 const int skip = SKIPPATHSEP(p); \ 3157 rb_str_set_len(result, p-buf+skip); \ 3158 BUFCHECK(bdiff + ((srclen)+skip) >= buflen); \ 3160 memcpy(p, (srcptr), (srclen)); \ 3164 #define WITH_ROOTDIFF(stmt) do { \ 3165 long rootdiff = root - buf; \ 3167 root = buf + rootdiff; \ 3174 #if defined DOSISH || defined __CYGWIN__ 3186 #if defined DOSISH || defined __CYGWIN__ 3188 for (bend = (p = buf) + dirlen; p < bend;
Inc(p, bend, enc)) {
3201 struct passwd *pwPtr;
3204 const char *pwPtr = 0;
3205 # define endpwent() ((void)0) 3219 pwPtr = getpwnam(username);
3222 dir = pwPtr =
getenv(
"HOME");
3229 dir = pwPtr->pw_dir;
3240 const char *dir =
getenv(
"HOME");
3242 #if defined HAVE_PWD_H 3246 struct passwd *pw = getpwnam(login);
3270 #if NORMALIZE_UTF8PATH 3271 VALUE path = rb_str_normalize_ospath(ptr, len);
3282 char *
buf, *cwdp = dir;
3288 if (direnc != fsenc) {
3297 do {buflen *= 2;}
while (dirlen > buflen);
3300 memcpy(buf, cwdp, dirlen);
3304 return buf + dirlen;
3310 const char *s, *b, *fend;
3311 char *
buf, *p, *pend, *root;
3312 size_t buflen, bdiff;
3322 if (s[0] ==
'~' && abs_mode == 0) {
3325 if (
isdirsep(s[1]) || s[1] ==
'\0') {
3336 BUFCHECK(bdiff + userlen >= buflen);
3348 (
int)userlen, b, fname);
3357 #ifdef DOSISH_DRIVE_LETTER 3359 else if (has_drive_letter(s)) {
3372 if (!
NIL_P(dname) && !not_same_drive(dname, s[0])) {
3381 char *e =
append_fspath(result, fname, getcwdofdrv(*s), &enc, fsenc);
3396 if (!
NIL_P(dname)) {
3408 #if defined DOSISH || defined __CYGWIN__ 3425 memset(buf,
'/', len);
3429 if (p > buf && p[-1] ==
'/')
3452 if (*(s+1) ==
'\0' ||
isdirsep(*(s+1))) {
3471 #if defined DOSISH || defined __CYGWIN__ 3496 #if defined DOSISH || defined __CYGWIN__ 3508 int n = ignored_char_p(s, fend, enc);
3527 static const char prime[] =
":$DATA";
3528 enum {prime_len =
sizeof(prime) -1};
3532 if (s > b + prime_len &&
strncasecmp(s - prime_len, prime, prime_len) == 0) {
3535 if (
isADS(*(s - (prime_len+1)))) {
3538 else if (memchr(b,
':', s - prime_len - b)) {
3547 if (p ==
skiproot(buf, p + !!*p, enc) - 1) p++;
3551 if ((s =
strrdirsep(b = buf, p, enc)) != 0 && !strpbrk(s,
"*?")) {
3556 WIN32_FIND_DATAW wfd;
3559 #ifdef HAVE_CYGWIN_CONV_PATH 3560 char *w32buf =
NULL;
3561 const int flags = CCP_POSIX_TO_WIN_A | CCP_RELATIVE;
3567 int lnk_added = 0, is_symlink = 0;
3573 if (len > 4 &&
STRCASECMP(p + len - 4,
".lnk") != 0) {
3577 path = *buf ?
buf :
"/";
3578 #ifdef HAVE_CYGWIN_CONV_PATH 3579 bufsize = cygwin_conv_path(flags, path,
NULL, 0);
3582 if (lnk_added) bufsize += 4;
3584 if (cygwin_conv_path(flags, path, w32buf, bufsize) == 0) {
3590 if (cygwin_conv_to_win32_path(path, w32buf) == 0) {
3594 if (is_symlink && b == w32buf) {
3598 strlcat(w32buf,
".lnk", bufsize);
3614 MultiByteToWideChar(CP_UTF8, 0,
RSTRING_PTR(tmp), -1, wstr, len);
3616 h = FindFirstFileW(wstr, &wfd);
3618 if (h != INVALID_HANDLE_VALUE) {
3621 len = lstrlenW(wfd.cFileName);
3623 if (lnk_added && len > 4 &&
3624 wcscasecmp(wfd.cFileName + len - 4,
L".lnk") == 0) {
3625 wfd.cFileName[len -= 4] =
L'\0';
3632 len = WideCharToMultiByte(CP_UTF8, 0, wfd.cFileName, wlen,
NULL, 0,
NULL,
NULL);
3633 if (tmp == result) {
3635 WideCharToMultiByte(CP_UTF8, 0, wfd.cFileName, wlen, p, len + 1,
NULL,
NULL);
3639 WideCharToMultiByte(CP_UTF8, 0, wfd.cFileName, wlen,
RSTRING_PTR(tmp), len + 1,
NULL,
NULL);
3663 #define EXPAND_PATH_BUFFER() rb_usascii_str_new(0, MAXPATHLEN + 2) 3672 #define expand_path(fname, dname, abs_mode, long_name, result) \ 3673 str_shrink(rb_file_expand_path_internal(fname, dname, abs_mode, long_name, result)) 3675 #define check_expand_path_args(fname, dname) \ 3676 (((fname) = rb_get_path(fname)), \ 3677 (void)(NIL_P(dname) ? (dname) : ((dname) = rb_get_path(dname)))) 3763 const char *pend = unresolved +
strlen(unresolved);
3767 while (unresolved < pend) {
3768 const char *testname = unresolved;
3770 long testnamelen = unresolved_firstsep - unresolved;
3771 const char *unresolved_nextname = unresolved_firstsep;
3772 while (unresolved_nextname < pend &&
isdirsep(*unresolved_nextname))
3773 unresolved_nextname++;
3774 unresolved = unresolved_nextname;
3775 if (testnamelen == 1 && testname[0] ==
'.') {
3777 else if (testnamelen == 2 && testname[0] ==
'.' && testname[1] ==
'.') {
3779 const char *resolved_str =
RSTRING_PTR(*resolvedp);
3780 const char *resolved_names = resolved_str + *prefixlenp;
3782 long len = lastsep ? lastsep - resolved_names : 0;
3791 #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) 3792 if (*prefixlenp > 1 && *prefixlenp ==
RSTRING_LEN(testpath)) {
3794 const char *last =
rb_enc_left_char_head(prefix, prefix + *prefixlenp - 1, prefix + *prefixlenp, enc);
3800 if (!
NIL_P(checkval)) {
3801 if (checkval ==
ID2SYM(resolving)) {
3812 #ifdef __native_client__ 3820 if (strict || !last || *unresolved_firstsep)
3822 *resolvedp = testpath;
3829 #ifdef HAVE_READLINK 3833 const char *link_prefix, *link_names;
3834 long link_prefixlen;
3839 link_prefixlen = link_names - link_prefix;
3840 if (link_prefixlen > 0) {
3847 *prefixlenp = link_prefixlen;
3849 realpath_rec(prefixlenp, resolvedp, link_names, loopcheck, strict, *unresolved_firstsep ==
'\0');
3858 *resolvedp = testpath;
3865 #ifdef __native_client__ 3877 volatile VALUE unresolved_path;
3882 char *path_names =
NULL, *basedir_names =
NULL, *curdir_names =
NULL;
3883 char *ptr, *prefixptr =
NULL, *pend;
3888 if (!
NIL_P(basedir)) {
3895 if (ptr != path_names) {
3896 resolved =
rb_str_subseq(unresolved_path, 0, path_names - ptr);
3900 if (!
NIL_P(basedir)) {
3903 if (ptr != basedir_names) {
3916 pend = prefixptr + prefixlen;
3920 prefixlen = ++ptr - prefixptr;
3923 #ifdef FILE_ALT_SEPARATOR 3924 while (prefixptr < ptr) {
3925 if (*prefixptr == FILE_ALT_SEPARATOR) {
3928 Inc(prefixptr, pend, enc);
3941 realpath_rec(&prefixlen, &resolved, curdir_names, loopcheck, 1, 0);
3943 realpath_rec(&prefixlen, &resolved, basedir_names, loopcheck, 1, 0);
3944 realpath_rec(&prefixlen, &resolved, path_names, loopcheck, strict, 1);
3971 VALUE path = argv[0];
3992 VALUE path = argv[0];
4002 const char *s, *
last;
4004 if (!e || !l2)
return 0;
4007 if (
rb_enc_ascget(e + len1, e + l2, &len2, enc) ==
'*' && len1 + len2 == l2) {
4008 if (c ==
'.')
return l0;
4018 if (l1 < l2)
return l1;
4022 #if CASEFOLD_FILESYSTEM 4023 #define fncomp strncasecmp 4025 #define fncomp strncmp 4027 if (
fncomp(s, e, l2) == 0) {
4036 const char *p, *q, *e, *end;
4037 #if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC 4042 end = name + (alllen ? (size_t)*alllen :
strlen(name));
4044 #if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC 4052 #if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC 4056 #ifdef DOSISH_DRIVE_LETTER 4057 else if (*p ==
':') {
4077 n = ntfs_tail(p, end, enc) - p;
4081 for (q = p; q - p < n && *q ==
'.'; q++);
4082 for (e = 0; q - p < n;
Inc(q, end, enc)) {
4083 if (*q ==
'.') e = q;
4116 VALUE fname, fext, basename;
4117 const char *
name, *p;
4179 const char *
name, *root, *p, *end;
4189 if (root > name + 1 &&
isdirsep(*name))
4190 root =
skipprefix(name = root - 2, end, enc);
4192 if (root > name + 1)
4201 #ifdef DOSISH_DRIVE_LETTER 4202 if (has_drive_letter(name) &&
isdirsep(*(name + 2))) {
4210 #ifdef DOSISH_DRIVE_LETTER 4211 if (has_drive_letter(name) && root == name + 2 && p - name == 2)
4234 const char *p, *e, *end = name + (len ? *
len : (long)
strlen(name));
4240 do name = ++p;
while (
isdirsep(*p));
4243 while (*p && *p ==
'.') p++;
4247 const char *
last = p++, *dot =
last;
4249 if (*p ==
'.') dot = p;
4252 if (!*p ||
isADS(*p)) {
4256 if (*last ==
'.' || dot > last) e = dot;
4263 else if (
isADS(*p)) {
4274 if (!e || e == name)
4310 const char *
name, *e;
4377 const char *
name, *tail;
4428 else if (!
NIL_P(sep)) {
4465 #if defined(HAVE_TRUNCATE) || defined(HAVE_CHSIZE) 4484 #ifdef HAVE_TRUNCATE 4485 #define NUM2POS(n) NUM2OFFT(n) 4488 #define NUM2POS(n) NUM2LONG(n) 4495 #ifdef HAVE_TRUNCATE 4506 if (chsize(tmpfd, pos) < 0) {
4518 #define rb_file_s_truncate rb_f_notimplement 4521 #if defined(HAVE_FTRUNCATE) || defined(HAVE_CHSIZE) 4540 #if defined(HAVE_FTRUNCATE) 4541 #define NUM2POS(n) NUM2OFFT(n) 4544 #define NUM2POS(n) NUM2LONG(n) 4554 #ifdef HAVE_FTRUNCATE 4558 if (chsize(fptr->
fd, pos) < 0)
4565 #define rb_file_truncate rb_f_notimplement 4582 #include <winerror.h> 4589 int old_errno =
errno;
4591 int *op = data, ret =
flock(op[0], op[1]);
4594 if (GetLastError() == ERROR_NOT_LOCKED) {
4653 op[1] = op1 =
NUM2INT(operation);
4665 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 4677 #if defined(ERESTART) 4696 for (i=1; i<n; i++) {
4703 #define CHECK(n) test_check((n), argc, argv) 4780 if (
strchr(
"bcdefgGkloOprRsSuwWxXz", cmd)) {
4851 if (
strchr(
"MAC", cmd)) {
4853 VALUE fname = argv[1];
4856 if (
rb_stat(fname, &st) == -1) {
4877 if (
strchr(
"=<>", cmd)) {
4878 struct stat st1, st2;
4940 struct stat st, *nst;
4951 nst =
ALLOC(
struct stat);
4970 nst =
ALLOC(
struct stat);
4971 *nst = *(
struct stat*)
DATA_PTR(orig);
5478 if (size == 0)
return Qnil;
5544 #if !defined HAVE_MKFIFO && defined HAVE_MKNOD && defined S_IFIFO 5545 #define mkfifo(path, mode) mknod(path, (mode)&~S_IFMT|S_IFIFO, 0) 5579 #define rb_file_s_mkfifo rb_f_notimplement 5593 #ifdef DOSISH_DRIVE_LETTER 5594 if (has_drive_letter(path) &&
isdirsep(path[2]))
return 1;
5600 if (path[0] ==
'/')
return 1;
5605 #ifndef ENABLE_PATH_CHECK 5606 # if defined DOSISH || defined __CYGWIN__ 5607 # define ENABLE_PATH_CHECK 0 5609 # define ENABLE_PATH_CHECK 1 5613 #if ENABLE_PATH_CHECK 5639 # define S_IWOTH 002 5643 && !(p && execpath && (st.st_mode & S_ISVTX))
5646 rb_warn(
"Insecure world writable dir %s in %sPATH, mode 0%" 5647 PRI_MODET_PREFIX
"o",
5648 p0, (execpath ?
"" :
"LOAD_"), st.st_mode);
5655 if (!s || s == p0)
return 1;
5663 #if ENABLE_PATH_CHECK 5664 #define fpath_check(path) path_check_0((path), FALSE) 5666 #define fpath_check(path) 1 5672 #if ENABLE_PATH_CHECK 5673 const char *p0, *p, *pend;
5676 if (!path)
return 1;
5678 pend = path +
strlen(path);
5688 if (p0 > pend)
break;
5704 if (
fstat(fd, &st) < 0)
5710 if (S_ISFIFO(st.st_mode))
5731 int mode = (O_RDONLY |
5732 #if defined O_NONBLOCK 5734 #elif defined O_NDELAY 5739 if (fd == -1)
return 0;
5750 if (*path++ !=
'.')
return 0;
5751 if (*path ==
'.') path++;
5774 VALUE fname = *filep, load_path, tmp;
5778 if (!ext[0])
return 0;
5796 for (i=0; ext[i]; i++) {
5808 if (!load_path)
return 0;
5815 for (j=0; ext[j]; j++) {
5817 for (i = 0; i <
RARRAY_LEN(load_path); i++) {
5845 VALUE tmp, load_path;
5875 for (i = 0; i <
RARRAY_LEN(load_path); i++) {
5909 #elif defined AMIGA || defined __amigaos__ 6083 #if defined(O_NDELAY) || defined(O_NONBLOCK) 6085 # define O_NONBLOCK O_NDELAY 6101 #ifndef O_SHARE_DELETE 6102 # define O_SHARE_DELETE 0 RUBY_EXTERN VALUE rb_cString
static VALUE rb_file_exists_p(VALUE obj, VALUE fname)
#define RBASIC_CLEAR_CLASS(obj)
static VALUE rb_stat_ino(VALUE self)
VALUE rb_get_path_check_convert(VALUE obj, VALUE tmp, int level)
#define ENCINDEX_US_ASCII
VALUE rb_get_path(VALUE obj)
#define MBCLEN_CHARFOUND_P(ret)
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
static VALUE rb_file_socket_p(VALUE obj, VALUE fname)
#define MBCLEN_CHARFOUND_LEN(ret)
static VALUE rb_file_s_mtime(VALUE klass, VALUE fname)
#define rb_enc_mbc_to_codepoint(p, e, enc)
static VALUE stat_mtime(struct stat *st)
void rb_enc_copy(VALUE obj1, VALUE obj2)
#define RUBY_TYPED_FREE_IMMEDIATELY
static VALUE rb_file_sgid_p(VALUE obj, VALUE fname)
static struct timespec stat_atimespec(struct stat *st)
size_t strlen(const char *)
static VALUE rb_get_path_check(VALUE obj, int level)
static VALUE rb_stat_z(VALUE obj)
void rb_update_max_fd(int fd)
static VALUE rb_stat_init(VALUE obj, VALUE fname)
VALUE rb_time_nano_new(time_t, long)
static VALUE rb_file_executable_p(VALUE obj, VALUE fname)
static VALUE rb_stat_rdev(VALUE self)
static VALUE rb_stat_cmp(VALUE self, VALUE other)
int rb_is_absolute_path(const char *path)
static VALUE rb_stat_init_copy(VALUE copy, VALUE orig)
static VALUE rb_file_grpowned_p(VALUE obj, VALUE fname)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define skipprefix(path, end, enc)
#define access(path, mode)
static VALUE rb_file_size_p(VALUE obj, VALUE fname)
#define expand_path(fname, dname, abs_mode, long_name, result)
static VALUE rb_file_s_size(VALUE klass, VALUE fname)
#define rb_usascii_str_new2
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
void rb_file_const(const char *name, VALUE value)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE rb_f_test(int argc, VALUE *argv)
static VALUE rb_stat_mode(VALUE self)
int rb_find_file_ext(VALUE *filep, const char *const *ext)
static VALUE rb_file_world_writable_p(VALUE obj, VALUE fname)
static VALUE rb_file_readable_p(VALUE obj, VALUE fname)
static VALUE rb_stat_f(VALUE obj)
#define TypedData_Wrap_Struct(klass, data_type, sval)
#define OBJ_INIT_COPY(obj, orig)
ssize_t readlink(const char *, char *, size_t)
void rb_io_check_initialized(rb_io_t *)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_get_path_check_to_string(VALUE obj, int level)
const struct timespec * tsp
#define ENC_CODERANGE_CLEAR(obj)
SOCKET rb_w32_get_osfhandle(int)
int eaccess(const char *path, int mode)
int lchown(const char *path, int owner, int group)
rb_encoding * rb_default_internal_encoding(void)
VALUE rb_str_buf_new2(const char *)
SSL_METHOD *(* func)(void)
static VALUE rb_file_flock(VALUE obj, VALUE operation)
const char * ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc)
int rb_usascii_encindex(void)
VALUE rb_str_plus(VALUE, VALUE)
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
#define FilePathStringValue(v)
static VALUE rb_stat_blocks(VALUE self)
void rb_str_set_len(VALUE, long)
static VALUE copy_path_class(VALUE path, VALUE orig)
#define RBASIC_SET_CLASS(obj, cls)
int rb_enc_str_coderange(VALUE)
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static struct timespec stat_mtimespec(struct stat *st)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
static VALUE rb_stat_w(VALUE obj)
VALUE rb_io_taint_check(VALUE)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
VALUE rb_readlink(VALUE path, rb_encoding *resultenc)
static VALUE rb_file_zero_p(VALUE obj, VALUE fname)
static VALUE rb_stat_d(VALUE obj)
static VALUE file_inspect_join(VALUE ary, VALUE argp, int recur)
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
static VALUE rb_file_size(VALUE obj)
void rb_include_module(VALUE klass, VALUE module)
static VALUE file_path_convert(VALUE name)
#define rb_file_birthtime
static VALUE rb_file_lstat(VALUE obj)
static VALUE rb_stat_dev_minor(VALUE self)
static VALUE rb_file_suid_p(VALUE obj, VALUE fname)
static VALUE rb_file_s_basename(int argc, VALUE *argv)
int rb_str_cmp(VALUE, VALUE)
static VALUE rb_stat_S(VALUE obj)
static VALUE file_expand_path_1(VALUE fname)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
static VALUE rb_file_s_utime(int argc, VALUE *argv)
static VALUE rb_stat_s(VALUE obj)
static VALUE rb_stat_dev(VALUE self)
int rb_filesystem_encindex(void)
rb_encoding * rb_utf8_encoding(void)
static void realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE loopcheck, int strict, int last)
VALUE rb_str_dup_frozen(VALUE)
static VALUE rb_file_ctime(VALUE obj)
static VALUE rb_stat_uid(VALUE self)
VALUE rb_str_tmp_new(long)
VALUE rb_str_buf_append(VALUE, VALUE)
#define GetOpenFile(obj, fp)
static VALUE rb_stat_r(VALUE obj)
static VALUE rb_stat_grpowned(VALUE obj)
static VALUE apply2files(void(*func)(const char *, VALUE, void *), int argc, VALUE *argv, void *arg)
int truncate(const char *path, off_t new_size)
#define ENC_CODERANGE_7BIT
const char * rb_obj_classname(VALUE)
struct timespec rb_time_timespec(VALUE time)
static VALUE rb_stat_x(VALUE obj)
static char * chompdirsep(const char *path, const char *end, rb_encoding *enc)
#define rb_file_s_readlink
void rb_exc_raise(VALUE mesg)
static VALUE rb_file_blockdev_p(VALUE obj, VALUE fname)
char * rb_enc_path_skip_prefix(const char *path, const char *end, rb_encoding *enc)
static VALUE rb_file_world_readable_p(VALUE obj, VALUE fname)
#define RBASIC_SET_CLASS_RAW(obj, cls)
static VALUE rb_stat_s_alloc(VALUE klass)
#define RB_TYPE_P(obj, type)
int utimes(const char *filename, const struct timeval times[2])
static VALUE rb_file_ftype(const struct stat *st)
static VALUE rb_thread_flock(void *data)
static int path_check_0(VALUE path, int execpath)
static VALUE stat_ctime(struct stat *st)
static rb_encoding * check_path_encoding(VALUE str)
static VALUE rb_stat_size(VALUE self)
int rb_enc_to_index(rb_encoding *enc)
static VALUE rb_file_s_split(VALUE klass, VALUE path)
static VALUE stat_new_0(VALUE klass, const struct stat *st)
unsigned long long uint64_t
static VALUE rb_file_pipe_p(VALUE obj, VALUE fname)
VALUE rb_find_file(VALUE path)
static VALUE rb_file_s_chmod(int argc, VALUE *argv)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
static VALUE rb_file_s_lstat(VALUE klass, VALUE fname)
VALUE rb_str_new_shared(VALUE)
VALUE rb_obj_taint(VALUE)
VALUE rb_str_encode_ospath(VALUE path)
static rb_gid_t to_gid(VALUE g)
static VALUE rb_file_readable_real_p(VALUE obj, VALUE fname)
#define rb_file_s_symlink
RUBY_EXTERN VALUE rb_cObject
VALUE rb_home_dir_of(VALUE user, VALUE result)
static VALUE rb_file_s_stat(VALUE klass, VALUE fname)
static VALUE rb_file_mtime(VALUE obj)
static VALUE rb_file_s_chown(int argc, VALUE *argv)
static VALUE rb_file_s_realpath(int argc, VALUE *argv, VALUE klass)
static VALUE rb_stat_owned(VALUE obj)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_str_buf_cat2(VALUE, const char *)
VALUE rb_file_s_expand_path(int argc, const VALUE *argv)
static int is_explicit_relative(const char *path)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE rb_file_exist_p(VALUE obj, VALUE fname)
int chown(const char *, int, int)
static VALUE str_shrink(VALUE str)
#define OBJ_BUILTIN_TYPE(obj)
void rb_define_const(VALUE, const char *, VALUE)
static char * skiproot(const char *path, const char *end, rb_encoding *enc)
char * rb_enc_path_next(const char *s, const char *e, rb_encoding *enc)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
VALUE rb_io_flush_raw(VALUE, int)
#define insecure_obj_p(obj, level)
static VALUE rb_file_sticky_p(VALUE obj, VALUE fname)
static VALUE rb_file_s_join(VALUE klass, VALUE args)
static VALUE rb_file_atime(VALUE obj)
#define ALLOCV_N(type, v, n)
static size_t stat_memsize(const void *p)
mode_t umask(mode_t mask)
static VALUE rb_stat_b(VALUE obj)
#define ALLOCA_N(type, n)
#define fpath_check(path)
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
VALUE rb_enc_associate_index(VALUE obj, int idx)
static VALUE rb_file_s_unlink(int argc, VALUE *argv, VALUE klass)
static void chmod_internal(const char *path, VALUE pathv, void *mode)
VALUE rb_find_file_safe(VALUE path, int safe_level)
static VALUE rb_stat_suid(VALUE obj)
int link(const char *, const char *)
static VALUE rb_file_writable_real_p(VALUE obj, VALUE fname)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
#define rb_file_s_birthtime
static VALUE rb_stat_sticky(VALUE obj)
static VALUE rb_stat_ftype(VALUE obj)
static char * append_fspath(VALUE result, VALUE fname, char *dir, rb_encoding **enc, rb_encoding *fsenc)
VALUE rb_file_absolute_path(VALUE fname, VALUE dname)
VALUE rb_str_resize(VALUE, long)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
VALUE rb_str_subseq(VALUE, long, long)
static VALUE rb_stat_blksize(VALUE self)
#define syserr_fail2_in(func, e, s1, s2)
static VALUE rb_file_identical_p(VALUE obj, VALUE fname1, VALUE fname2)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
VALUE rb_sprintf(const char *format,...)
int ruby_is_fd_loadable(int fd)
VALUE rb_file_s_absolute_path(int argc, const VALUE *argv)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_eSystemCallError
#define NORMALIZE_UTF8PATH
static VALUE rb_file_s_path(VALUE klass, VALUE fname)
static VALUE rb_stat_dev_major(VALUE self)
VALUE rb_file_dirname(VALUE fname)
#define WITH_ROOTDIFF(stmt)
static char * skipprefixroot(const char *path, const char *end, rb_encoding *enc)
void rb_str_modify_expand(VALUE, long)
static VALUE rb_stat_ctime(VALUE self)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
VALUE rb_file_directory_p(VALUE obj, VALUE fname)
static int rb_group_member(GETGROUPS_T gid)
int ftruncate(int fd, off_t new_size)
#define EXPAND_PATH_BUFFER()
#define check_expand_path_args(fname, dname)
static VALUE rb_stat_sgid(VALUE obj)
char * strchr(char *, char)
static VALUE rb_stat_inspect(VALUE self)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
#define rb_enc_asciicompat(enc)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
static VALUE rb_file_writable_p(VALUE obj, VALUE fname)
VALUE rb_str_ellipsize(VALUE, long)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
VALUE rb_str_new_cstr(const char *)
static void utime_internal(const char *path, VALUE pathv, void *arg)
static VALUE copy_home_path(VALUE result, const char *dir)
static struct timespec stat_ctimespec(struct stat *st)
static void chown_internal(const char *path, VALUE pathv, void *arg)
static void test_check(int n, int argc, VALUE *argv)
VALUE rb_stat_new(const struct stat *st)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
#define StringValueCStr(v)
static VALUE rb_stat_wr(VALUE obj)
static VALUE rb_stat_mtime(VALUE self)
void rb_thread_wait_for(struct timeval)
#define sys_fail2(s1, s2)
#define ENCODING_GET(obj)
VALUE rb_equal(VALUE, VALUE)
rb_encoding * rb_enc_get(VALUE obj)
#define utime_failed(path, tsp, atime, mtime)
void rb_insecure_operation(void)
static const char null_device[]
int utime(const char *filename, const struct utimbuf *times)
static VALUE rb_file_s_ftype(VALUE klass, VALUE fname)
#define RARRAY_AREF(a, i)
int rb_path_check(const char *path)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
VALUE rb_file_expand_path(VALUE fname, VALUE dname)
static const rb_data_type_t stat_data_type
static VALUE rb_file_chown(VALUE obj, VALUE owner, VALUE group)
static VALUE rb_stat_rowned(VALUE obj)
static VALUE rb_stat_c(VALUE obj)
static VALUE rb_file_s_extname(VALUE klass, VALUE fname)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static VALUE rb_file_chmod(VALUE obj, VALUE vmode)
VALUE rb_str_catf(VALUE str, const char *format,...)
static VALUE rb_file_chardev_p(VALUE obj, VALUE fname)
#define rb_stat_birthtime
static VALUE stat_atime(struct stat *st)
static VALUE rb_file_s_dirname(VALUE klass, VALUE fname)
static VALUE rb_file_owned_p(VALUE obj, VALUE fname)
VALUE rb_default_home_dir(VALUE result)
size_t rb_str_capacity(VALUE str)
static void unlink_internal(const char *path, VALUE pathv, void *arg)
rb_encoding * rb_filesystem_encoding(void)
static VALUE rb_stat_atime(VALUE self)
#define BUFCOPY(srcptr, srclen)
static VALUE rb_stat_gid(VALUE self)
static VALUE rb_file_rowned_p(VALUE obj, VALUE fname)
static size_t rmext(const char *p, long l0, long l1, const char *e, long l2, rb_encoding *enc)
#define rb_enc_left_char_head(s, p, e, enc)
VALUE rb_str_inspect(VALUE)
static VALUE rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
static VALUE rb_stat_p(VALUE obj)
static VALUE ospath_new(const char *ptr, long len, rb_encoding *fsenc)
VALUE rb_get_expanded_load_path(void)
static VALUE rb_stat_rdev_major(VALUE self)
char * rb_enc_path_end(const char *path, const char *end, rb_encoding *enc)
static struct stat * get_stat(VALUE self)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
static int rb_stat(VALUE file, struct stat *st)
#define rb_sys_fail_path(path)
static VALUE rb_stat_X(VALUE obj)
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict)
#define istrailinggarbage(x)
char * rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
RUBY_EXTERN VALUE rb_eIOError
static VALUE rb_file_executable_real_p(VALUE obj, VALUE fname)
int rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
int rb_file_load_ok(const char *path)
static VALUE rb_stat_ww(VALUE obj)
RUBY_EXTERN size_t strlcat(char *, const char *, size_t)
static VALUE rb_file_s_ctime(VALUE klass, VALUE fname)
static VALUE rb_file_path(VALUE obj)
VALUE rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len, rb_encoding *from, int ecflags, VALUE ecopts)
static VALUE rb_io_stat(VALUE obj)
#define StringValuePtr(v)
#define STRCASECMP(s1, s2)
NORETURN(static void syserr_fail2_in(const char *, int, VALUE, VALUE))
#define RTYPEDDATA_DATA(v)
void rb_warning(const char *fmt,...)
#define rb_syserr_fail_path(err, path)
#define CONST_ID(var, str)
#define RUBY_TYPED_DEFAULT_FREE
static VALUE rb_stat_nlink(VALUE self)
VALUE rb_obj_freeze(VALUE)
int fchmod(int fd, int mode)
VALUE rb_define_module(const char *name)
int rb_enc_str_asciionly_p(VALUE)
int symlink(const char *src, const char *link)
const char * ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
VALUE rb_str_buf_new(long)
static VALUE rb_file_s_umask(int argc, VALUE *argv)
VALUE rb_get_path_no_checksafe(VALUE obj)
#define rb_file_s_truncate
VALUE rb_class_inherited_p(VALUE mod, VALUE arg)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
static VALUE rb_stat_rdev_minor(VALUE self)
static VALUE rb_stat_l(VALUE obj)
static VALUE rb_file_s_realdirpath(int argc, VALUE *argv, VALUE klass)
static VALUE rb_file_join(VALUE ary, VALUE sep)
void rb_warn(const char *fmt,...)
void rb_io_check_closed(rb_io_t *)
static VALUE rb_stat_W(VALUE obj)
static VALUE rb_file_s_atime(VALUE klass, VALUE fname)
VALUE rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_name, VALUE result)
static VALUE rb_stat_R(VALUE obj)
static rb_uid_t to_uid(VALUE u)
VALUE rb_file_expand_path_fast(VALUE fname, VALUE dname)
static void define_filetest_function(const char *name, VALUE(*func)(ANYARGS), int argc)
rb_encoding * rb_enc_from_index(int index)
VALUE rb_str_new(const char *, long)
VALUE rb_obj_class(VALUE)
static VALUE rb_file_file_p(VALUE obj, VALUE fname)
static VALUE rb_file_symlink_p(VALUE obj, VALUE fname)