Extra files from coreutils required for getloadavg.c to compile

on Tru64 (Ciro Iriarte - 1520331)


git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1446 f882894a-f735-0410-b71e-b25c423dba1c
This commit is contained in:
Ton Voon 2006-07-11 12:38:09 +00:00
parent 6267f10367
commit df23fd7526
12 changed files with 369 additions and 0 deletions

33
lib/creat-safer.c Normal file
View file

@ -0,0 +1,33 @@
/* Invoke creat, but avoid some glitches.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Jim Meyering. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "fcntl-safer.h"
#include <fcntl.h>
#include "unistd-safer.h"
int
creat_safer (char const *file, mode_t mode)
{
return fd_safer (creat (file, mode));
}

46
lib/dup-safer.c Normal file
View file

@ -0,0 +1,46 @@
/* Invoke dup, but avoid some glitches.
Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "unistd-safer.h"
#include <fcntl.h>
#include <unistd.h>
#ifndef STDERR_FILENO
# define STDERR_FILENO 2
#endif
/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
STDERR_FILENO. */
int
dup_safer (int fd)
{
#ifdef F_DUPFD
return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
#else
/* fd_safer calls us back, but eventually the recursion unwinds and
does the right thing. */
return fd_safer (dup (fd));
#endif
}

28
lib/fcntl--.h Normal file
View file

@ -0,0 +1,28 @@
/* Like fcntl.h, but redefine some names to avoid glitches.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#include <fcntl.h>
#include "fcntl-safer.h"
#undef open
#define open open_safer
#undef creat
#define creat creat_safer

24
lib/fcntl-safer.h Normal file
View file

@ -0,0 +1,24 @@
/* Invoke fcntl-like functions, but avoid some glitches.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#include <sys/types.h>
int open_safer (char const *, int, ...);
int creat_safer (char const *, mode_t);

59
lib/fd-safer.c Normal file
View file

@ -0,0 +1,59 @@
/* Return a safer copy of a file descriptor.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "unistd-safer.h"
#include <errno.h>
#include <unistd.h>
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
#ifndef STDERR_FILENO
# define STDERR_FILENO 2
#endif
/* Return FD, unless FD would be a copy of standard input, output, or
error; in that case, return a duplicate of FD, closing FD. On
failure to duplicate, close FD, set errno, and return -1. Preserve
errno if FD is negative, so that the caller can always inspect
errno when the returned value is negative.
This function is usefully wrapped around functions that return file
descriptors, e.g., fd_safer (open ("file", O_RDONLY)). */
int
fd_safer (int fd)
{
if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
{
int f = dup_safer (fd);
int e = errno;
close (fd);
errno = e;
fd = f;
}
return fd;
}

51
lib/open-safer.c Normal file
View file

@ -0,0 +1,51 @@
/* Invoke open, but avoid some glitches.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "fcntl-safer.h"
#include <fcntl.h>
#include <stdarg.h>
#include "unistd-safer.h"
int
open_safer (char const *file, int flags, ...)
{
mode_t mode = 0;
if (flags & O_CREAT)
{
va_list ap;
va_start (ap, flags);
/* Assume mode_t promotes to int if and only if it is smaller.
This assumption isn't guaranteed by the C standard, but we
don't know of any real-world counterexamples. */
mode = (sizeof (mode_t) < sizeof (int)
? va_arg (ap, int)
: va_arg (ap, mode_t));
va_end (ap);
}
return fd_safer (open (file, flags, mode));
}

50
lib/pipe-safer.c Normal file
View file

@ -0,0 +1,50 @@
/* Invoke pipe, but avoid some glitches.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Jim Meyering. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "unistd-safer.h"
#include <unistd.h>
/* Like pipe, but ensure that neither of the file descriptors is
STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */
int
pipe_safer (int fd[2])
{
int fail = pipe (fd);
if (fail)
return fail;
{
int i;
for (i = 0; i < 2; i++)
{
int f = fd_safer (fd[i]);
if (f < 0)
return -1;
fd[i] = f;
}
}
return 0;
}

28
lib/unistd--.h Normal file
View file

@ -0,0 +1,28 @@
/* Like unistd.h, but redefine some names to avoid glitches.
Copyright (C) 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#include <unistd.h>
#include "unistd-safer.h"
#undef dup
#define dup dup_safer
#undef pipe
#define pipe pipe_safer

23
lib/unistd-safer.h Normal file
View file

@ -0,0 +1,23 @@
/* Invoke unistd-like functions, but avoid some glitches.
Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
int dup_safer (int);
int fd_safer (int);
int pipe_safer (int[2]);

12
m4/fcntl-safer.m4 Normal file
View file

@ -0,0 +1,12 @@
#serial 2
dnl Copyright (C) 2005 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FCNTL_SAFER],
[
AC_LIBSOURCES([creat-safer.c, fcntl-safer.h, open-safer.c, fcntl--.h])
AC_LIBOBJ([open-safer])
AC_LIBOBJ([creat-safer])
])

View file

@ -13,11 +13,13 @@ AC_DEFUN([np_COREUTILS],
AC_REQUIRE([AM_STDBOOL_H])
AC_REQUIRE([gl_C_STRTOLD])
AC_REQUIRE([gl_EXITFAIL])
AC_REQUIRE([gl_FCNTL_SAFER])
AC_REQUIRE([gl_FSUSAGE])
AC_REQUIRE([gl_FUNC_ALLOCA])
AC_REQUIRE([gl_GETOPT])
AC_REQUIRE([gl_MOUNTLIST])
AC_REQUIRE([gl_REGEX])
AC_REQUIRE([gl_UNISTD_SAFER])
AC_REQUIRE([gl_XALLOC])
AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO])

13
m4/unistd-safer.m4 Normal file
View file

@ -0,0 +1,13 @@
#serial 7
dnl Copyright (C) 2002, 2005 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_UNISTD_SAFER],
[
AC_LIBSOURCES([dup-safer.c, fd-safer.c, pipe-safer.c, unistd-safer.h, unistd--.h])
AC_LIBOBJ([dup-safer])
AC_LIBOBJ([fd-safer])
AC_LIBOBJ([pipe-safer])
])