@@ -76,6 +76,8 @@ extern int __lchown (const char *__file, __uid_t __owner,
__gid_t __group);
extern int __chdir (const char *__path) attribute_hidden;
extern int __fchdir (int __fd) attribute_hidden;
+extern char *__getcwd_generic (char *__buf, size_t __size) attribute_hidden;
+extern char *__getcwd_system (char *__buf, size_t __size) attribute_hidden;
extern char *__getcwd (char *__buf, size_t __size);
libc_hidden_proto (__getcwd)
extern int __rmdir (const char *__path) attribute_hidden;
@@ -46,7 +46,7 @@ routines := \
close dup dup2 dup3 pipe pipe2 \
creat creat64 \
chdir fchdir \
- getcwd getwd getdirname \
+ getcwd getwd getcwd-system getdirname \
chown fchown lchown fchownat \
ttyname ttyname_r isatty \
link linkat symlink symlinkat readlink readlinkat \
similarity index 99%
rename from sysdeps/posix/getcwd.c
rename to io/getcwd-generic.c
@@ -153,7 +153,7 @@ getcwd_nothrow (char *buf, size_t size)
if BUF is NULL, an array is allocated with 'malloc'; the array is SIZE
bytes long, unless SIZE == 0, in which case it is as big as necessary. */
-GETCWD_RETURN_TYPE
+char *
__getcwd_generic (char *buf, size_t size)
{
/* Lengths of big file name components and entire file names, and a
@@ -486,8 +486,3 @@ __getcwd_generic (char *buf, size_t size)
}
return NULL;
}
-
-#if defined _LIBC && !defined GETCWD_RETURN_TYPE
-libc_hidden_def (__getcwd)
-weak_alias (__getcwd, getcwd)
-#endif
new file mode 100644
@@ -0,0 +1,28 @@
+/* Architecture specific getcwd implementation. Generic implementation.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <unistd.h>
+
+/* This function is called by the generic 'getcwd' implementation to allow
+ a system to implement if the it provides a faster or simpler way to obtain
+ the current direction (e.g. through a syscall). */
+char *
+__getcwd_system (char *buf, size_t size)
+{
+ return NULL;
+}
@@ -19,6 +19,11 @@
#include <unistd.h>
#include <stddef.h>
+/* The rtld does not need to handle path larger than PATH_MAX. */
+#if !IS_IN(rtld)
+#include <getcwd-generic.c>
+#endif
+
/* Get the pathname of the current working directory,
and put it in SIZE bytes of BUF. Returns NULL if the
directory couldn't be determined or SIZE was too small.
@@ -29,11 +34,12 @@
char *
__getcwd (char *buf, size_t size)
{
- __set_errno (ENOSYS);
- return NULL;
+ char *r = __getcwd_system (buf, size);
+#if !IS_IN(rtld)
+ if (r == NULL)
+ r = __getcwd_generic (buf, size);
+#endif
+ return r;
}
libc_hidden_def (__getcwd)
weak_alias (__getcwd, getcwd)
-
-stub_warning (__getcwd)
-stub_warning (getcwd)
@@ -281,8 +281,7 @@ tests += tst-fallocate tst-fallocate64 tst-o_path-locks
endif
ifeq ($(subdir),elf)
-sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir \
- dl-fxstatat64
+sysdep-rtld-routines += dl-brk dl-sbrk dl-openat64 dl-opendir
libof-lddlibc4 = lddlibc4
deleted file mode 100644
@@ -1 +0,0 @@
-#include "fxstatat.c"
deleted file mode 100644
@@ -1 +0,0 @@
-#include <fxstatat64.c>
deleted file mode 100644
@@ -1 +0,0 @@
-#include "getcwd.c"
similarity index 76%
rename from sysdeps/unix/sysv/linux/getcwd.c
rename to sysdeps/unix/sysv/linux/getcwd-system.c
@@ -17,25 +17,13 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
-#include <limits.h>
+#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-
#include <sysdep.h>
-#include <sys/syscall.h>
-
-#if !IS_IN (rtld)
-/* The generic implementation is used for valid paths larger than
- PATH_MAX (where the syscall returns a positive value with errno
- set to ENAMETOOLONG). */
-#define GETCWD_RETURN_TYPE static char *
-#include <sysdeps/posix/getcwd.c>
-#endif
char *
-__getcwd (char *buf, size_t size)
+__getcwd_system (char *buf, size_t size)
{
char *r = NULL;
int len;
@@ -73,12 +61,5 @@ __getcwd (char *buf, size_t size)
if (len > 0 && r[0] == '/')
return r;
-#if !IS_IN (rtld)
- if (len >=0 || errno == ENAMETOOLONG)
- return __getcwd_generic (buf, size);
-#endif
-
return NULL;
}
-libc_hidden_def (__getcwd)
-weak_alias (__getcwd, getcwd)
deleted file mode 100644
@@ -1 +0,0 @@
-#include "fxstatat.c"
deleted file mode 100644
@@ -1 +0,0 @@
-#include "fxstatat.c"