]>
sourceware.org Git - glibc.git/blob - sysdeps/mach/hurd/linkat.c
1 /* Make a link between file names relative to open directories. Hurd version.
2 Copyright (C) 2006-2015 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/>. */
27 /* Make a link to FROM relative to FROMFD called TO relative to TOFD. */
29 linkat (int fromfd
, const char *from
, int tofd
, const char *to
, int flags
)
32 file_t oldfile
, linknode
, todir
;
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
)
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
);
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
)
60 return __hurd_fail (err
);
This page took 0.038588 seconds and 5 git commands to generate.