Blame src/gl/close.c

Packit aea12f
/* close replacement.
Packit Service 991b93
   Copyright (C) 2008-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or modify
Packit aea12f
   it under the terms of the GNU General Public License as published by
Packit aea12f
   the Free Software Foundation; either version 3 of the License, or
Packit aea12f
   (at your option) any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
#include <config.h>
Packit aea12f
Packit aea12f
/* Specification.  */
Packit aea12f
#include <unistd.h>
Packit aea12f
Packit aea12f
#include <errno.h>
Packit aea12f
Packit aea12f
#include "fd-hook.h"
Packit aea12f
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
Packit aea12f
# include "msvc-inval.h"
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#undef close
Packit aea12f
Packit aea12f
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
Packit aea12f
static int
Packit aea12f
close_nothrow (int fd)
Packit aea12f
{
Packit aea12f
  int result;
Packit aea12f
Packit aea12f
  TRY_MSVC_INVAL
Packit aea12f
    {
Packit aea12f
      result = close (fd);
Packit aea12f
    }
Packit aea12f
  CATCH_MSVC_INVAL
Packit aea12f
    {
Packit aea12f
      result = -1;
Packit aea12f
      errno = EBADF;
Packit aea12f
    }
Packit aea12f
  DONE_MSVC_INVAL;
Packit aea12f
Packit aea12f
  return result;
Packit aea12f
}
Packit aea12f
#else
Packit aea12f
# define close_nothrow close
Packit aea12f
#endif
Packit aea12f
Packit aea12f
/* Override close() to call into other gnulib modules.  */
Packit aea12f
Packit aea12f
int
Packit aea12f
rpl_close (int fd)
Packit aea12f
{
Packit aea12f
#if WINDOWS_SOCKETS
Packit aea12f
  int retval = execute_all_close_hooks (close_nothrow, fd);
Packit aea12f
#else
Packit aea12f
  int retval = close_nothrow (fd);
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#if REPLACE_FCHDIR
Packit aea12f
  if (retval >= 0)
Packit aea12f
    _gl_unregister_fd (fd);
Packit aea12f
#endif
Packit aea12f
Packit aea12f
  return retval;
Packit aea12f
}