在Carbon应用程序中,我需要将HFS样式的MacOS路径转换为可以在fopen()调用中使用的POSIX。例如:
我的Vol:myFolder:myFile.jpg
像这样:
/ my Vol / myFolder / myFile.jpg
如果我的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/