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/symlink.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/symlink.c')
-rw-r--r-- | sysdeps/mach/hurd/symlink.c | 40 |
1 files changed, 1 insertions, 39 deletions
diff --git a/sysdeps/mach/hurd/symlink.c b/sysdeps/mach/hurd/symlink.c index bb73ea3529..a987e41048 100644 --- a/sysdeps/mach/hurd/symlink.c +++ b/sysdeps/mach/hurd/symlink.c @@ -25,45 +25,7 @@ int __symlink (const char *from, const char *to) { - error_t err; - file_t dir, node; - char *name; - const size_t len = strlen (from) + 1; - char buf[sizeof (_HURD_SYMLINK) + len]; - - /* A symlink is a file whose translator is "/hurd/symlink\0target\0". */ - - memcpy (buf, _HURD_SYMLINK, sizeof (_HURD_SYMLINK)); - memcpy (&buf[sizeof (_HURD_SYMLINK)], from, len); - - dir = __file_name_split (to, &name); - if (dir == MACH_PORT_NULL) - return -1; - - /* Create a new, unlinked node in the target directory. */ - err = __dir_mkfile (dir, O_WRITE, 0777 & ~_hurd_umask, &node); - - if (! err) - { - /* Set the node's translator to make it a symlink. */ - err = __file_set_translator (node, - FS_TRANS_EXCL|FS_TRANS_SET, - FS_TRANS_EXCL|FS_TRANS_SET, 0, - buf, sizeof (_HURD_SYMLINK) + len, - MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND); - - if (! err) - /* Link the node, now a valid symlink, into the target directory. */ - err = __dir_link (dir, node, name, 1); - - __mach_port_deallocate (__mach_task_self (), node); - } - - __mach_port_deallocate (__mach_task_self (), dir); - - if (err) - return __hurd_fail (err); - return 0; + return __symlinkat (from, AT_FDCWD, to); } weak_alias (__symlink, symlink) |