Back to index

glibc  2.9
open.c
Go to the documentation of this file.
00001 /* Copyright (C) 1992,93,94,95,97,2000,2002,2006 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 <stdio.h>
00023 #include <hurd.h>
00024 #include <hurd/fd.h>
00025 
00026 /* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
00027    a third argument is the file protection.  */
00028 int
00029 __libc_open (const char *file, int oflag, ...)
00030 {
00031   mode_t mode;
00032   io_t port;
00033 
00034   if (oflag & O_CREAT)
00035     {
00036       va_list arg;
00037       va_start (arg, oflag);
00038       mode = va_arg (arg, mode_t);
00039       va_end (arg);
00040     }
00041   else
00042     mode = 0;
00043 
00044   port = __file_name_lookup (file, oflag, mode);
00045   if (port == MACH_PORT_NULL)
00046     return -1;
00047 
00048   return _hurd_intern_fd (port, oflag, 1);
00049 }
00050 
00051 libc_hidden_def (__libc_open)
00052 weak_alias (__libc_open, __open)
00053 libc_hidden_weak (__open)
00054 weak_alias (__libc_open, open)
00055 
00056 int
00057 __open_2 (file, oflag)
00058      const char *file;
00059      int oflag;
00060 {
00061   if (oflag & O_CREAT)
00062     __fortify_fail ("invalid open call: O_CREAT without mode");
00063 
00064   return __open (file, oflag);
00065 }
00066 
00067 /* open64 is just the same as open for us.  */
00068 weak_alias (__libc_open, __libc_open64)
00069 weak_alias (__libc_open, __open64)
00070 libc_hidden_weak (_open64)
00071 weak_alias (__libc_open, open64)
00072 strong_alias (__open_2, __open64_2)