Skip to content

Commit 0946cdf

Browse files
committed
* file.c (rb_stat, rb_file_lstat, eaccess, rb_file_s_ftype,
rb_file_size, rb_file_chmod, chown_internal, rb_file_chown, utime_internal, rb_file_s_link, unlink_internal, rb_file_s_rename, rb_stat_init): use wrapper macros instead of using platform ifdefs. * file.c (rb_file_s_truncate): call rb_str_conv_for_path(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/win32-unicode-test@24733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 366c650 commit 0946cdf

File tree

2 files changed

+50
-64
lines changed

2 files changed

+50
-64
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Wed Sep 2 11:30:49 2009 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* file.c (rb_stat, rb_file_lstat, eaccess, rb_file_s_ftype,
4+
rb_file_size, rb_file_chmod, chown_internal, rb_file_chown,
5+
utime_internal, rb_file_s_link, unlink_internal, rb_file_s_rename,
6+
rb_stat_init): use wrapper macros instead of using platform ifdefs.
7+
8+
* file.c (rb_file_s_truncate): call rb_str_conv_for_path().
9+
110
Tue Sep 1 17:24:05 2009 NAKAMURA Usaku <usa@ruby-lang.org>
211

312
* win32/win32.c (rb_w32_opendir, link, rb_w32_stati64, rb_w32_utime,

file.c

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ int flock(int, int);
7070
#define lstat stat
7171
#endif
7272

73+
/* define system APIs */
74+
#ifdef _WIN32
75+
#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))
84+
#else
85+
#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)
94+
#endif
95+
7396
#ifdef __BEOS__ /* should not change ID if -1 */
7497
static int
7598
be_chown(const char *path, uid_t owner, gid_t group)
@@ -772,11 +795,7 @@ rb_stat(VALUE file, struct stat *st)
772795
}
773796
FilePathValue(file);
774797
file = rb_str_conv_for_path(file);
775-
#ifdef _WIN32
776-
return rb_w32_wstati64((WCHAR *)RSTRING_PTR(file), st);
777-
#else
778-
return stat(RSTRING_PTR(file), st);
779-
#endif
798+
return STAT(RSTRING_PTR(file), st);
780799
}
781800

782801
#ifdef _WIN32
@@ -925,7 +944,7 @@ rb_file_lstat(VALUE obj)
925944
GetOpenFile(obj, fptr);
926945
if (NIL_P(fptr->pathv)) return Qnil;
927946
path = rb_str_conv_for_path(fptr->pathv);
928-
if (lstat(RSTRING_PTR(path), &st) == -1) {
947+
if (LSTAT(RSTRING_PTR(path), &st) == -1) {
929948
rb_sys_fail_path(fptr->pathv);
930949
}
931950
return stat_new(&st);
@@ -981,11 +1000,7 @@ eaccess(const char *path, int mode)
9811000
struct stat st;
9821001
rb_uid_t euid;
9831002

984-
#ifdef _WIN32
985-
if (_wstat((WCHAR *)path, &st) < 0)
986-
#else
987-
if (stat(path, &st) < 0)
988-
#endif
1003+
if (STAT(path, &st) < 0)
9891004
return -1;
9901005

9911006
euid = geteuid();
@@ -1015,19 +1030,15 @@ eaccess(const char *path, int mode)
10151030
# if defined(_MSC_VER) || defined(__MINGW32__)
10161031
mode &= ~1;
10171032
# endif
1018-
return access(path, mode);
1033+
return ACCESS(path, mode);
10191034
#endif
10201035
}
10211036
#endif
10221037

10231038
static inline int
10241039
access_internal(const char *path, int mode)
10251040
{
1026-
#ifdef _WIN32
1027-
return _waccess((WCHAR *)path, mode);
1028-
#else
1029-
return access(path, mode);
1030-
#endif
1041+
return ACCESS(path, mode);
10311042
}
10321043

10331044

@@ -1745,11 +1756,7 @@ rb_file_s_ftype(VALUE klass, VALUE fname)
17451756
rb_secure(2);
17461757
FilePathValue(fname);
17471758
fname = rb_str_conv_for_path(fname);
1748-
#ifdef _WIN32
1749-
if (rb_w32_wstati64((WCHAR *)RSTRING_PTR(fname), &st) == -1)
1750-
#else
1751-
if (lstat(RSTRING_PTR(fname), &st) == -1)
1752-
#endif
1759+
if (LSTAT(RSTRING_PTR(fname), &st) == -1)
17531760
rb_sys_fail(RSTRING_PTR(fname));
17541761

17551762
return rb_file_ftype(&st);
@@ -1923,11 +1930,7 @@ rb_file_size(VALUE obj)
19231930
static void
19241931
chmod_internal(const char *path, void *mode)
19251932
{
1926-
#ifdef _WIN32
1927-
if (_wchmod((WCHAR *)path, *(int *)mode) < 0)
1928-
#else
1929-
if (chmod(path, *(int *)mode) < 0)
1930-
#endif
1933+
if (CHMOD(path, *(int *)mode) < 0)
19311934
rb_sys_fail(path);
19321935
}
19331936

@@ -1992,11 +1995,7 @@ rb_file_chmod(VALUE obj, VALUE vmode)
19921995
#else
19931996
if (NIL_P(fptr->pathv)) return Qnil;
19941997
path = rb_str_conv_for_path(fptr->pathv);
1995-
# ifdef _WIN32
1996-
if (_wchmod((WCHAR *)RSTRING_PTR(path), mode) == -1)
1997-
# else
1998-
if (chmod(RSTRING_PTR(path), mode) == -1)
1999-
# endif
1998+
if (CHMOD(RSTRING_PTR(path), mode) == -1)
20001999
rb_sys_fail_path(fptr->pathv);
20012000
#endif
20022001

