win32-host.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Platform-Specific Win32 Functions
  2. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC 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. GCC 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
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>.
  15. Java and all Java-based marks are trademarks or registered trademarks
  16. of Sun Microsystems, Inc. in the United States and other countries.
  17. The Free Software Foundation is independent of Sun Microsystems, Inc. */
  18. /* Written by Mohan Embar <gnustuff@thisiscool.com>, March 2003. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "coretypes.h"
  22. #include "jcf.h"
  23. #ifdef WIN32
  24. #define WIN32_LEAN_AND_MEAN
  25. #include <windows.h>
  26. #undef WIN32_LEAN_AND_MEAN
  27. /* Simulate an open() failure with ENOENT */
  28. static int
  29. file_not_found (void);
  30. static int
  31. file_not_found (void)
  32. {
  33. errno = ENOENT;
  34. return -1;
  35. }
  36. int
  37. jcf_open_exact_case (const char *filename, int oflag)
  38. {
  39. int filename_len = strlen (filename);
  40. int found_file_len;
  41. HANDLE found_file_handle;
  42. WIN32_FIND_DATA fd;
  43. /* See if we can find this file. */
  44. found_file_handle = FindFirstFile (filename, &fd);
  45. if (found_file_handle == INVALID_HANDLE_VALUE)
  46. return file_not_found ();
  47. FindClose (found_file_handle);
  48. found_file_len = strlen (fd.cFileName);
  49. /* This should never happen. */
  50. if (found_file_len > filename_len)
  51. return file_not_found ();
  52. /* Here, we're only actually comparing the filename and not
  53. checking the case of any containing directory components.
  54. Although we're not fully obeying our contract, checking
  55. all directory components would be tedious and time-consuming
  56. and it's a pretty safe assumption that mixed-case package
  57. names are a fringe case.... */
  58. if (filename_cmp (filename + filename_len - found_file_len, fd.cFileName))
  59. {
  60. /* Reject this because it is not a perfect-case match. */
  61. /* printf("************\nRejected:\n%s\n%s\n************\n\n", filename, fd.cFileName); */
  62. return file_not_found ();
  63. }
  64. else
  65. {
  66. return open (filename, oflag);
  67. }
  68. }
  69. #endif /* WIN32 */