2006-03-06 07:59:23 +00:00
|
|
|
/* Create a symbolic link named relative to an open directory. Hurd version.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 1991-2023 Free Software Foundation, Inc.
|
2006-03-06 07:59:23 +00:00
|
|
|
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
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2006-03-06 07:59:23 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <hurd.h>
|
|
|
|
#include <hurd/paths.h>
|
|
|
|
#include <hurd/fd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* Make a link to FROM called TO relative to FD. */
|
|
|
|
int
|
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.
2022-09-17 19:47:57 +00:00
|
|
|
__symlinkat (const char *from, int fd, const char *to)
|
2006-03-06 07:59:23 +00:00
|
|
|
{
|
|
|
|
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_at (fd, 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)
|
2012-04-24 20:12:12 +00:00
|
|
|
{
|
|
|
|
/* 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);
|
2006-03-06 07:59:23 +00:00
|
|
|
|
2012-04-24 20:12:12 +00:00
|
|
|
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);
|
|
|
|
}
|
2006-03-06 07:59:23 +00:00
|
|
|
|
|
|
|
__mach_port_deallocate (__mach_task_self (), dir);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return __hurd_fail (err);
|
|
|
|
return 0;
|
|
|
|
}
|
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.
2022-09-17 19:47:57 +00:00
|
|
|
|
|
|
|
weak_alias (__symlinkat, symlinkat)
|