6 #include <mruby/array.h>
7 #include <mruby/class.h>
8 #include <mruby/data.h>
9 #include <mruby/string.h>
10 #include <mruby/ext/io.h>
11 #include <mruby/error.h>
12 #include <mruby/presym.h>
14 #include <sys/types.h>
25 #define NULL_FILE "NUL"
26 #define UNLINK _unlink
27 #define GETCWD _getcwd
29 #define MAXPATHLEN 1024
30 #if !defined(PATH_MAX)
31 #define PATH_MAX _MAX_PATH
33 #define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
36 #define NULL_FILE "/dev/null"
40 #define CHMOD(a, b) chmod(a,b)
45 #include <sys/param.h>
49 #define FILE_SEPARATOR "/"
52 #define PATH_SEPARATOR ";"
53 #define FILE_ALT_SEPARATOR "\\"
54 #define VOLUME_SEPARATOR ":"
55 #define DIRSEP_P(ch) (((ch) == '/') | ((ch) == '\\'))
56 #define VOLSEP_P(ch) ((ch) == ':')
57 #define UNC_PATH_P(path) (DIRSEP_P((path)[0]) && DIRSEP_P((path)[1]))
58 #define DRIVE_LETTER_P(path) (((size_t)(((path)[0]) | 0x20) - 'a' <= (size_t)'z' - 'a') && (path)[1] == ':')
59 #define DRIVE_EQUAL_P(x, y) (((x)[0] | 0x20) == ((y)[0] | 0x20))
61 #define PATH_SEPARATOR ":"
62 #define DIRSEP_P(ch) ((ch) == '/')
78 #if !defined(_WIN32) || defined(MRB_MINGW32_LEGACY)
79 typedef struct stat mrb_stat
;
80 # define mrb_stat(path, sb) stat(path, sb)
81 # define mrb_fstat(fd, sb) fstat(fd, sb)
82 #elif defined MRB_INT32
83 typedef struct _stat32 mrb_stat
;
84 # define mrb_stat(path, sb) _stat32(path, sb)
85 # define mrb_fstat(fd, sb) _fstat32(fd, sb)
87 typedef struct _stat64 mrb_stat
;
88 # define mrb_stat(path, sb) _stat64(path, sb)
89 # define mrb_fstat(fd, sb) _fstat64(fd, sb)
94 flock(int fd
, int operation
)
96 HANDLE h
= (HANDLE
)_get_osfhandle(fd
);
98 flags
= ((operation
& LOCK_NB
) ? LOCKFILE_FAIL_IMMEDIATELY
: 0)
99 | ((operation
& LOCK_SH
) ? LOCKFILE_EXCLUSIVE_LOCK
: 0);
100 static const OVERLAPPED zero_ov
= {0};
101 OVERLAPPED ov
= zero_ov
;
102 return LockFileEx(h
, flags
, 0, 0xffffffff, 0xffffffff, &ov
) ? 0 : -1;
107 mrb_file_s_umask(mrb_state
*mrb
, mrb_value klass
)
110 /* nothing to do on windows */
111 return mrb_fixnum_value(0);
115 if (mrb_get_args(mrb
, "|i", &mask
) == 0) {