Back to index

glibc  2.9
lookup-at.c
Go to the documentation of this file.
00001 /* Lookup helper function for Hurd implementation of *at functions.
00002    Copyright (C) 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <hurd.h>
00021 #include <hurd/lookup.h>
00022 #include <hurd/fd.h>
00023 #include <string.h>
00024 #include <fcntl.h>
00025 
00026 file_t
00027 __file_name_lookup_at (int fd, int at_flags,
00028                      const char *file_name, int flags, mode_t mode)
00029 {
00030   error_t err;
00031   file_t result;
00032 
00033   flags |= (at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0;
00034   at_flags &= ~AT_SYMLINK_NOFOLLOW;
00035   if (at_flags != 0)
00036     return __hurd_fail (EINVAL);
00037 
00038   if (fd == AT_FDCWD || file_name[0] == '/')
00039     return __file_name_lookup (file_name, flags, mode);
00040 
00041   file_t startdir;
00042   error_t use_init_port (int which, error_t (*operate) (mach_port_t))
00043     {
00044       return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
00045              _hurd_ports_use (which, operate));
00046     }
00047 
00048   err = HURD_DPORT_USE (fd, (startdir = port,
00049                           __hurd_file_name_lookup (&use_init_port,
00050                                                 &__getdport, NULL,
00051                                                 file_name,
00052                                                 flags,
00053                                                 mode & ~_hurd_umask,
00054                                                 &result)));
00055 
00056   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
00057 }
00058 
00059 file_t
00060 __file_name_split_at (int fd, const char *file_name, char **name)
00061 {
00062   error_t err;
00063   file_t result;
00064 
00065   if (fd == AT_FDCWD || file_name[0] == '/')
00066     return __file_name_split (file_name, name);
00067 
00068   err = __hurd_file_name_split (&_hurd_ports_use, &__getdport, 0,
00069                             file_name, &result, name);
00070 
00071   file_t startdir;
00072   error_t use_init_port (int which, error_t (*operate) (mach_port_t))
00073   {
00074     return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
00075            _hurd_ports_use (which, operate));
00076   }
00077 
00078   err = HURD_DPORT_USE (fd, (startdir = port,
00079                           __hurd_file_name_split (&use_init_port,
00080                                                &__getdport, 0,
00081                                                file_name,
00082                                                &result, name)));
00083 
00084   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
00085 }
00086 
00087 file_t
00088 __directory_name_split_at (int fd, const char *directory_name, char **name)
00089 {
00090   error_t err;
00091   file_t result;
00092 
00093   if (fd == AT_FDCWD || directory_name[0] == '/')
00094     return __directory_name_split (directory_name, name);
00095 
00096   file_t startdir;
00097   error_t use_init_port (int which, error_t (*operate) (mach_port_t))
00098     {
00099       return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
00100              _hurd_ports_use (which, operate));
00101     }
00102 
00103   err = HURD_DPORT_USE (fd, (startdir = port,
00104                           __hurd_directory_name_split (&use_init_port,
00105                                                    &__getdport, 0,
00106                                                    directory_name,
00107                                                    &result, name)));
00108 
00109   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
00110 }