FSFindFolder找到奇怪的目录

时间:2011-03-09 08:56:55

标签: macos operating-system macos-carbon

我有以下代码:

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”。 有人知道我偶然发现了什么问题吗?

1 个答案:

答案 0 :(得分:3)

/private/var/root是root用户的主目录。此代码是否在具有setuid或提升权限的进程中运行?