1 /* Make a link between file names relative to open directories. Hurd version.
2 Copyright (C) 2006-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
26 #include <linkat_common.h>
28 /* Make a link to FROM relative to FROMFD called TO relative to TOFD. */
30 __linkat_common (int fromfd
, const char *from
, int tofd
, const char *to
, int at_flags
, int flags
)
33 file_t oldfile
, linknode
, todir
;
36 oldfile
= __file_name_lookup_at (fromfd
, at_flags
, from
, flags
, 0);
37 if (oldfile
== MACH_PORT_NULL
)
40 /* The file_getlinknode RPC returns the port that should be passed to
41 the receiving filesystem (the one containing TODIR) in dir_link. */
43 err
= __file_getlinknode (oldfile
, &linknode
);
44 __mach_port_deallocate (__mach_task_self (), oldfile
);
46 return __hurd_fail (err
);
48 todir
= __file_name_split_at (tofd
, to
, &toname
);
49 if (todir
!= MACH_PORT_NULL
)
51 err
= __dir_link (todir
, linknode
, toname
, 1);
52 __mach_port_deallocate (__mach_task_self (), todir
);
54 __mach_port_deallocate (__mach_task_self (), linknode
);
55 if (todir
== MACH_PORT_NULL
)
59 return __hurd_fail (err
);
64 __linkat (int fromfd
, const char *from
, int tofd
, const char *to
, int at_flags
)
66 /* POSIX says linkat doesn't follow symlinks by default, so pass
67 O_NOLINK. That can be overridden by AT_SYMLINK_FOLLOW in FLAGS. */
68 return __linkat_common (fromfd
, from
, tofd
, to
, at_flags
, O_NOLINK
);
70 weak_alias (__linkat
, linkat
)