From fc30e8dafa2326ef5f5c05f032606635c329cc12 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 16 Dec 2005 00:13:45 +0000 Subject: [PATCH] Move errno setting code in separate function __atfct_seterrno_2. --- sysdeps/unix/sysv/linux/renameat.c | 87 +++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/sysdeps/unix/sysv/linux/renameat.c b/sysdeps/unix/sysv/linux/renameat.c index 9d94d5f86c..849c67b5d6 100644 --- a/sysdeps/unix/sysv/linux/renameat.c +++ b/sysdeps/unix/sysv/linux/renameat.c @@ -23,6 +23,52 @@ #include +void +attribute_hidden +__atfct_seterrno_2 (int errval, int fd1, const char *buf1, int fd2, + const char *buf2) +{ + if (errval == ENOTDIR && (buf1 != NULL || buf2 != NULL)) + { + /* This can mean either the file descriptor is invalid or + /proc is not mounted. */ + struct stat64 st; + + if (buf1 != NULL) + { + if (__fxstat64 (_STAT_VER, fd1, &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; + goto out; + } + } + + if (buf2 != NULL) + { + if (__fxstat64 (_STAT_VER, fd2, &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; + } + } + + out: + __set_errno (errval); +} + + /* Rename the file OLD relative to OLDFD to NEW relative to NEWFD. */ int renameat (oldfd, old, newfd, new) @@ -76,45 +122,8 @@ renameat (oldfd, old, newfd, new) if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0)) { - int errval = INTERNAL_SYSCALL_ERRNO (result, err); - if (errval == ENOTDIR && (bufnew != NULL || bufold != NULL)) - { - /* This can mean either the file descriptor is invalid or - /proc is not mounted. */ - struct stat64 st; - - if (bufnew != NULL) - { - if (__fxstat64 (_STAT_VER, newfd, &st) != 0) - /* errno is already set correctly. */ - return -1; - - /* 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; - goto out; - } - } - - if (bufold != NULL) - { - if (__fxstat64 (_STAT_VER, oldfd, &st) != 0) - /* errno is already set correctly. */ - return -1; - - /* 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; - } - } - - out: - __set_errno (errval); + __atfct_seterrno_2 (INTERNAL_SYSCALL_ERRNO (result, err), newfd, bufnew, + oldfd, bufold); result = -1; } -- 2.11.4.GIT