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