Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

int com::GetVBoxUserHomeDirectory ( char *  aDir,
size_t  aDirLen 
)

Returns the VirtualBox user home directory.

On failure, this function will return a path that caused a failure (or NULL if the faiulre is not path-related).

On success, this function will try to create the returned directory if it doesn't exist yet. This may also fail with the corresponding status code.

If aDirLen is smaller than RTPATH_MAX then there is a great chance that this method will return VERR_BUFFER_OVERFLOW.

Parameters:
aDir Buffer to store the directory string in UTF-8 encoding.
aDirLen Length of the supplied buffer including space for the terminating null character, in bytes.
Returns:
VBox status code.

Definition at line 139 of file com.cpp.

References AssertReturn, NULL, RT_SUCCESS, RTPATH_DELIMITER, RTPATH_MAX, strlen(), VERR_BUFFER_OVERFLOW, VERR_INVALID_POINTER, and VINF_SUCCESS.

Referenced by Initialize(), and main().

{
    AssertReturn (aDir, VERR_INVALID_POINTER);
    AssertReturn (aDirLen > 0, VERR_BUFFER_OVERFLOW);

    /* start with null */
    *aDir = 0;

    const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME");

    char path [RTPATH_MAX];
    int vrc = VINF_SUCCESS;

    if (VBoxUserHome)
    {
        /* get the full path name */
        char *VBoxUserHomeUtf8 = NULL;
        vrc = RTStrCurrentCPToUtf8 (&VBoxUserHomeUtf8, VBoxUserHome);
        if (RT_SUCCESS (vrc))
        {
            vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path));
            if (RT_SUCCESS (vrc))
            {
                if (aDirLen < strlen (path) + 1)
                    vrc = VERR_BUFFER_OVERFLOW;
                else
                    strcpy (aDir, path);
            }
            RTStrFree (VBoxUserHomeUtf8);
        }
    }
    else
    {
        /* compose the config directory (full path) */
        vrc = RTPathUserHome (path, sizeof (path));
        if (RT_SUCCESS (vrc))
        {
            size_t len =
                RTStrPrintf (aDir, aDirLen, "%s%c%s",
                             path, RTPATH_DELIMITER, VBOX_USER_HOME_SUFFIX);
            if (len != strlen (path) + 1 + strlen (VBOX_USER_HOME_SUFFIX))
                vrc = VERR_BUFFER_OVERFLOW;
        }
    }

    /* ensure the home directory exists */
    if (RT_SUCCESS (vrc))
        if (!RTDirExists (aDir))
            vrc = RTDirCreateFullPath (aDir, 0777);

    return vrc;
}


Generated by  Doxygen 1.6.0   Back to index