[前][次][番号順一覧][スレッド一覧]

ruby-changes:33517

From: nobu <ko1@a...>
Date: Wed, 16 Apr 2014 17:46:33 +0900 (JST)
Subject: [ruby-changes:33517] nobu:r45598 (trunk): util.c: let getcwd allocate buffer

nobu	2014-04-16 17:46:29 +0900 (Wed, 16 Apr 2014)

  New Revision: 45598

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45598

  Log:
    util.c: let getcwd allocate buffer
    
    * util.c (ruby_getcwd): POSIX.1-2001 extends getcwd(3) as it
      allocates the buffer if the argument is NULL.

  Modified files:
    trunk/util.c
Index: util.c
===================================================================
--- util.c	(revision 45597)
+++ util.c	(revision 45598)
@@ -467,19 +467,14 @@ ruby_strdup(const char *str) https://github.com/ruby/ruby/blob/trunk/util.c#L467
     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) https://github.com/ruby/ruby/blob/trunk/util.c#L486
 	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) https://github.com/ruby/ruby/blob/trunk/util.c#L505
 #endif
     return buf;
 }
-#endif
 
 /****************************************************************
  *

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]