summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-07 09:01:34 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-07 09:01:34 +0000
commit2f12c07c76c38a377e98555f1af738a8aa12f112 (patch)
tree0ca8dfde034e3a4837a4d4c7b5536a0bf3540e03 /dir.c
parent566c793d9b032ae1bc03340a10c4b5d1dcd116a7 (diff)
* dir.c (my_getcwd): do not rely on MAXPATHLEN.
* eval.c (rb_yield_0): should not call rb_f_block_given_p(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/dir.c b/dir.c
index 621418b797..9feb48faf0 100644
--- a/dir.c
+++ b/dir.c
@@ -419,20 +419,29 @@ dir_s_chdir(argc, argv, obj)
return INT2FIX(0);
}
+static char *
+my_getcwd()
+{
+ int size = MAXPATHLEN;
+ char *buf = xmalloc(size);
+
+ while (!getcwd(buf, size)) {
+ if (errno != ERANGE) rb_sys_fail(buf);
+ size *= 2;
+ buf = xrealloc(buf, size);
+ }
+ return buf;
+}
+
static VALUE
dir_s_getwd(dir)
VALUE dir;
{
- char path[MAXPATHLEN];
-
-#ifdef HAVE_GETCWD
- if (getcwd(path, sizeof(path)) == 0) rb_sys_fail(path);
-#else
- extern char *getwd();
- if (getwd(path) == 0) rb_sys_fail(path);
-#endif
+ char *path = my_getcwd();
+ VALUE cwd = rb_tainted_str_new2(path);
- return rb_tainted_str_new2(path);
+ free(path);
+ return cwd;
}
static VALUE