diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -467,19 +467,14 @@ ruby_strdup(const char *str) return tmp; } -#ifdef __native_client__ char * ruby_getcwd(void) { +#if defined __native_client__ char *buf = xmalloc(2); strcpy(buf, "."); - return buf; -} -#else -char * -ruby_getcwd(void) -{ -#ifdef HAVE_GETCWD +#elif defined HAVE_GETCWD +# if defined NO_GETCWD_MALLOC int size = 200; char *buf = xmalloc(size); @@ -491,6 +486,12 @@ ruby_getcwd(void) size *= 2; buf = xrealloc(buf, size); } +# else + char *buf, *cwd = getcwd(NULL, 0); + if (!cwd) rb_sys_fail("getcwd"); + buf = ruby_strdup(cwd); /* allocate by xmalloc */ + free(cwd); +# endif #else # ifndef PATH_MAX # define PATH_MAX 8192 @@ -504,7 +505,6 @@ ruby_getcwd(void) #endif return buf; } -#endif /**************************************************************** * |