mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* file.c (strrdirsep): multi-byte pathname and DOSish separater
supprot. originally comes from Patrick Cheng. [new] * file.c (rb_file_s_basename, rb_file_s_dirname): use strrdirsep(). comes from Patrick Cheng. * file.c (is_absolute_path): restricted in DOSish absolute path with drive letter, and UNC support. originally comes from Patrick Cheng. * file.c (getcwd): define macro using getwd() unless provided. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e54216b740
commit
4a74d867af
2 changed files with 54 additions and 17 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
Tue Jul 24 23:10:47 2001 Nobuyoshi.Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
|
* file.c (strrdirsep): multi-byte pathname and DOSish separater
|
||||||
|
supprot. originally comes from Patrick Cheng. [new]
|
||||||
|
|
||||||
|
* file.c (rb_file_s_basename, rb_file_s_dirname): use
|
||||||
|
strrdirsep(). comes from Patrick Cheng.
|
||||||
|
|
||||||
|
* file.c (is_absolute_path): restricted in DOSish absolute path
|
||||||
|
with drive letter, and UNC support. originally comes from
|
||||||
|
Patrick Cheng.
|
||||||
|
|
||||||
|
* file.c (getcwd): define macro using getwd() unless provided.
|
||||||
|
|
||||||
Tue Jul 24 19:23:15 2001 Akinori MUSHA <knu@iDaemons.org>
|
Tue Jul 24 19:23:15 2001 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* ext/extmk.rb.in, lib/mkmf.rb: dig the target subdirectory for
|
* ext/extmk.rb.in, lib/mkmf.rb: dig the target subdirectory for
|
||||||
|
@ -16,7 +30,7 @@ Sun Jul 22 21:16:43 2001 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
Sat Jul 21 09:40:10 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
Sat Jul 21 09:40:10 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
* io.c (io_fread): use fread(3) if PENDING_COUND is available.
|
* io.c (io_fread): use fread(3) if PENDING_COUNT is available.
|
||||||
|
|
||||||
Fri Jul 20 22:55:01 2001 Akinori MUSHA <knu@iDaemons.org>
|
Fri Jul 20 22:55:01 2001 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
|
55
file.c
55
file.c
|
@ -1290,11 +1290,41 @@ rb_file_s_umask(argc, argv)
|
||||||
return INT2FIX(omask);
|
return INT2FIX(omask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_GETCWD
|
||||||
|
#define getcwd(buf, len) ((void)(len), getwd(buf))
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined DOSISH
|
#if defined DOSISH
|
||||||
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
||||||
#else
|
#else
|
||||||
#define isdirsep(x) ((x) == '/')
|
#define isdirsep(x) ((x) == '/')
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
|
||||||
|
# if defined(DJGPP)
|
||||||
|
# define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
|
||||||
|
# else
|
||||||
|
# define CharNext(p) ((p) + 1)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static char *
|
||||||
|
strrdirsep(path)
|
||||||
|
char *path;
|
||||||
|
{
|
||||||
|
char *last = NULL;
|
||||||
|
#ifdef DOSISH
|
||||||
|
if (ISALPHA(path[0]) && path[1] == ':') path += 2;
|
||||||
|
#endif
|
||||||
|
while (*path) {
|
||||||
|
if (isdirsep(*path)) {
|
||||||
|
last = path++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path = CharNext(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_file_s_expand_path(argc, argv)
|
rb_file_s_expand_path(argc, argv)
|
||||||
|
@ -1366,11 +1396,7 @@ rb_file_s_expand_path(argc, argv)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tainted = 1;
|
tainted = 1;
|
||||||
#ifdef HAVE_GETCWD
|
|
||||||
getcwd(buf, MAXPATHLEN);
|
getcwd(buf, MAXPATHLEN);
|
||||||
#else
|
|
||||||
getwd(buf);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
p = &buf[strlen(buf)];
|
p = &buf[strlen(buf)];
|
||||||
while (p > buf && *(p - 1) == '/') p--;
|
while (p > buf && *(p - 1) == '/') p--;
|
||||||
|
@ -1476,7 +1502,7 @@ rb_file_s_basename(argc, argv)
|
||||||
ext = StringValuePtr(fext);
|
ext = StringValuePtr(fext);
|
||||||
}
|
}
|
||||||
name = StringValuePtr(fname);
|
name = StringValuePtr(fname);
|
||||||
p = strrchr(name, '/');
|
p = strrdirsep(name);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
if (NIL_P(fext) || !(f = rmext(name, ext)))
|
if (NIL_P(fext) || !(f = rmext(name, ext)))
|
||||||
return fname;
|
return fname;
|
||||||
|
@ -1503,7 +1529,7 @@ rb_file_s_dirname(klass, fname)
|
||||||
VALUE dirname;
|
VALUE dirname;
|
||||||
|
|
||||||
name = StringValuePtr(fname);
|
name = StringValuePtr(fname);
|
||||||
p = strrchr(name, '/');
|
p = strrdirsep(name);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return rb_str_new2(".");
|
return rb_str_new2(".");
|
||||||
}
|
}
|
||||||
|
@ -2136,11 +2162,12 @@ static int
|
||||||
is_absolute_path(path)
|
is_absolute_path(path)
|
||||||
const char *path;
|
const char *path;
|
||||||
{
|
{
|
||||||
|
#ifdef DOSISH
|
||||||
|
if (ISALPHA(path[0]) && path[1] == ':' && isdirsep(path[2])) return 1;
|
||||||
|
if (isdirsep(path[0]) && isdirsep(path[1])) return 1;
|
||||||
|
#else
|
||||||
if (path[0] == '/') return 1;
|
if (path[0] == '/') return 1;
|
||||||
# if defined DOSISH
|
#endif
|
||||||
if (path[0] == '\\') return 1;
|
|
||||||
if (strlen(path) > 2 && path[1] == ':') return 1;
|
|
||||||
# endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2155,11 +2182,7 @@ path_check_1(path)
|
||||||
if (!is_absolute_path(path)) {
|
if (!is_absolute_path(path)) {
|
||||||
char buf[MAXPATHLEN+1];
|
char buf[MAXPATHLEN+1];
|
||||||
|
|
||||||
#ifdef HAVE_GETCWD
|
|
||||||
if (getcwd(buf, MAXPATHLEN) == 0) return 0;
|
if (getcwd(buf, MAXPATHLEN) == 0) return 0;
|
||||||
#else
|
|
||||||
if (getwd(buf) == 0) return 0;
|
|
||||||
#endif
|
|
||||||
strncat(buf, "/", MAXPATHLEN);
|
strncat(buf, "/", MAXPATHLEN);
|
||||||
strncat(buf, path, MAXPATHLEN);
|
strncat(buf, path, MAXPATHLEN);
|
||||||
buf[MAXPATHLEN] = '\0';
|
buf[MAXPATHLEN] = '\0';
|
||||||
|
@ -2167,10 +2190,10 @@ path_check_1(path)
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (stat(path, &st) == 0 && (st.st_mode & 002)) {
|
if (stat(path, &st) == 0 && (st.st_mode & 002)) {
|
||||||
if (p) *p = '/';
|
if (p) *p = '/';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s = strrchr(path, '/');
|
s = strrdirsep(path);
|
||||||
if (p) *p = '/';
|
if (p) *p = '/';
|
||||||
if (!s || s == path) return 1;
|
if (!s || s == path) return 1;
|
||||||
p = s;
|
p = s;
|
||||||
|
|
Loading…
Reference in a new issue