Search code examples
macosoperating-systemmacos-carbon

FSFindFolder finds strange directory


I have the following code:

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);

So after code execution I expect to have "/User/myname/Library/Application Support" but I have "/private/var/root/Library/Application Support" instead. Does anybody know what the problem I've stumbled on?


Solution

  • /private/var/root is the home directory for the root user. Is this code running in a process with setuid or elevated privileges?