win32-host.c 2.5 KB
Newer Older
Andrew Haley committed
1
/* Platform-Specific Win32 Functions
2
   Copyright (C) 2003-2014 Free Software Foundation, Inc.
Andrew Haley committed
3

4 5 6
This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
Andrew Haley committed
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)
Andrew Haley committed
9 10
any later version.

11
GCC is distributed in the hope that it will be useful,
Andrew Haley committed
12 13 14 15 16
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
17 18
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.
Andrew Haley committed
19 20 21 22 23 24 25 26 27 28

Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc.  */

/* Written by Mohan Embar <gnustuff@thisiscool.com>, March 2003. */


#include "config.h"
#include "system.h"
29 30
#include "coretypes.h"
#include "jcf.h"
Andrew Haley committed
31

32 33
#ifdef WIN32

Andrew Haley committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

/* Simulate an open() failure with ENOENT */
static int
file_not_found (void);

static int
file_not_found (void)
{
  errno = ENOENT;
  return -1;
}

int
jcf_open_exact_case (const char *filename, int oflag)
{
  int filename_len = strlen (filename);
  int found_file_len;
  HANDLE found_file_handle;
  WIN32_FIND_DATA fd;
  
  /* See if we can find this file. */
  found_file_handle = FindFirstFile (filename, &fd);
  if (found_file_handle == INVALID_HANDLE_VALUE)
    return file_not_found ();
  FindClose (found_file_handle);

  found_file_len = strlen (fd.cFileName);
  
  /* This should never happen. */
  if (found_file_len > filename_len)
    return file_not_found ();
  
  /* Here, we're only actually comparing the filename and not
     checking the case of any containing directory components.
     Although we're not fully obeying our contract, checking
     all directory components would be tedious and time-consuming
     and it's a pretty safe assumption that mixed-case package
     names are a fringe case.... */
Kai Tietz committed
75
  if (filename_cmp (filename + filename_len - found_file_len, fd.cFileName))
Andrew Haley committed
76 77 78 79 80 81 82 83 84 85 86 87
    {
      /* Reject this because it is not a perfect-case match. */
      /* printf("************\nRejected:\n%s\n%s\n************\n\n", filename, fd.cFileName); */
      return file_not_found ();
    }
  else
    {
      return open (filename, oflag);
    }
}

#endif /* WIN32 */