msvc-nothrow.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Wrappers that don't throw invalid parameter notifications
  2. with MSVC runtime libraries.
  3. Copyright (C) 2011-2020 Free Software Foundation, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, see <https://www.gnu.org/licenses/>. */
  14. #ifndef _MSVC_NOTHROW_H
  15. #define _MSVC_NOTHROW_H
  16. /* With MSVC runtime libraries with the "invalid parameter handler" concept,
  17. functions like fprintf(), dup2(), or close() crash when the caller passes
  18. an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
  19. instead.
  20. This file defines wrappers that turn such an invalid parameter notification
  21. into an error code. */
  22. #if defined _WIN32 && ! defined __CYGWIN__
  23. /* Get original declaration of _get_osfhandle. */
  24. # include <io.h>
  25. # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
  26. /* Override _get_osfhandle. */
  27. extern intptr_t _gl_nothrow_get_osfhandle (int fd);
  28. # define _get_osfhandle _gl_nothrow_get_osfhandle
  29. # endif
  30. #endif
  31. #endif /* _MSVC_NOTHROW_H */