Procházet zdrojové kódy

REVIEWED: GetDirectoryPath()

Check if provided path is a full path containing system root letter: C:\
pull/1097/head
Ray před 5 roky
rodič
revize
87d5b51256
1 změnil soubory, kde provedl 11 přidání a 6 odebrání
  1. +11
    -6
      src/core.c

+ 11
- 6
src/core.c Zobrazit soubor

@ -1964,17 +1964,22 @@ const char *GetDirectoryPath(const char *filePath)
static char dirPath[MAX_FILEPATH_LENGTH]; static char dirPath[MAX_FILEPATH_LENGTH];
memset(dirPath, 0, MAX_FILEPATH_LENGTH); memset(dirPath, 0, MAX_FILEPATH_LENGTH);
// For security, we set starting path to current directory,
// obtained path will be concated to this
//dirPath[0] = '.';
//dirPath[1] = '/';
// In case provided path does not contains a root drive letter (C:\, D:\),
// we add the current directory path to dirPath
if (filePath[1] != ':')
{
// For security, we set starting path to current directory,
// obtained path will be concated to this
dirPath[0] = '.';
dirPath[1] = '/';
}
lastSlash = strprbrk(filePath, "\\/"); lastSlash = strprbrk(filePath, "\\/");
if (lastSlash) if (lastSlash)
{ {
// NOTE: Be careful, strncpy() is not safe, it does not care about '\0' // NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
strncpy(dirPath, filePath, strlen(filePath) - (strlen(lastSlash) - 1));
dirPath[strlen(filePath) - strlen(lastSlash)] = '\0'; // Add '\0' manually
strncpy(dirPath + ((filePath[1] != ':')? 2 : 0), filePath, strlen(filePath) - (strlen(lastSlash) - 1));
dirPath[strlen(filePath) - strlen(lastSlash) + ((filePath[1] != ':')? 2 : 0)] = '\0'; // Add '\0' manually
} }
return dirPath; return dirPath;

Načítá se…
Zrušit
Uložit