2013-06-06 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / java / win32-host.c
blob74366333afff2b2e560ec8d80199c0e54322b2de
1 /* Platform-Specific Win32 Functions
2 Copyright (C) 2003-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 /* Written by Mohan Embar <gnustuff@thisiscool.com>, March 2003. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "jcf.h"
32 #ifdef WIN32
34 #define WIN32_LEAN_AND_MEAN
35 #include <windows.h>
36 #undef WIN32_LEAN_AND_MEAN
38 /* Simulate an open() failure with ENOENT */
39 static int
40 file_not_found (void);
42 static int
43 file_not_found (void)
45 errno = ENOENT;
46 return -1;
49 int
50 jcf_open_exact_case (const char *filename, int oflag)
52 int filename_len = strlen (filename);
53 int found_file_len;
54 HANDLE found_file_handle;
55 WIN32_FIND_DATA fd;
57 /* See if we can find this file. */
58 found_file_handle = FindFirstFile (filename, &fd);
59 if (found_file_handle == INVALID_HANDLE_VALUE)
60 return file_not_found ();
61 FindClose (found_file_handle);
63 found_file_len = strlen (fd.cFileName);
65 /* This should never happen. */
66 if (found_file_len > filename_len)
67 return file_not_found ();
69 /* Here, we're only actually comparing the filename and not
70 checking the case of any containing directory components.
71 Although we're not fully obeying our contract, checking
72 all directory components would be tedious and time-consuming
73 and it's a pretty safe assumption that mixed-case package
74 names are a fringe case.... */
75 if (filename_cmp (filename + filename_len - found_file_len, fd.cFileName))
77 /* Reject this because it is not a perfect-case match. */
78 /* printf("************\nRejected:\n%s\n%s\n************\n\n", filename, fd.cFileName); */
79 return file_not_found ();
81 else
83 return open (filename, oflag);
87 #endif /* WIN32 */