Created
March 2, 2023 15:47
-
-
Save ugexe/bff0f9a20e3cd5c29e85d572c069bd86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _WIN32 | |
#include <windows.h> | |
#endif | |
#define MAX_PATH_LENGTH 260 | |
void transform_path(char *path) { | |
#ifdef _WIN32 | |
// Check if path is already a long path | |
if (strlen(path) >= 7 && strncmp(path, "\\\\?\\", 4) == 0) { | |
// Path is already a long path, so do nothing | |
return; | |
} | |
if (strlen(path) >= MAX_PATH_LENGTH) { | |
char long_path[MAX_PATH_LENGTH + 7]; | |
// Windows long path prefix is \\?\, so we add 4 extra characters | |
// to account for this and a terminating null character | |
sprintf(long_path, "\\\\?\\%s", path); | |
strcpy(path, long_path); | |
} | |
#else | |
// On non-Windows systems, do nothing | |
(void)path; | |
#endif | |
} | |
This updated implementation first checks whether the given path is already a Windows long path by verifying that the string starts with \\?\. If it is already a long path, the function returns immediately without making any modifications to the path. Otherwise, it proceeds with checking the length of the path and adding the long path prefix if necessary. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment