Use ioctl_handler_t typedef in Hurd ioctl macros.
[platform/upstream/glibc.git] / hurd / lookup-at.c
1 /* Lookup helper function for Hurd implementation of *at functions.
2    Copyright (C) 2006 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
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.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <hurd.h>
21 #include <hurd/lookup.h>
22 #include <hurd/fd.h>
23 #include <string.h>
24 #include <fcntl.h>
25
26 file_t
27 __file_name_lookup_at (int fd, int at_flags,
28                        const char *file_name, int flags, mode_t mode)
29 {
30   error_t err;
31   file_t result;
32
33   flags |= (at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0;
34   at_flags &= ~AT_SYMLINK_NOFOLLOW;
35   if (at_flags != 0)
36     return __hurd_fail (EINVAL);
37
38   if (fd == AT_FDCWD || file_name[0] == '/')
39     return __file_name_lookup (file_name, flags, mode);
40
41   file_t startdir;
42   error_t use_init_port (int which, error_t (*operate) (mach_port_t))
43     {
44       return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
45               _hurd_ports_use (which, operate));
46     }
47
48   err = HURD_DPORT_USE (fd, (startdir = port,
49                              __hurd_file_name_lookup (&use_init_port,
50                                                       &__getdport, NULL,
51                                                       file_name,
52                                                       flags,
53                                                       mode & ~_hurd_umask,
54                                                       &result)));
55
56   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
57 }
58
59 file_t
60 __file_name_split_at (int fd, const char *file_name, char **name)
61 {
62   error_t err;
63   file_t result;
64
65   if (fd == AT_FDCWD || file_name[0] == '/')
66     return __file_name_split (file_name, name);
67
68   err = __hurd_file_name_split (&_hurd_ports_use, &__getdport, 0,
69                                 file_name, &result, name);
70
71   file_t startdir;
72   error_t use_init_port (int which, error_t (*operate) (mach_port_t))
73   {
74     return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
75             _hurd_ports_use (which, operate));
76   }
77
78   err = HURD_DPORT_USE (fd, (startdir = port,
79                              __hurd_file_name_split (&use_init_port,
80                                                      &__getdport, 0,
81                                                      file_name,
82                                                      &result, name)));
83
84   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
85 }
86
87 file_t
88 __directory_name_split_at (int fd, const char *directory_name, char **name)
89 {
90   error_t err;
91   file_t result;
92
93   if (fd == AT_FDCWD || directory_name[0] == '/')
94     return __directory_name_split (directory_name, name);
95
96   file_t startdir;
97   error_t use_init_port (int which, error_t (*operate) (mach_port_t))
98     {
99       return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
100               _hurd_ports_use (which, operate));
101     }
102
103   err = HURD_DPORT_USE (fd, (startdir = port,
104                              __hurd_directory_name_split (&use_init_port,
105                                                           &__getdport, 0,
106                                                           directory_name,
107                                                           &result, name)));
108
109   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
110 }