Blame gettext-tools/gnulib-tests/dup.c

Packit Bot 06c835
/* Duplicate an open file descriptor.
Packit Bot 06c835
Packit Bot 06c835
   Copyright (C) 2011-2015 Free Software Foundation, Inc.
Packit Bot 06c835
Packit Bot 06c835
   This program is free software: you can redistribute it and/or modify
Packit Bot 06c835
   it under the terms of the GNU General Public License as published by
Packit Bot 06c835
   the Free Software Foundation; either version 3 of the License, or
Packit Bot 06c835
   (at your option) any later version.
Packit Bot 06c835
Packit Bot 06c835
   This program is distributed in the hope that it will be useful,
Packit Bot 06c835
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Bot 06c835
   GNU General Public License for more details.
Packit Bot 06c835
Packit Bot 06c835
   You should have received a copy of the GNU General Public License
Packit Bot 06c835
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Bot 06c835
Packit Bot 06c835
#include <config.h>
Packit Bot 06c835
Packit Bot 06c835
/* Specification.  */
Packit Bot 06c835
#include <unistd.h>
Packit Bot 06c835
Packit Bot 06c835
#include <errno.h>
Packit Bot 06c835
Packit Bot 06c835
#include "msvc-inval.h"
Packit Bot 06c835
Packit Bot 06c835
#undef dup
Packit Bot 06c835
Packit Bot 06c835
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
Packit Bot 06c835
static int
Packit Bot 06c835
dup_nothrow (int fd)
Packit Bot 06c835
{
Packit Bot 06c835
  int result;
Packit Bot 06c835
Packit Bot 06c835
  TRY_MSVC_INVAL
Packit Bot 06c835
    {
Packit Bot 06c835
      result = dup (fd);
Packit Bot 06c835
    }
Packit Bot 06c835
  CATCH_MSVC_INVAL
Packit Bot 06c835
    {
Packit Bot 06c835
      result = -1;
Packit Bot 06c835
      errno = EBADF;
Packit Bot 06c835
    }
Packit Bot 06c835
  DONE_MSVC_INVAL;
Packit Bot 06c835
Packit Bot 06c835
  return result;
Packit Bot 06c835
}
Packit Bot 06c835
#else
Packit Bot 06c835
# define dup_nothrow dup
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
int
Packit Bot 06c835
rpl_dup (int fd)
Packit Bot 06c835
{
Packit Bot 06c835
  int result = dup_nothrow (fd);
Packit Bot 06c835
#if REPLACE_FCHDIR
Packit Bot 06c835
  if (result >= 0)
Packit Bot 06c835
    result = _gl_register_dup (fd, result);
Packit Bot 06c835
#endif
Packit Bot 06c835
  return result;
Packit Bot 06c835
}