我有以下代码:
FSRef FileRef;
OSStatus Error = ::FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &FileRef);
if (Error != noErr)
{
//error
}
CFURLRef UrlRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, &FileRef);
if (!UrlRef)
{
//error
}
CFStringRef PathRef = ::CFURLCopyFileSystemPath(UrlRef, kCFURLPOSIXPathStyle);
/Qt class for string store
QString strResult;
if (PathRef)
{
CFIndex Size = ::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(PathRef), kCFStringEncodingUTF8);
//Qt smart pointer for arrays
QScopedArrayPointer<char> spBuffer(new char[Size + 1]);
if (::CFStringGetCString(PathRef, spBuffer.data(), Size, kCFStringEncodingUTF8))
{
strResult = QString::fromUtf8(spBuffer.data());
}
else
{
//error
}
::CFRelease(PathRef);
}
else
{
//error
}
::CFRelease(UrlRef);
所以在代码执行后我希望有“/ User / myname / Library / Application Support”,但我有“/ private / var / root / Library / Application Support”。 有人知道我偶然发现了什么问题吗?
答案 0 :(得分:3)
/private/var/root
是root用户的主目录。此代码是否在具有setuid或提升权限的进程中运行?