summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/openat.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-01-22 00:05:30 +0000
committerUlrich Drepper <drepper@redhat.com>2006-01-22 00:05:30 +0000
commitb2680b0331f23ae44f259ecf6c0016e5644c36b6 (patch)
treef778e8d382cea54f837f1add1e21f101cd97d063 /sysdeps/unix/sysv/linux/openat.c
parentc545373264ab75b5cafa6ca8952d11db2228cd97 (diff)
(__atfct_seterrno): Correcty return EBADF for non-existing file descriptors.
Diffstat (limited to 'sysdeps/unix/sysv/linux/openat.c')
-rw-r--r--sysdeps/unix/sysv/linux/openat.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/sysdeps/unix/sysv/linux/openat.c b/sysdeps/unix/sysv/linux/openat.c
index 7423800a13..bcdbada9c9 100644
--- a/sysdeps/unix/sysv/linux/openat.c
+++ b/sysdeps/unix/sysv/linux/openat.c
@@ -35,20 +35,36 @@ void
attribute_hidden
__atfct_seterrno (int errval, int fd, const char *buf)
{
- if (buf != NULL && errval == ENOTDIR)
+ if (buf != NULL)
{
- /* This can mean either the file descriptor is invalid or
- /proc is not mounted. */
struct stat64 st;
- if (__fxstat64 (_STAT_VER, fd, &st) != 0)
- /* errno is already set correctly. */
- return;
-
- /* If /proc is not mounted there is nothing we can do. */
- if (S_ISDIR (st.st_mode)
- && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
- || !S_ISDIR (st.st_mode)))
- errval = ENOSYS;
+
+ if (errval == ENOTDIR)
+ {
+ /* This can mean either the file descriptor is invalid or
+ /proc is not mounted. */
+ if (__fxstat64 (_STAT_VER, fd, &st) != 0)
+ /* errno is already set correctly. */
+ return;
+
+ /* If /proc is not mounted there is nothing we can do. */
+ if (S_ISDIR (st.st_mode)
+ && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+ || !S_ISDIR (st.st_mode)))
+ errval = ENOSYS;
+ }
+ else if (errval == ENOENT)
+ {
+ /* This could mean the file descriptor is not valid. We
+ reuse BUF for the stat call. Find the slash after the
+ file descriptor number. */
+ *(char *) strchr (buf + sizeof "/proc/self/fd", '/') = '\0';
+
+ int e = __xstat64 (_STAT_VER, buf, &st);
+ if ((e == -1 && errno == ENOENT)
+ ||(e == 0 && !S_ISLNK (st.st_mode)))
+ errval = EBADF;
+ }
}
__set_errno (errval);