+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.
#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
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)
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)
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);
/* Either buf was NULL all along, or `realloc' failed but
we still have the original string. */
buf = path;
+# endif
return buf;
}
large enough. */
assert (errno != ERANGE || buf != NULL || size != 0);
+# ifndef NO_ALLOCATION
if (buf == NULL)
free (path);
+# endif
return NULL;
# else
}
else if (errno != ERANGE || buf != NULL)
{
+# ifndef NO_ALLOCATION
if (buf == NULL)
free (path);
+# endif
return NULL;
}
# endif
{
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);
/* Either buf was NULL all along, or `realloc' failed but
we still have the original string. */
buf = path;
+#endif
return buf;
}
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;
}