msvc-nothrow.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Wrappers that don't throw invalid parameter notifications
  2. with MSVC runtime libraries.
  3. Copyright (C) 2011-2022 Free Software Foundation, Inc.
  4. This file is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. This file 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #include <config.h>
  15. /* Specification. */
  16. #include "msvc-nothrow.h"
  17. /* Get declarations of the native Windows API functions. */
  18. #define WIN32_LEAN_AND_MEAN
  19. #include <windows.h>
  20. #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
  21. # include "msvc-inval.h"
  22. #endif
  23. #undef _get_osfhandle
  24. #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
  25. intptr_t
  26. _gl_nothrow_get_osfhandle (int fd)
  27. {
  28. intptr_t result;
  29. TRY_MSVC_INVAL
  30. {
  31. result = _get_osfhandle (fd);
  32. }
  33. CATCH_MSVC_INVAL
  34. {
  35. result = (intptr_t) INVALID_HANDLE_VALUE;
  36. }
  37. DONE_MSVC_INVAL;
  38. return result;
  39. }
  40. #endif