install-reloc: Support multi-binary installation.
[gnulib.git] / tests / test-getcwd-lgpl.c
index 67ee66d..e3e7b7a 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of getcwd() function.
-   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+   Copyright (C) 2009-2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -65,12 +65,22 @@ main (int argc, char **argv)
     pwd2 = malloc (len + 2);
     for ( ; i <= len; i++)
       {
+        char *tmp;
         errno = 0;
         ASSERT (getcwd (pwd2, i) == NULL);
         ASSERT (errno == ERANGE);
+        /* Allow either glibc or BSD behavior, since POSIX allows both.  */
         errno = 0;
-        ASSERT (getcwd (NULL, i) == NULL);
-        ASSERT (errno == ERANGE);
+        tmp = getcwd (NULL, i);
+        if (tmp)
+          {
+            ASSERT (strcmp (pwd1, tmp) == 0);
+            free (tmp);
+          }
+        else
+          {
+            ASSERT (errno == ERANGE);
+          }
       }
     ASSERT (getcwd (pwd2, len + 1) == pwd2);
     pwd2[len] = '/';
@@ -80,6 +90,11 @@ main (int argc, char **argv)
   ASSERT (strstr (pwd2, "/../") == NULL);
   ASSERT (strstr (pwd2 + 1 + (pwd2[1] == '/'), "//") == NULL);
 
+  /* Validate a POSIX requirement on size.  */
+  errno = 0;
+  ASSERT (getcwd(pwd2, 0) == NULL);
+  ASSERT (errno == EINVAL);
+
   free (pwd1);
   free (pwd2);