bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] getcwd: fix mingw bugs


From: Eric Blake
Subject: [PATCH] getcwd: fix mingw bugs
Date: Wed, 27 Apr 2011 20:49:40 -0600

On mingw, getcwd(NULL,1) succeeds, even though glibc documents that
with a non-zero size, the allocation will not exceed that many bytes.

On mingw, getcwd has the wrong signature.  However, we don't have
to check for this if anything else triggers the replacement.

Also, fix a type bug that crept into the original getcwd-lgpl commit.

* m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Detect one mingw bug.
* doc/posix-functions/getcwd.texi (getcwd): Document the problems.
* lib/getcwd-lgpl.c (rpl_getcwd): Fix return type.

Signed-off-by: Eric Blake <address@hidden>
---



 ChangeLog                       |    7 +++++++
 doc/posix-functions/getcwd.texi |    7 ++++++-
 lib/getcwd-lgpl.c               |    2 +-
 m4/getcwd.m4                    |   10 ++++++----
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f20299f..8dae3ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-04-27  Eric Blake  <address@hidden>
+
+       getcwd: fix mingw bugs
+       * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Detect one mingw bug.
+       * doc/posix-functions/getcwd.texi (getcwd): Document the problems.
+       * lib/getcwd-lgpl.c (rpl_getcwd): Fix return type.
+
 2011-04-27  Bruno Haible  <address@hidden>

        mkstemps: Ensure declaration on MacOS X 10.5.
diff --git a/doc/posix-functions/getcwd.texi b/doc/posix-functions/getcwd.texi
index a8dba96..1f6dd18 100644
--- a/doc/posix-functions/getcwd.texi
+++ b/doc/posix-functions/getcwd.texi
@@ -11,7 +11,12 @@ getcwd
 @itemize
 @item
 On glibc platforms, @code{getcwd (NULL, n)} allocates memory for the result.
-On other platforms, this call is not allowed.
+On some other platforms, this call is not allowed.  Conversely, mingw fails
+to honor non-zero @code{n}.
address@hidden
+On some platforms, the prototype for @code{getcwd} uses @code{int}
+instead of @code{size_t} for the size argument:
+mingw.
 @end itemize

 Portability problems fixed by Gnulib module @code{getcwd}:
diff --git a/lib/getcwd-lgpl.c b/lib/getcwd-lgpl.c
index a5596f8..53c5562 100644
--- a/lib/getcwd-lgpl.c
+++ b/lib/getcwd-lgpl.c
@@ -53,7 +53,7 @@ rpl_getcwd (char *buf, size_t size)
       if (!buf)
         {
           errno = ENOMEM;
-          return -1;
+          return NULL;
         }
       result = getcwd (buf, size);
       if (!result)
diff --git a/m4/getcwd.m4 b/m4/getcwd.m4
index 55f9372..eb2c9d9 100644
--- a/m4/getcwd.m4
+++ b/m4/getcwd.m4
@@ -6,7 +6,7 @@
 # with or without modifications, as long as this notice is preserved.

 # Written by Paul Eggert.
-# serial 5
+# serial 6

 AC_DEFUN([gl_FUNC_GETCWD_NULL],
   [
@@ -20,7 +20,8 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL],
 #        endif
 ]], [[
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* mingw cwd does not start with '/', but getcwd does allocate.  */
+/* mingw cwd does not start with '/', but getcwd does allocate.
+   However, mingw fails to honor non-zero size.  */
 #else
            if (chdir ("/") != 0)
              return 1;
@@ -36,6 +37,9 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL],
                return 0;
              }
 #endif
+         /* If size is non-zero, allocation must fail if size is too small */
+         if (getcwd (NULL, 1))
+           return 5;
          ]])],
         [gl_cv_func_getcwd_null=yes],
         [gl_cv_func_getcwd_null=no],
@@ -45,8 +49,6 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL],
          *-gnu*)               gl_cv_func_getcwd_null="guessing yes";;
                                # Guess yes on Cygwin.
          cygwin*)              gl_cv_func_getcwd_null="guessing yes";;
-                               # Guess yes on mingw.
-         mingw*)               gl_cv_func_getcwd_null="guessing yes";;
                                # If we don't know, assume the worst.
          *)                    gl_cv_func_getcwd_null="guessing no";;
        esac
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]