forked from haskell/directory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8ee4d5
commit 72270f9
Showing
3 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <windows.h> | ||
#include <stdio.h> | ||
|
||
const wchar_t *error_string(DWORD code) | ||
{ | ||
static wchar_t message[1024]; | ||
if (!FormatMessageW( | ||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | ||
NULL, code, 0, message, sizeof(message) / sizeof(*message), NULL)) { | ||
wprintf(L"??? %d\n", GetLastError()); | ||
return L"???"; | ||
} | ||
return message; | ||
} | ||
|
||
static const wchar_t *dir = L"VERYLONGDIRECTORYNAME"; | ||
|
||
int main(void) | ||
{ | ||
wchar_t buf[512], buf2[512]; | ||
if (!CreateDirectoryW(dir, NULL)) { | ||
DWORD code = GetLastError(); | ||
if (code != ERROR_ALREADY_EXISTS) { | ||
wprintf(L"CreateDirectoryA: %ls\n", error_string(code)); | ||
return 1; | ||
} | ||
} | ||
if (!GetShortPathNameW(dir, buf, sizeof(buf) / sizeof(*buf))) { | ||
wprintf(L"GetShortPathNameW: %ls\n", error_string(GetLastError())); | ||
return 1; | ||
} | ||
wprintf(L"short path = %ls\n", buf); | ||
if (!GetLongPathNameW(buf, buf2, sizeof(buf2) / sizeof(*buf2))) { | ||
wprintf(L"GetLongPathNameW: %ls\n", error_string(GetLastError())); | ||
return 1; | ||
} | ||
wprintf(L"short-then-long path = %ls\n", buf2); | ||
return 0; | ||
} |
This file contains 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