在 Carbon 应用程序中,我需要将 HFS 样式的 MacOS 路径转换为可在 fopen() 调用中使用的 POSIX 路径。例如:
我的 Vol:myFolder:myFile.jpg
类似于:
/我的卷/myFolder/myFile.jpg
如果 my Vol 是我的系统磁盘,/myFolder/myFile.jpg 工作得很好,但如果它在不同的卷上,它就不起作用(即。 我的 Vol/myFolder/myFile.jpg 失败了。
如何在此处指定音量?
谢谢!
比尔
最佳答案
一种避免硬编码的方法(考虑未安装在 /Volumes/
中的卷,例如手动安装的卷。)
CFStringRef myHFSPath = CFSTR("Macintosh HD:Some Folder:Some Subfolder:Some File");
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, myHFSPath, kCFURLHFSPathStyle, FALSE);
if (url) {
UInt8 posixPath[PATH_MAX * 2]; /* Extra-large because why not? */
if (CFURLGetFileSystemRepresentation(url, TRUE, posixPath, sizeof(posixPath)) {
/*
posixPath now contains a C string suitable for passing to BSD and
C functions like fopen().
*/
}
CFRelease(url);
}
关于c++ - 将 MacOSPath 转换为 POSIX 时如何设置卷名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11587735/