diff --git a/Quake/common.c b/Quake/common.c index 5fb20315..c33e2178 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -919,23 +919,25 @@ void COM_StripExtension (const char *in, char *out) /* ============ -COM_FileExtension +COM_FileGetExtension - doesn't return NULL ============ */ -const char *COM_FileExtension (const char *in) +const char *COM_FileGetExtension (const char *in) { - static char exten[8]; - int i; + const char *src; + size_t len; - while (*in && *in != '.') - in++; - if (!*in) + len = strlen(in); + if (len < 2) /* nothing meaningful */ return ""; - in++; - for (i=0 ; i<7 && *in ; i++,in++) - exten[i] = *in; - exten[i] = 0; - return exten; + + src = in + len - 1; + while (src != in && src[-1] != '.') + src--; + if (src == in || strchr(src, '/') != NULL || strchr(src, '\\') != NULL) + return ""; /* no extension, or parent directory has a dot */ + + return src; } /* diff --git a/Quake/common.h b/Quake/common.h index 3ef6f5b4..c8051085 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -178,6 +178,7 @@ const char *COM_SkipPath (const char *pathname); void COM_StripExtension (const char *in, char *out); void COM_FileBase (const char *in, char *out); void COM_DefaultExtension (char *path, const char *extension); +const char *COM_FileGetExtension (const char *in); void COM_CreatePath (char *path); char *va (const char *format, ...) __attribute__((__format__(__printf__,1,2)));