Use libc_hidden_* for fputs (bug 15105).
[glibc.git] / sysdeps / mach / hurd / linkat.c
blobe2e427cb4d86543ed5104bd2af227b0212742bd2
1 /* Make a link between file names relative to open directories. Hurd version.
2 Copyright (C) 2006-2018 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 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <stddef.h>
22 #include <unistd.h>
23 #include <hurd.h>
24 #include <hurd/fd.h>
27 /* Make a link to FROM relative to FROMFD called TO relative to TOFD. */
28 int
29 linkat (int fromfd, const char *from, int tofd, const char *to, int flags)
31 error_t err;
32 file_t oldfile, linknode, todir;
33 char *toname;
35 /* POSIX says linkat doesn't follow symlinks by default, so pass
36 O_NOLINK. That can be overridden by AT_SYMLINK_FOLLOW in FLAGS. */
37 oldfile = __file_name_lookup_at (fromfd, flags, from, O_NOLINK, 0);
38 if (oldfile == MACH_PORT_NULL)
39 return -1;
41 /* The file_getlinknode RPC returns the port that should be passed to
42 the receiving filesystem (the one containing TODIR) in dir_link. */
44 err = __file_getlinknode (oldfile, &linknode);
45 __mach_port_deallocate (__mach_task_self (), oldfile);
46 if (err)
47 return __hurd_fail (err);
49 todir = __file_name_split_at (tofd, to, &toname);
50 if (todir != MACH_PORT_NULL)
52 err = __dir_link (todir, linknode, toname, 1);
53 __mach_port_deallocate (__mach_task_self (), todir);
55 __mach_port_deallocate (__mach_task_self (), linknode);
56 if (todir == MACH_PORT_NULL)
57 return -1;
59 if (err)
60 return __hurd_fail (err);
61 return 0;