summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-18 05:57:46 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-18 05:57:46 +0000
commitc0e5ea941820076461beabe6c8342b8a47484319 (patch)
treebeeb3efa69c6cfebc596ea43875222f25483b726 /file.c
parent32dc42cf1a248821df7594047bd3fd7822622b32 (diff)
1.1b9_21
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/file.c b/file.c
index 4ea5871f8b..9382d89edb 100644
--- a/file.c
+++ b/file.c
@@ -1108,12 +1108,16 @@ file_s_umask(argc, argv)
}
VALUE
-file_s_expand_path(obj, fname)
- VALUE obj, fname;
+file_s_expand_path(argc, argv)
+ int argc;
+ VALUE *argv;
{
+ VALUE fname, dname;
char *s, *p;
char buf[MAXPATHLEN+2];
+ rb_scan_args(argc, argv, "11", &fname, &dname);
+
s = STR2CSTR(fname);
p = buf;
if (s[0] == '~') {
@@ -1136,7 +1140,6 @@ file_s_expand_path(obj, fname)
struct passwd *pwPtr;
s++;
#endif
-
while (*s && *s != '/') {
*p++ = *s++;
}
@@ -1154,12 +1157,18 @@ file_s_expand_path(obj, fname)
}
}
else if (s[0] != '/') {
+ if (argc == 2) {
+ strcpy(buf, STR2CSTR(dname));
+ }
+ else {
#ifdef HAVE_GETCWD
- getcwd(buf, MAXPATHLEN);
+ getcwd(buf, MAXPATHLEN);
#else
- getwd(buf);
+ getwd(buf);
#endif
+ }
p = &buf[strlen(buf)];
+ while (p > buf && *(p - 1) == '/') p--;
}
*p = '/';
@@ -1628,7 +1637,7 @@ Init_File()
rb_define_singleton_method(cFile, "rename", file_s_rename, 2);
rb_define_singleton_method(cFile, "umask", file_s_umask, -1);
rb_define_singleton_method(cFile, "truncate", file_s_truncate, 2);
- rb_define_singleton_method(cFile, "expand_path", file_s_expand_path, 1);
+ rb_define_singleton_method(cFile, "expand_path", file_s_expand_path, -1);
rb_define_singleton_method(cFile, "basename", file_s_basename, -1);
rb_define_singleton_method(cFile, "dirname", file_s_dirname, 1);