From 09ef260209d4a2e3acab6673ce1e443205e554bd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 9 Nov 2003 20:59:07 +0000 Subject: [PATCH] Added internal function __PHYSFS_platformStrnicmp(). --- physfs_internal.h | 5 +++++ platform/macclassic.c | 7 +++++++ platform/os2.c | 24 ++++++++++++++++++++++++ platform/pocketpc.c | 7 ++++++- platform/posix.c | 22 ++++++++++++++++++++++ platform/skeleton.c | 6 ++++++ platform/win32.c | 28 ++++++++++++++++++++++++++++ 7 files changed, 98 insertions(+), 1 deletion(-) diff --git a/physfs_internal.h b/physfs_internal.h index 109c6e49..89c2ad7d 100644 --- a/physfs_internal.h +++ b/physfs_internal.h @@ -1313,6 +1313,11 @@ PHYSFS_uint64 __PHYSFS_platformGetThreadID(void); */ int __PHYSFS_platformStricmp(const char *str1, const char *str2); +/* + * This is a pass-through to whatever strnicmp() is called on your platform. + */ +int __PHYSFS_platformStrnicmp(const char *s1, const char *s2, PHYSFS_uint32 l); + /* * Return non-zero if filename (in platform-dependent notation) exists. * Symlinks should NOT be followed; at this stage, we do not care what the diff --git a/platform/macclassic.c b/platform/macclassic.c index 8ae0eeba..43554a39 100644 --- a/platform/macclassic.c +++ b/platform/macclassic.c @@ -350,6 +350,13 @@ int __PHYSFS_platformStricmp(const char *x, const char *y) } /* __PHYSFS_platformStricmp */ +int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 l) +{ + extern int _strnicmp(const char *, const char *, int); + return(_strnicmp(x, y, (int) l)); /* (*shrug*) */ +} /* __PHYSFS_platformStricmp */ + + static OSErr fnameToFSSpecNoAlias(const char *fname, FSSpec *spec) { OSErr err; diff --git a/platform/os2.c b/platform/os2.c index f6662b3a..8b3c466b 100644 --- a/platform/os2.c +++ b/platform/os2.c @@ -340,6 +340,30 @@ int __PHYSFS_platformStricmp(const char *x, const char *y) } /* __PHYSFS_platformStricmp */ +int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len) +{ + int ux, uy; + + if (!len) + return(0); + + do + { + ux = toupper((int) *x); + uy = toupper((int) *y); + if (ux > uy) + return(1); + else if (ux < uy) + return(-1); + x++; + y++; + len--; + } while ((ux) && (uy) && (len)); + + return(0); +} /* __PHYSFS_platformStrnicmp */ + + int __PHYSFS_platformExists(const char *fname) { FILESTATUS3 fs; diff --git a/platform/pocketpc.c b/platform/pocketpc.c index fea7c05e..ca2708b2 100644 --- a/platform/pocketpc.c +++ b/platform/pocketpc.c @@ -211,10 +211,15 @@ PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) int __PHYSFS_platformStricmp(const char *x, const char *y) { return(_stricmp(x, y)); - } /* __PHYSFS_platformStricmp */ +int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len) +{ + return(_strnicmp(x, y, (int) len)); +} /* __PHYSFS_platformStrnicmp */ + + int __PHYSFS_platformExists(const char *fname) { int retval=0; diff --git a/platform/posix.c b/platform/posix.c index 388db12e..5530b9a6 100644 --- a/platform/posix.c +++ b/platform/posix.c @@ -141,6 +141,28 @@ int __PHYSFS_platformStricmp(const char *x, const char *y) } /* __PHYSFS_platformStricmp */ +int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len) +{ + int ux, uy; + + if (!len) + return(0); + + do + { + ux = toupper((int) *x); + uy = toupper((int) *y); + if (ux != uy) + return((ux > uy) ? 1 : -1); + x++; + y++; + len--; + } while ((ux) && (uy) && (len)); + + return(0); +} /* __PHYSFS_platformStrnicmp */ + + #if (defined __PHYSFS_NO_SYMLINKS__) #define doStat stat #else diff --git a/platform/skeleton.c b/platform/skeleton.c index 0509dc8c..7594327e 100644 --- a/platform/skeleton.c +++ b/platform/skeleton.c @@ -68,6 +68,12 @@ int __PHYSFS_platformStricmp(const char *x, const char *y) } /* __PHYSFS_platformStricmp */ +int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 l) +{ + BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0); +} /* __PHYSFS_platformStrnicmp */ + + int __PHYSFS_platformExists(const char *fname) { BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0); diff --git a/platform/win32.c b/platform/win32.c index 507e94c7..9d764abc 100644 --- a/platform/win32.c +++ b/platform/win32.c @@ -368,6 +368,34 @@ int __PHYSFS_platformStricmp(const char *x, const char *y) } /* __PHYSFS_platformStricmp */ +int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len) +{ +#if (defined _MSC_VER) + return(strnicmp(x, y, (int) len)); +#else + int ux, uy; + + if (!len) + return(0); + + do + { + ux = toupper((int) *x); + uy = toupper((int) *y); + if (ux > uy) + return(1); + else if (ux < uy) + return(-1); + x++; + y++; + len--; + } while ((ux) && (uy) && (len)); + + return(0); +#endif +} /* __PHYSFS_platformStricmp */ + + int __PHYSFS_platformExists(const char *fname) { BAIL_IF_MACRO(GetFileAttributes(fname) == INVALID_FILE_ATTRIBUTES,