Improve MinGW support.
- Code specific to Windows was #ifdef'ed with _MSC_VER so it wasn't included with MinGW. So _MSC_VER is replaced with _WIN32. - MinGW doesn't support _get_pgmptr() so it is necessary to directly call the Win32 function GetModuleFileName(). This implies including windows.h which in turn causes a name clash with the Win32 function SearchPath(). So the cc65 type SearchPath is renamed to SearchPaths.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/* */
|
||||
/* filestat.c */
|
||||
/* */
|
||||
/* Replacement for buggy Microsoft code */
|
||||
/* Replacement for Windows code */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -46,8 +46,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#if defined(__WATCOMC__) && defined(__NT__)
|
||||
#define BUGGY_OS 1
|
||||
#if defined(_WIN32)
|
||||
#include <errno.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
@@ -63,7 +62,7 @@
|
||||
|
||||
|
||||
|
||||
#if defined(BUGGY_OS)
|
||||
#if defined(_WIN32)
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +76,7 @@ static time_t FileTimeToUnixTime (const FILETIME* T)
|
||||
* way to express a number > 32 bit (known to me) but is able to do
|
||||
* calculations with 64 bit integers, so we need to do it this way.
|
||||
*/
|
||||
static const ULARGE_INTEGER Offs = { 0xB6109100UL, 0x00000020UL };
|
||||
static const ULARGE_INTEGER Offs = { { 0xB6109100UL, 0x00000020UL } };
|
||||
ULARGE_INTEGER V;
|
||||
V.LowPart = T->dwLowDateTime;
|
||||
V.HighPart = T->dwHighDateTime;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* */
|
||||
/* filestat.h */
|
||||
/* */
|
||||
/* Replacement for buggy Microsoft code */
|
||||
/* Replacement for Windows code */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* */
|
||||
/* filetime.c */
|
||||
/* */
|
||||
/* Replacement for buggy Microsoft code */
|
||||
/* Replacement for Windows code */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -42,18 +42,12 @@
|
||||
|
||||
|
||||
|
||||
#if defined(__WATCOMC__) && defined(__NT__)
|
||||
#define BUGGY_OS 1
|
||||
#if defined(_WIN32)
|
||||
#include <errno.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__)
|
||||
/* The Windows compilers have the file in the wrong directory */
|
||||
# include <sys/utime.h>
|
||||
#else
|
||||
# include <sys/types.h> /* FreeBSD needs this */
|
||||
# include <utime.h>
|
||||
#endif
|
||||
#include <sys/types.h> /* FreeBSD needs this */
|
||||
#include <utime.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,7 +62,7 @@
|
||||
|
||||
|
||||
|
||||
#if defined(BUGGY_OS)
|
||||
#if defined(_WIN32)
|
||||
|
||||
|
||||
|
||||
@@ -82,7 +76,7 @@ static FILETIME* UnixTimeToFileTime (time_t T, FILETIME* FT)
|
||||
* way to express a number > 32 bit (known to me) but is able to do
|
||||
* calculations with 64 bit integers, so we need to do it this way.
|
||||
*/
|
||||
static const ULARGE_INTEGER Offs = { 0xB6109100UL, 0x00000020UL };
|
||||
static const ULARGE_INTEGER Offs = { { 0xB6109100UL, 0x00000020UL } };
|
||||
ULARGE_INTEGER V;
|
||||
V.QuadPart = ((unsigned __int64) T + Offs.QuadPart) * 10000000U;
|
||||
FT->dwLowDateTime = V.LowPart;
|
||||
@@ -150,6 +144,3 @@ int SetFileTimes (const char* Path, time_t T)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* */
|
||||
/* filetime.h */
|
||||
/* */
|
||||
/* Replacement for buggy Microsoft code */
|
||||
/* Replacement for Windows code */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
/* Microsoft compiler */
|
||||
# include <io.h>
|
||||
@@ -83,7 +86,7 @@ static char* CleanupPath (const char* Path)
|
||||
|
||||
|
||||
|
||||
static void Add (SearchPath* P, const char* New)
|
||||
static void Add (SearchPaths* P, const char* New)
|
||||
/* Cleanup a new search path and add it to the list */
|
||||
{
|
||||
/* Add a clean copy of the path to the collection */
|
||||
@@ -92,7 +95,7 @@ static void Add (SearchPath* P, const char* New)
|
||||
|
||||
|
||||
|
||||
SearchPath* NewSearchPath (void)
|
||||
SearchPaths* NewSearchPath (void)
|
||||
/* Create a new, empty search path list */
|
||||
{
|
||||
return NewCollection ();
|
||||
@@ -100,7 +103,7 @@ SearchPath* NewSearchPath (void)
|
||||
|
||||
|
||||
|
||||
void AddSearchPath (SearchPath* P, const char* NewPath)
|
||||
void AddSearchPath (SearchPaths* P, const char* NewPath)
|
||||
/* Add a new search path to the end of an existing list */
|
||||
{
|
||||
/* Allow a NULL path */
|
||||
@@ -111,7 +114,7 @@ void AddSearchPath (SearchPath* P, const char* NewPath)
|
||||
|
||||
|
||||
|
||||
void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar)
|
||||
void AddSearchPathFromEnv (SearchPaths* P, const char* EnvVar)
|
||||
/* Add a search path from an environment variable to the end of an existing
|
||||
* list.
|
||||
*/
|
||||
@@ -121,7 +124,7 @@ void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar)
|
||||
|
||||
|
||||
|
||||
void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* SubDir)
|
||||
void AddSubSearchPathFromEnv (SearchPaths* P, const char* EnvVar, const char* SubDir)
|
||||
/* Add a search path from an environment variable, adding a subdirectory to
|
||||
* the environment variable value.
|
||||
*/
|
||||
@@ -157,21 +160,20 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub
|
||||
|
||||
|
||||
|
||||
void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir)
|
||||
void AddSubSearchPathFromWinBin (SearchPaths* P, const char* SubDir)
|
||||
{
|
||||
/* Windows only:
|
||||
* Add a search path from the running binary, adding a subdirectory to
|
||||
* the parent directory of the directory containing the binary.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_WIN32)
|
||||
|
||||
char Dir[_MAX_PATH];
|
||||
char* Ptr;
|
||||
|
||||
if (_get_pgmptr (&Ptr) != 0) {
|
||||
if (GetModuleFileName (NULL, Dir, _MAX_PATH) == 0) {
|
||||
return;
|
||||
}
|
||||
strcpy (Dir, Ptr);
|
||||
|
||||
/* Remove binary name */
|
||||
Ptr = strrchr (Dir, '\\');
|
||||
@@ -204,7 +206,7 @@ void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir)
|
||||
}
|
||||
|
||||
|
||||
int PushSearchPath (SearchPath* P, const char* NewPath)
|
||||
int PushSearchPath (SearchPaths* P, const char* NewPath)
|
||||
/* Add a new search path to the head of an existing search path list, provided
|
||||
* that it's not already there. If the path is already at the first position,
|
||||
* return zero, otherwise return a non zero value.
|
||||
@@ -227,7 +229,7 @@ int PushSearchPath (SearchPath* P, const char* NewPath)
|
||||
|
||||
|
||||
|
||||
void PopSearchPath (SearchPath* P)
|
||||
void PopSearchPath (SearchPaths* P)
|
||||
/* Remove a search path from the head of an existing search path list */
|
||||
{
|
||||
/* Remove the path at position 0 */
|
||||
@@ -237,7 +239,7 @@ void PopSearchPath (SearchPath* P)
|
||||
|
||||
|
||||
|
||||
char* SearchFile (const SearchPath* P, const char* File)
|
||||
char* SearchFile (const SearchPaths* P, const char* File)
|
||||
/* Search for a file in a list of directories. Return a pointer to a malloced
|
||||
* area that contains the complete path, if found, return 0 otherwise.
|
||||
*/
|
||||
@@ -271,6 +273,3 @@ char* SearchFile (const SearchPath* P, const char* File)
|
||||
SB_Done (&PathName);
|
||||
return Name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
#define STRINGIZE(arg) _STRINGIZE(arg)
|
||||
|
||||
/* A search path is a pointer to the list */
|
||||
typedef struct Collection SearchPath;
|
||||
typedef struct Collection SearchPaths;
|
||||
|
||||
|
||||
|
||||
@@ -63,38 +63,38 @@ typedef struct Collection SearchPath;
|
||||
|
||||
|
||||
|
||||
SearchPath* NewSearchPath (void);
|
||||
SearchPaths* NewSearchPath (void);
|
||||
/* Create a new, empty search path list */
|
||||
|
||||
void AddSearchPath (SearchPath* P, const char* NewPath);
|
||||
void AddSearchPath (SearchPaths* P, const char* NewPath);
|
||||
/* Add a new search path to the end of an existing list */
|
||||
|
||||
void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar);
|
||||
void AddSearchPathFromEnv (SearchPaths* P, const char* EnvVar);
|
||||
/* Add a search path from an environment variable to the end of an existing
|
||||
* list.
|
||||
*/
|
||||
|
||||
void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* SubDir);
|
||||
void AddSubSearchPathFromEnv (SearchPaths* P, const char* EnvVar, const char* SubDir);
|
||||
/* Add a search path from an environment variable, adding a subdirectory to
|
||||
* the environment variable value.
|
||||
*/
|
||||
|
||||
void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir);
|
||||
void AddSubSearchPathFromWinBin (SearchPaths* P, const char* SubDir);
|
||||
/* Windows only:
|
||||
* Add a search path from the running binary, adding a subdirectory to
|
||||
* the parent directory of the directory containing the binary.
|
||||
*/
|
||||
|
||||
int PushSearchPath (SearchPath* P, const char* NewPath);
|
||||
int PushSearchPath (SearchPaths* P, const char* NewPath);
|
||||
/* Add a new search path to the head of an existing search path list, provided
|
||||
* that it's not already there. If the path is already at the first position,
|
||||
* return zero, otherwise return a non zero value.
|
||||
*/
|
||||
|
||||
void PopSearchPath (SearchPath* P);
|
||||
void PopSearchPath (SearchPaths* P);
|
||||
/* Remove a search path from the head of an existing search path list */
|
||||
|
||||
char* SearchFile (const SearchPath* P, const char* File);
|
||||
char* SearchFile (const SearchPaths* P, const char* File);
|
||||
/* Search for a file in a list of directories. Return a pointer to a malloced
|
||||
* area that contains the complete path, if found, return 0 otherwise.
|
||||
*/
|
||||
|
||||
@@ -41,7 +41,11 @@
|
||||
* and precision to such a StrBuf, but *not* using %p would bring up a warning
|
||||
* about a wrong argument type each time. Maybe gcc will one day allow custom
|
||||
* format specifiers and we can change this ...
|
||||
* However this cheat doesn't work with MinGW as there's no support for %m :-(
|
||||
*/
|
||||
#if defined( __MINGW32__)
|
||||
# pragma GCC diagnostic ignored "-Wformat"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user