]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update.
authorUlrich Drepper <drepper@redhat.com>
Sat, 20 Sep 2003 01:06:31 +0000 (01:06 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 20 Sep 2003 01:06:31 +0000 (01:06 +0000)
2003-09-19  Ulrich Drepper  <drepper@redhat.com>

* sysdeps/unix/sysv/linux/getcwd.c (__getcwd): If compiled for
ld.so, don't include NULL buffer pointer handling.

ChangeLog
sysdeps/unix/sysv/linux/getcwd.c

index 6a2b729980d7916ca2c203a113f078d5589b084c..8773c675f3480f9985098b1e8d2899036f834443 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-09-19  Ulrich Drepper  <drepper@redhat.com>
+
+       * sysdeps/unix/sysv/linux/getcwd.c (__getcwd): If compiled for
+       ld.so, don't include NULL buffer pointer handling.
+
 2003-09-19  Jakub Jelinek  <jakub@redhat.com>
 
        * dlfcn/dlopen.c (dlopen): Add static_link_warning.
index b14e5beb087bddc75f7b985d5334f4f25cd63df4..9695d8a035e9035aa719bae9ded8272ab3931309 100644 (file)
 #include "kernel-features.h"
 
 
+/* If we compile the file for use in ld.so we don't need the feature
+   that getcwd() allocates the buffers itself.  */
+#ifdef IS_IN_rtld
+# define NO_ALLOCATION 1
+#endif
+
+
 #if __ASSUME_GETCWD_SYSCALL > 0
 /* Kernel 2.1.92 introduced a third way to get the current working
    directory: a syscall.  We've got to be careful that even when
@@ -65,11 +72,12 @@ __getcwd (char *buf, size_t size)
   char *path;
   int n;
   char *result;
-  size_t alloc_size = size;
 
   if (no_syscall_getcwd && !have_new_dcache)
     return generic_getcwd (buf, size);
 
+#ifndef NO_ALLOCATION
+  size_t alloc_size = size;
   if (size == 0)
     {
       if (buf != NULL)
@@ -81,14 +89,17 @@ __getcwd (char *buf, size_t size)
       alloc_size = PATH_MAX;
     }
 
-  if (buf != NULL)
-    path = buf;
-  else
+  if (buf == NULL)
     {
       path = malloc (alloc_size);
       if (path == NULL)
        return NULL;
     }
+  else
+#else
+# define alloc_size size
+#endif
+    path = buf;
 
 #if defined __NR_getcwd || __LINUX_GETCWD_SYSCALL > 0
   if (!no_syscall_getcwd)
@@ -98,6 +109,7 @@ __getcwd (char *buf, size_t size)
       retval = INLINE_SYSCALL (getcwd, 2, CHECK_STRING (path), alloc_size);
       if (retval >= 0)
        {
+# ifndef NO_ALLOCATION
          if (buf == NULL && size == 0)
            /* Ensure that the buffer is only as large as necessary.  */
            buf = realloc (path, (size_t) retval);
@@ -106,6 +118,7 @@ __getcwd (char *buf, size_t size)
            /* Either buf was NULL all along, or `realloc' failed but
               we still have the original string.  */
            buf = path;
+# endif
 
          return buf;
        }
@@ -116,8 +129,10 @@ __getcwd (char *buf, size_t size)
         large enough.  */
       assert (errno != ERANGE || buf != NULL || size != 0);
 
+#  ifndef NO_ALLOCATION
       if (buf == NULL)
        free (path);
+#  endif
 
       return NULL;
 # else
@@ -128,8 +143,10 @@ __getcwd (char *buf, size_t size)
        }
       else if (errno != ERANGE || buf != NULL)
        {
+#  ifndef NO_ALLOCATION
          if (buf == NULL)
            free (path);
+#  endif
          return NULL;
        }
 # endif
@@ -143,12 +160,15 @@ __getcwd (char *buf, size_t size)
        {
          if ((size_t) n >= alloc_size - 1)
            {
+#ifndef NO_ALLOCATION
              if (buf == NULL)
                free (path);
+#endif
              return NULL;
            }
 
          path[n] = '\0';
+#ifndef NO_ALLOCATION
          if (buf == NULL && size == 0)
            /* Ensure that the buffer is only as large as necessary.  */
            buf = realloc (path, (size_t) n + 1);
@@ -156,6 +176,7 @@ __getcwd (char *buf, size_t size)
            /* Either buf was NULL all along, or `realloc' failed but
               we still have the original string.  */
            buf = path;
+#endif
 
          return buf;
        }
@@ -172,17 +193,21 @@ __getcwd (char *buf, size_t size)
     have_new_dcache = 0;
 #endif
 
+#ifndef NO_ALLOCATION
   /* Don't put restrictions on the length of the path unless the user does.  */
   if (size == 0)
     {
       free (path);
       path = NULL;
     }
+#endif
 
   result = generic_getcwd (path, size);
 
+#ifndef NO_ALLOCATION
   if (result == NULL && buf == NULL && size != 0)
     free (path);
+#endif
 
   return result;
 }