Skip to content

Commit 73196ef

Browse files
committed
* dir.c, file.c: define wrapper macros by the original function name
directly. suggested by matz. but, ``stat'' is used as function's name and struct's name, so cannot define simply. it's pending. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/win32-unicode-test@25331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 2499cbd commit 73196ef

File tree

3 files changed

+48
-42
lines changed

3 files changed

+48
-42
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Wed Oct 14 17:17:25 2009 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* dir.c, file.c: define wrapper macros by the original function name
4+
directly. suggested by matz.
5+
but, ``stat'' is used as function's name and struct's name, so cannot
6+
define simply. it's pending.
7+
18
Wed Oct 7 10:15:50 2009 NAKAMURA Usaku <usa@ruby-lang.org>
29

310
* dir.c (dir_chdir, dir_s_mkdir, dir_s_rmdir): use wrapper macros

dir.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ char *strchr(char*,char);
6969

7070
/* define system APIs */
7171
#ifdef _WIN32
72-
#define CHDIR(p) _wchdir((WCHAR *)(p))
73-
#define MKDIR(p, m) rb_w32_wmkdir((WCHAR *)(p), m)
74-
#define RMDIR(p) _wrmdir((WCHAR *)(p))
75-
#else
76-
#define CHDIR(p) chdir(p)
77-
#define MKDIR(p, m) mkdir(p, m)
78-
#define RMDIR(p, m) rmdir(p, m)
72+
#undef chdir
73+
#define chdir(p) _wchdir((WCHAR *)(p))
74+
#undef mkdir
75+
#define mkdir(p, m) rb_w32_wmkdir((WCHAR *)(p), m)
76+
#undef rmdir
77+
#define rmdir(p) _wrmdir((WCHAR *)(p))
7978
#endif
8079

8180
#define FNM_NOESCAPE 0x01
@@ -752,7 +751,7 @@ static void
752751
dir_chdir(VALUE path)
753752
{
754753
path = rb_str_conv_for_path(path);
755-
if (CHDIR(RSTRING_PTR(path)) < 0)
754+
if (chdir(RSTRING_PTR(path)) < 0)
756755
rb_sys_fail(RSTRING_PTR(path));
757756
}
758757

@@ -955,7 +954,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
955954

956955
check_dirname(&path);
957956
path = rb_str_conv_for_path(path);
958-
if (MKDIR(RSTRING_PTR(path), mode) == -1)
957+
if (mkdir(RSTRING_PTR(path), mode) == -1)
959958
rb_sys_fail(RSTRING_PTR(path));
960959

