Back to index

nagios-plugins  1.4.16
open-safer.c
Go to the documentation of this file.
00001 /* Invoke open, but avoid some glitches.
00002 
00003    Copyright (C) 2005-2006, 2008-2010 Free Software Foundation, Inc.
00004 
00005    This program is free software: you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3 of the License, or
00008    (at your option) any later version.
00009 
00010    This program 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
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00017 
00018 /* Written by Paul Eggert.  */
00019 
00020 #include <config.h>
00021 
00022 #include "fcntl-safer.h"
00023 
00024 #include <fcntl.h>
00025 #include <stdarg.h>
00026 #include "unistd-safer.h"
00027 
00028 int
00029 open_safer (char const *file, int flags, ...)
00030 {
00031   mode_t mode = 0;
00032 
00033   if (flags & O_CREAT)
00034     {
00035       va_list ap;
00036       va_start (ap, flags);
00037 
00038       /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
00039          creates crashing code when 'mode_t' is smaller than 'int'.  */
00040       mode = va_arg (ap, PROMOTED_MODE_T);
00041 
00042       va_end (ap);
00043     }
00044 
00045   return fd_safer (open (file, flags, mode));
00046 }