Skip to content

Commit ea7cc6e

Browse files
authored
Merge pull request swiftlang#459 from swiftwasm/main
[pull] swiftwasm from main
2 parents 953e040 + 675ce56 commit ea7cc6e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

CoreFoundation/PlugIn.subproj/CFBundle_Internal.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,29 @@ static bool _CFGetPathFromFileDescriptor(int fd, char *path) {
461461
#else
462462

463463
static bool _CFGetPathFromFileDescriptor(int fd, char *path) {
464-
#warning This platform does not have a way to go back from an open file descriptor to a path.
465-
return false;
464+
HANDLE hFile = _get_osfhandle(fd);
465+
if (hFile == INVALID_HANDLE_VALUE)
466+
return false;
467+
468+
DWORD dwLength = GetFinalPathNameByHandleW(hFile, NULL, 0, 0);
469+
470+
WCHAR *wszPath = (WCHAR *)malloc(dwLength);
471+
if (wszPath == NULL)
472+
return false;
473+
474+
if (GetFinalPathNameByHandleW(hFile, wszPath, dwLength, 0) != dwLength - 1) {
475+
free(wszPath);
476+
return false;
477+
}
478+
479+
CFStringRef location =
480+
CFStringCreateWithBytes(kCFAllocatorSystemDefault,
481+
(const UInt8 *)wszPath, dwLength - 1,
482+
kCFStringEncodingUTF16, false);
483+
path = strdup(CFStringGetCStringPtr(location, kCFStringEncodingUTF8));
484+
CFRelease(location);
485+
free(wszPath);
486+
return true;
466487
}
467488

468489
#endif

0 commit comments

Comments
 (0)