Back to index

glibc  2.9
openat.c
Go to the documentation of this file.
00001 /* Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <fcntl.h>
00021 #include <stdarg.h>
00022 #include <stddef.h>
00023 #include <stdio.h>
00024 #include <sys/stat.h>
00025 
00026 /* Open FILE with access OFLAG.  Interpret relative paths relative to
00027    the directory associated with FD.  If OFLAG includes O_CREAT, a
00028    third argument is the file protection.  */
00029 int
00030 __openat (fd, file, oflag)
00031      int fd;
00032      const char *file;
00033      int oflag;
00034 {
00035   int mode;
00036 
00037   if (file == NULL)
00038     {
00039       __set_errno (EINVAL);
00040       return -1;
00041     }
00042 
00043   if (fd != AT_FDCWD && file[0] != '/')
00044     {
00045       /* Check FD is associated with a directory.  */
00046       struct stat64 st;
00047       if (__fxstat64 (_STAT_VER, fd, &st) != 0)
00048        return -1;
00049 
00050       if (!S_ISDIR (st.st_mode))
00051        {
00052          __set_errno (ENOTDIR);
00053          return -1;
00054        }
00055     }
00056 
00057   if (oflag & O_CREAT)
00058     {
00059       va_list arg;
00060       va_start (arg, oflag);
00061       mode = va_arg (arg, int);
00062       va_end (arg);
00063     }
00064 
00065   __set_errno (ENOSYS);
00066   return -1;
00067 }
00068 libc_hidden_def (__openat)
00069 weak_alias (__openat, openat)
00070 stub_warning (openat)
00071 
00072 
00073 int
00074 __openat_2 (fd, file, oflag)
00075      int fd;
00076      const char *file;
00077      int oflag;
00078 {
00079   if (oflag & O_CREAT)
00080     __fortify_fail ("invalid openat call: O_CREAT without mode");
00081 
00082   return __openat (fd, file, oflag);
00083 }
00084 stub_warning (__openat_2)
00085 
00086 #include <stub-tag.h>