diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-09-17 19:47:57 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-09-17 19:58:30 +0000 |
commit | 7ae60af75b78f408420512c58fd5a08ca7a88bad (patch) | |
tree | 51ef7f542c448a0717e69029f1b9dd164933c7bd /sysdeps/mach/hurd/readlink.c | |
parent | 6841aed6c4abde1aa7015348496c86cadc227a1f (diff) | |
download | glibc-7ae60af75b78f408420512c58fd5a08ca7a88bad.tar glibc-7ae60af75b78f408420512c58fd5a08ca7a88bad.tar.gz glibc-7ae60af75b78f408420512c58fd5a08ca7a88bad.tar.bz2 glibc-7ae60af75b78f408420512c58fd5a08ca7a88bad.zip |
hurd: Factorize at/non-at functions
Non-at functions can be implemented by just calling the corresponding at
function with AT_FDCWD and zero at_flags.
In the linkat case, the at behavior is different (O_NOLINK), so this introduces
__linkat_common to pass O_NOLINK as appropriate.
lstat functions can also be implemented with fstatat by adding
__fstatat64_common which takes a flags parameter in addition to the at_flags
parameter,
In the end this factorizes chmod, chown, link, lstat64, mkdir, readlink,
rename, stat64, symlink, unlink, utimes.
This also makes __lstat, __lxstat64, __stat and __xstat64 directly use
__fstatat64_common instead of __lstat64 or __stat64.
Diffstat (limited to 'sysdeps/mach/hurd/readlink.c')
-rw-r--r-- | sysdeps/mach/hurd/readlink.c | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/sysdeps/mach/hurd/readlink.c b/sysdeps/mach/hurd/readlink.c index 34f132cb92..ddad3d2919 100644 --- a/sysdeps/mach/hurd/readlink.c +++ b/sysdeps/mach/hurd/readlink.c @@ -27,46 +27,6 @@ ssize_t __readlink (const char *file_name, char *buf, size_t len) { - error_t err; - file_t file_stat; - struct stat64 st; - - file_stat = __file_name_lookup (file_name, O_NOLINK, 0); - if (file_stat == MACH_PORT_NULL) - return -1; - - err = __io_stat (file_stat, &st); - if (! err) - if (S_ISLNK (st.st_mode)) - { - enum retry_type doretry; - char retryname[1024]; - file_t file; - char *rbuf = buf; - - err = __dir_lookup (file_stat, "", O_READ | O_NOLINK, 0, &doretry, retryname, &file); - if (! err && (doretry != FS_RETRY_NORMAL || retryname[0] != '\0')) - err = EGRATUITOUS; - if (! err) - { - err = __io_read (file, &rbuf, &len, 0, len); - if (!err && rbuf != buf) - { - memcpy (buf, rbuf, len); - __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len); - } - - __mach_port_deallocate (__mach_task_self (), file); - } - } - else - err = EINVAL; - - __mach_port_deallocate (__mach_task_self (), file_stat); - - if (err) - return __hurd_fail (err); - else - return len; + return __readlinkat (AT_FDCWD, file_name, buf, len); } weak_alias (__readlink, readlink) |