1*c87b03e5Sespie /* Platform-Specific Win32 Functions
2*c87b03e5Sespie Copyright (C) 2003 Free Software Foundation, Inc.
3*c87b03e5Sespie
4*c87b03e5Sespie This program is free software; you can redistribute it and/or modify
5*c87b03e5Sespie it under the terms of the GNU General Public License as published by
6*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
7*c87b03e5Sespie any later version.
8*c87b03e5Sespie
9*c87b03e5Sespie This program is distributed in the hope that it will be useful,
10*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
11*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*c87b03e5Sespie GNU General Public License for more details.
13*c87b03e5Sespie
14*c87b03e5Sespie You should have received a copy of the GNU General Public License
15*c87b03e5Sespie along with GNU CC; see the file COPYING. If not, write to
16*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
17*c87b03e5Sespie Boston, MA 02111-1307, USA.
18*c87b03e5Sespie
19*c87b03e5Sespie Java and all Java-based marks are trademarks or registered trademarks
20*c87b03e5Sespie of Sun Microsystems, Inc. in the United States and other countries.
21*c87b03e5Sespie The Free Software Foundation is independent of Sun Microsystems, Inc. */
22*c87b03e5Sespie
23*c87b03e5Sespie /* Written by Mohan Embar <gnustuff@thisiscool.com>, March 2003. */
24*c87b03e5Sespie
25*c87b03e5Sespie #ifdef WIN32
26*c87b03e5Sespie
27*c87b03e5Sespie #include "config.h"
28*c87b03e5Sespie #include "system.h"
29*c87b03e5Sespie
30*c87b03e5Sespie #include "jcf.h"
31*c87b03e5Sespie
32*c87b03e5Sespie #define WIN32_LEAN_AND_MEAN
33*c87b03e5Sespie #include <windows.h>
34*c87b03e5Sespie #undef WIN32_LEAN_AND_MEAN
35*c87b03e5Sespie
36*c87b03e5Sespie /* Simulate an open() failure with ENOENT */
37*c87b03e5Sespie static int
38*c87b03e5Sespie file_not_found (void);
39*c87b03e5Sespie
40*c87b03e5Sespie static int
file_not_found(void)41*c87b03e5Sespie file_not_found (void)
42*c87b03e5Sespie {
43*c87b03e5Sespie errno = ENOENT;
44*c87b03e5Sespie return -1;
45*c87b03e5Sespie }
46*c87b03e5Sespie
47*c87b03e5Sespie int
jcf_open_exact_case(const char * filename,int oflag)48*c87b03e5Sespie jcf_open_exact_case (const char *filename, int oflag)
49*c87b03e5Sespie {
50*c87b03e5Sespie int filename_len = strlen (filename);
51*c87b03e5Sespie int found_file_len;
52*c87b03e5Sespie HANDLE found_file_handle;
53*c87b03e5Sespie WIN32_FIND_DATA fd;
54*c87b03e5Sespie
55*c87b03e5Sespie /* See if we can find this file. */
56*c87b03e5Sespie found_file_handle = FindFirstFile (filename, &fd);
57*c87b03e5Sespie if (found_file_handle == INVALID_HANDLE_VALUE)
58*c87b03e5Sespie return file_not_found ();
59*c87b03e5Sespie FindClose (found_file_handle);
60*c87b03e5Sespie
61*c87b03e5Sespie found_file_len = strlen (fd.cFileName);
62*c87b03e5Sespie
63*c87b03e5Sespie /* This should never happen. */
64*c87b03e5Sespie if (found_file_len > filename_len)
65*c87b03e5Sespie return file_not_found ();
66*c87b03e5Sespie
67*c87b03e5Sespie /* Here, we're only actually comparing the filename and not
68*c87b03e5Sespie checking the case of any containing directory components.
69*c87b03e5Sespie Although we're not fully obeying our contract, checking
70*c87b03e5Sespie all directory components would be tedious and time-consuming
71*c87b03e5Sespie and it's a pretty safe assumption that mixed-case package
72*c87b03e5Sespie names are a fringe case.... */
73*c87b03e5Sespie if (strcmp (filename + filename_len - found_file_len, fd.cFileName))
74*c87b03e5Sespie {
75*c87b03e5Sespie /* Reject this because it is not a perfect-case match. */
76*c87b03e5Sespie /* printf("************\nRejected:\n%s\n%s\n************\n\n", filename, fd.cFileName); */
77*c87b03e5Sespie return file_not_found ();
78*c87b03e5Sespie }
79*c87b03e5Sespie else
80*c87b03e5Sespie {
81*c87b03e5Sespie return open (filename, oflag);
82*c87b03e5Sespie }
83*c87b03e5Sespie }
84*c87b03e5Sespie
85*c87b03e5Sespie #endif /* WIN32 */
86