msvc-nothrow.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Wrappers that don't throw invalid parameter notifications
  2. with MSVC runtime libraries.
  3. Copyright (C) 2011-2021 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. #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