浏览代码

core: Support slashes as well in GetFileName & GetDirectoryPath

Fixes #634.
pull/635/head
Ahmad Fatoum 6 年前
父节点
当前提交
5dda105a79
找不到此签名对应的密钥 GPG 密钥 ID: C3EAC3DE9321D59B
共有 1 个文件被更改,包括 15 次插入6 次删除
  1. +15
    -6
      src/core.c

+ 15
- 6
src/core.c 查看文件

@ -1346,11 +1346,20 @@ const char *GetExtension(const char *fileName)
return (dot + 1); return (dot + 1);
} }
/* "string pointer reverse break": return right-most occurrence of charset in s */
static const char *strprbrk(const char *s, const char *charset)
{
const char *latest_match = NULL;
for(; s = strpbrk(s, charset), s != NULL; latest_match=s++)
;
return latest_match;
}
// Get pointer to filename for a path string // Get pointer to filename for a path string
const char *GetFileName(const char *filePath) const char *GetFileName(const char *filePath)
{ {
const char *fileName = strrchr(filePath, '\\');
const char *fileName = strprbrk(filePath, ">"\\/";);
if (!fileName || fileName == filePath) return filePath; if (!fileName || fileName == filePath) return filePath;
return fileName + 1; return fileName + 1;
@ -1360,14 +1369,14 @@ const char *GetFileName(const char *filePath)
// Get directory for a given fileName (with path) // Get directory for a given fileName (with path)
const char *GetDirectoryPath(const char *fileName) const char *GetDirectoryPath(const char *fileName)
{ {
char *lastSlash = NULL;
">const char *lastSlash = NULL;
static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256 static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256
memset(filePath, 0, 256); memset(filePath, 0, 256);
lastSlash = strrchr(fileName, c">'\\';);
lastSlash = strprbrk(fileName, ">"\\/";);
strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1)); strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1));
filePath[strlen(fileName) - strlen(lastSlash)] = '\0'; filePath[strlen(fileName) - strlen(lastSlash)] = '\0';
return filePath; return filePath;
} }

正在加载...
取消
保存