@@ -2048,11 +2047,7 @@ static void
20482047
chown_internal(const char *path, void *arg)
20492048
{
20502049
struct chown_args *args = arg;
2051-
#ifdef _WIN32
2052-
if (rb_w32_wchown((WCHAR *)path, args->owner, args->group) < 0)
2053-
#else
20542050
if (chown(path, args->owner, args->group) < 0)
2055-
#endif
20562051
rb_sys_fail(path);
20572052
}
20582053

@@ -2128,11 +2123,7 @@ rb_file_chown(VALUE obj, VALUE owner, VALUE group)
21282123
#ifndef HAVE_FCHOWN
21292124
if (NIL_P(fptr->pathv)) return Qnil;
21302125
path = rb_str_conv_for_path(fptr->pathv);
2131-
# ifdef _WIN32
2132-
if (rb_w32_wchown((WCHAR *)RSTRING_PTR(path), o, g) == -1)
2133-
# else
2134-
if (chown(RSTRING_PTR(path), o, g) == -1)
2135-
# endif
2126+
if (CHOWN(RSTRING_PTR(path), o, g) == -1)
21362127
rb_sys_fail_path(fptr->pathv);
21372128
#else
21382129
if (fchown(fptr->fd, o, g) == -1)
@@ -2292,11 +2283,7 @@ utime_internal(const char *path, void *arg)
22922283
utbuf.modtime = tsp[1].tv_sec;
22932284
utp = &utbuf;
22942285
}
2295-
#ifdef _WIN32
2296-
if (rb_w32_wutime((WCHAR *)path, utp) < 0)
2297-
#else
2298-
if (utime(path, utp) < 0)
2299-
#endif
2286+
if (UTIME(path, utp) < 0)
23002287
utime_failed(path, tsp, v->atime, v->mtime);
23012288
}
23022289

@@ -2388,11 +2375,7 @@ rb_file_s_link(VALUE klass, VALUE from, VALUE to)
23882375
from = rb_str_conv_for_path(from);
23892376
to = rb_str_conv_for_path(to);
23902377

2391-
#ifdef _WIN32
2392-
if (rb_w32_wlink((WCHAR *)RSTRING_PTR(from), (WCHAR *)RSTRING_PTR(to)) < 0)
2393-
#else
23942378
if (link(RSTRING_PTR(from), RSTRING_PTR(to)) < 0)
2395-
#endif
23962379
sys_fail2(from, to);
23972380
return INT2FIX(0);
23982381
}
@@ -2479,11 +2462,7 @@ rb_file_s_readlink(VALUE klass, VALUE path)
24792462
static void
24802463
unlink_internal(const char *path, void *arg)
24812464
{
2482-
#ifdef _WIN32
2483-
if (rb_w32_wunlink((WCHAR *)path) < 0)
2484-
#else
2485-
if (unlink(path) < 0)
2486-
#endif
2465+
if (UNLINK(path) < 0)
24872466
rb_sys_fail(path);
24882467
}
24892468

@@ -2532,11 +2511,7 @@ rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
25322511
#if defined __CYGWIN__
25332512
errno = 0;
25342513
#endif
2535-
#ifdef _WIN32
2536-
if (_wrename((WCHAR *)src, (WCHAR *)dst) < 0) {
2537-
#else
2538-
if (rename(src, dst) < 0) {
2539-
#endif
2514+
if (RENAME(src, dst) < 0) {
25402515
#if defined DOSISH && !defined _WIN32
25412516
switch (errno) {
25422517
case EEXIST:
@@ -3549,19 +3524,20 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
35493524
rb_secure(2);
35503525
pos = NUM2OFFT(len);
35513526
FilePathValue(path);
3527+
path = rb_str_conv_for_path(path);
35523528
#ifdef HAVE_TRUNCATE
3553-
if (truncate(StringValueCStr(path), pos) < 0)
3529+
if (truncate(RSTRING_PTR(path), pos) < 0)
35543530
rb_sys_fail(RSTRING_PTR(path));
35553531
#else /* defined(HAVE_CHSIZE) */
35563532
{
35573533
int tmpfd;
35583534

35593535
# ifdef _WIN32
3560-
if ((tmpfd = open(StringValueCStr(path), O_RDWR)) < 0) {
3536+
if ((tmpfd = rb_w32_wopen((WCHAR *)RSTRING_PTR(path), O_RDWR)) < 0) {
35613537
rb_sys_fail(RSTRING_PTR(path));
35623538
}
35633539
# else
3564-
if ((tmpfd = open(StringValueCStr(path), 0)) < 0) {
3540+
if ((tmpfd = open(RSTRING_PTR(path), 0)) < 0) {
35653541
rb_sys_fail(RSTRING_PTR(path));
35663542
}
35673543
# endif
@@ -3993,7 +3969,8 @@ rb_stat_init(VALUE obj, VALUE fname)
39933969

39943970
rb_secure(2);
39953971
FilePathValue(fname);
3996-
if (stat(StringValueCStr(fname), &st) == -1) {
3972+
fname = rb_str_conv_for_path(fname);
3973+
if (STAT(RSTRING_PTR(fname), &st) == -1) {
39973974
rb_sys_fail(RSTRING_PTR(fname));
39983975
}
39993976
if (DATA_PTR(obj)) {

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