From 4a74d867afe583cbe73d4b482f1430cb92ad1a18 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 24 Jul 2001 15:11:02 +0000 Subject: * 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 --- ChangeLog | 16 +++++++++++++++- file.c | 55 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99d1536412..bb3d907a4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Tue Jul 24 23:10:47 2001 Nobuyoshi.Nakada + + * 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 * 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 Sat Jul 21 09:40:10 2001 Nobuyoshi Nakada - * 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 diff --git a/file.c b/file.c index e508cf0242..e7271defe5 100644 --- a/file.c +++ b/file.c @@ -1290,11 +1290,41 @@ rb_file_s_umask(argc, argv) return INT2FIX(omask); } +#ifndef HAVE_GETCWD +#define getcwd(buf, len) ((void)(len), getwd(buf)) +#endif + #if defined DOSISH #define isdirsep(x) ((x) == '/' || (x) == '\\') #else #define isdirsep(x) ((x) == '/') #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 rb_file_s_expand_path(argc, argv) @@ -1366,11 +1396,7 @@ rb_file_s_expand_path(argc, argv) } else { tainted = 1; -#ifdef HAVE_GETCWD getcwd(buf, MAXPATHLEN); -#else - getwd(buf); -#endif } p = &buf[strlen(buf)]; while (p > buf && *(p - 1) == '/') p--; @@ -1476,7 +1502,7 @@ rb_file_s_basename(argc, argv) ext = StringValuePtr(fext); } name = StringValuePtr(fname); - p = strrchr(name, '/'); + p = strrdirsep(name); if (!p) { if (NIL_P(fext) || !(f = rmext(name, ext))) return fname; @@ -1503,7 +1529,7 @@ rb_file_s_dirname(klass, fname) VALUE dirname; name = StringValuePtr(fname); - p = strrchr(name, '/'); + p = strrdirsep(name); if (!p) { return rb_str_new2("."); } @@ -2136,11 +2162,12 @@ static int is_absolute_path(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 defined DOSISH - if (path[0] == '\\') return 1; - if (strlen(path) > 2 && path[1] == ':') return 1; -# endif +#endif return 0; } @@ -2155,11 +2182,7 @@ path_check_1(path) if (!is_absolute_path(path)) { char buf[MAXPATHLEN+1]; -#ifdef HAVE_GETCWD if (getcwd(buf, MAXPATHLEN) == 0) return 0; -#else - if (getwd(buf) == 0) return 0; -#endif strncat(buf, "/", MAXPATHLEN); strncat(buf, path, MAXPATHLEN); buf[MAXPATHLEN] = '\0'; @@ -2167,10 +2190,10 @@ path_check_1(path) } for (;;) { if (stat(path, &st) == 0 && (st.st_mode & 002)) { - if (p) *p = '/'; + if (p) *p = '/'; return 0; } - s = strrchr(path, '/'); + s = strrdirsep(path); if (p) *p = '/'; if (!s || s == path) return 1; p = s; -- cgit v1.2.3