summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/util.c b/util.c
index 456704492a..cb0b4912f4 100644
--- a/util.c
+++ b/util.c
@@ -636,14 +636,25 @@ ruby_strdup(str)
char *
ruby_getcwd()
{
+#ifdef HAVE_GETCWD
int size = 200;
char *buf = xmalloc(size);
while (!getcwd(buf, size)) {
- if (errno != ERANGE) rb_sys_fail(0);
+ if (errno != ERANGE) rb_sys_fail("getcwd");
size *= 2;
buf = xrealloc(buf, size);
}
+#else
+# ifndef PATH_MAX
+# define PATH_MAX 8192
+# endif
+ char *buf = xmalloc(PATH_MAX+1);
+
+ if (!getwd(buf)) {
+ rb_sys_fail("getwd");
+ }
+#endif
return buf;
}