961960
return INT2FIX(0);
@@ -975,7 +974,7 @@ dir_s_rmdir(VALUE obj, VALUE dir)
975974
{
976975
check_dirname(&dir);
977976
dir = rb_str_conv_for_path(dir);
978-
if (RMDIR(RSTRING_PTR(dir)) < 0)
977+
if (rmdir(RSTRING_PTR(dir)) < 0)
979978
rb_sys_fail(RSTRING_PTR(dir));
980979

981980
return INT2FIX(0);

file.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,24 @@ int flock(int, int);
7373
/* define system APIs */
7474
#ifdef _WIN32
7575
#define STAT(p, s) rb_w32_wstati64((WCHAR *)(p), s)
76-
#define LSTAT(p, s) rb_w32_wstati64((WCHAR *)(p), s)
77-
#define ACCESS(p, m) _waccess((WCHAR *)(p), m)
78-
#define CHMOD(p, m) _wchmod((WCHAR *)(p), m)
79-
#define CHOWN(p, o, g) rb_w32_wchown((WCHAR *)(p), o, g)
80-
#define UTIME(p, t) rb_w32_wutime((WCHAR *)(p), t)
81-
#define LINK(f, t) rb_w32_wlink((WCHAR *)(f), (WCHAR *)(t))
82-
#define UNLINK(p) rb_w32_wunlink((WCHAR *)(p))
83-
#define RENAME(f, t) _wrename((WCHAR *)(f), (WCHAR *)(t))
76+
#undef lstat
77+
#define lstat(p, s) rb_w32_wstati64((WCHAR *)(p), s)
78+
#undef access
79+
#define access(p, m) _waccess((WCHAR *)(p), m)
80+
#undef chmod
81+
#define chmod(p, m) _wchmod((WCHAR *)(p), m)
82+
#undef chown
83+
#define chown(p, o, g) rb_w32_wchown((WCHAR *)(p), o, g)
84+
#undef utime
85+
#define utime(p, t) rb_w32_wutime((WCHAR *)(p), t)
86+
#undef link
87+
#define link(f, t) rb_w32_wlink((WCHAR *)(f), (WCHAR *)(t))
88+
#undef unlink
89+
#define unlink(p) rb_w32_wunlink((WCHAR *)(p))
90+
#undef rename
91+
#define rename(f, t) _wrename((WCHAR *)(f), (WCHAR *)(t))
8492
#else
8593
#define STAT(p, s) stat(p, s)
86-
#define LSTAT(p, s) lstat(p, s)
87-
#define ACCESS(p, m) access(p, m)
88-
#define CHMOD(p, m) chmod(p, m)
89-
#define CHOWN(p, o, g) chown(p, o, g)
90-
#define UTIME(p, t) utime(p, t)
91-
#define LINK(f, t) link(f, t)
92-
#define UNLINK(p) unlink(p)
93-
#define RENAME(f, t) rename(f, t)
9494
#endif
9595

9696
#ifdef __BEOS__ /* should not change ID if -1 */
@@ -99,7 +99,7 @@ be_chown(const char *path, uid_t owner, gid_t group)
9999
{
100100
if (owner == -1 || group == -1) {
101101
struct stat st;
102-
if (stat(path, &st) < 0) return -1;
102+
if (STAT(path, &st) < 0) return -1;
103103
if (owner == -1) owner = st.st_uid;
104104
if (group == -1) group = st.st_gid;
105105
}
@@ -956,7 +956,7 @@ rb_file_lstat(VALUE obj)
956956
GetOpenFile(obj, fptr);
957957
if (NIL_P(fptr->pathv)) return Qnil;
958958
path = rb_str_conv_for_path(fptr->pathv);
959-
if (LSTAT(RSTRING_PTR(path), &st) == -1) {
959+
if (lstat(RSTRING_PTR(path), &st) == -1) {
960960
rb_sys_fail_path(fptr->pathv);
961961
}
962962
return stat_new(&st);
@@ -1039,15 +1039,15 @@ eaccess(const char *path, int mode)
10391039

10401040
return -1;
10411041
#else
1042-
return ACCESS(path, mode);
1042+
return access(path, mode);
10431043
#endif
10441044
}
10451045
#endif
10461046

10471047
static inline int
10481048
access_internal(const char *path, int mode)
10491049
{
1050-
return ACCESS(path, mode);
1050+
return access(path, mode);
10511051
}
10521052

10531053

@@ -1559,7 +1559,7 @@ check3rdbyte(VALUE fname, int mode)
15591559
rb_secure(2);
15601560
FilePathValue(fname);
15611561
fname = rb_str_conv_for_path(fname);
1562-
if (stat(RSTRING_PTR(fname), &st) < 0) return Qfalse;
1562+
if (STAT(RSTRING_PTR(fname), &st) < 0) return Qfalse;
15631563
if (st.st_mode & mode) return Qtrue;
15641564
return Qfalse;
15651565
}
@@ -1765,7 +1765,7 @@ rb_file_s_ftype(VALUE klass, VALUE fname)
17651765
rb_secure(2);
17661766
FilePathValue(fname);
17671767
fname = rb_str_conv_for_path(fname);
1768-
if (LSTAT(RSTRING_PTR(fname), &st) == -1)
1768+
if (lstat(RSTRING_PTR(fname), &st) == -1)
17691769
rb_sys_fail(RSTRING_PTR(fname));
17701770

17711771
return rb_file_ftype(&st);
@@ -1939,7 +1939,7 @@ rb_file_size(VALUE obj)
19391939
static void
19401940
chmod_internal(const char *path, void *mode)
19411941
{
1942-
if (CHMOD(path, *(int *)mode) < 0)
1942+
if (chmod(path, *(int *)mode) < 0)
19431943
rb_sys_fail(path);
19441944
}
19451945

@@ -2004,7 +2004,7 @@ rb_file_chmod(VALUE obj, VALUE vmode)
20042004
#else
20052005
if (NIL_P(fptr->pathv)) return Qnil;
20062006
path = rb_str_conv_for_path(fptr->pathv);
2007-
if (CHMOD(RSTRING_PTR(path), mode) == -1)
2007+
if (chmod(RSTRING_PTR(path), mode) == -1)
20082008
rb_sys_fail_path(fptr->pathv);
20092009
#endif
20102010

@@ -2132,7 +2132,7 @@ rb_file_chown(VALUE obj, VALUE owner, VALUE group)
21322132
#ifndef HAVE_FCHOWN
21332133
if (NIL_P(fptr->pathv)) return Qnil;
21342134
path = rb_str_conv_for_path(fptr->pathv);
2135-
if (CHOWN(RSTRING_PTR(path), o, g) == -1)
2135+
if (chown(RSTRING_PTR(path), o, g) == -1)
21362136
rb_sys_fail_path(fptr->pathv);
21372137
#else
21382138
if (fchown(fptr->fd, o, g) == -1)
@@ -2292,7 +2292,7 @@ utime_internal(const char *path, void *arg)
22922292
utbuf.modtime = tsp[1].tv_sec;
22932293
utp = &utbuf;
22942294
}
2295-
if (UTIME(path, utp) < 0)
2295+
if (utime(path, utp) < 0)
22962296
utime_failed(path, tsp, v->atime, v->mtime);
22972297
}
22982298

