Blame gl/close.c

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