@@ -2471,7 +2471,7 @@ rb_file_s_readlink(VALUE klass, VALUE path)
24712471
static void
24722472
unlink_internal(const char *path, void *arg)
24732473
{
2474-
if (UNLINK(path) < 0)
2474+
if (unlink(path) < 0)
24752475
rb_sys_fail(path);
24762476
}
24772477

@@ -2521,16 +2521,16 @@ rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
25212521
#if defined __CYGWIN__
25222522
errno = 0;
25232523
#endif
2524-
if (RENAME(src, dst) < 0) {
2524+
if (rename(src, dst) < 0) {
25252525
#if defined DOSISH
25262526
switch (errno) {
25272527
case EEXIST:
25282528
#if defined (__EMX__)
25292529
case EACCES:
25302530
#endif
2531-
if (CHMOD(dst, 0666) == 0 &&
2532-
UNLINK(dst) == 0 &&
2533-
RENAME(src, dst) == 0)
2531+
if (chmod(dst, 0666) == 0 &&
2532+
unlink(dst) == 0 &&
2533+
rename(src, dst) == 0)
25342534
return INT2FIX(0);
25352535
}
25362536
#endif
@@ -4637,7 +4637,7 @@ path_check_0(VALUE path, int execpath)
46374637
#ifndef S_IWOTH
46384638
# define S_IWOTH 002
46394639
#endif
4640-
if (stat(p0, &st) == 0 && S_ISDIR(st.st_mode) && (st.st_mode & S_IWOTH)
4640+
if (STAT(p0, &st) == 0 && S_ISDIR(st.st_mode) && (st.st_mode & S_IWOTH)
46414641
#ifdef S_ISVTX
46424642
&& !(p && execpath && (st.st_mode & S_ISVTX))
46434643
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy