VirtualBox

Changeset 20018 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
May 26, 2009 9:37:49 AM (16 years ago)
Author:
vboxsync
Message:

Runtime: Added method for returning the system temporary directory path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/path.cpp

    r19929 r20018  
    4242#include <iprt/err.h>
    4343#include <iprt/uni.h>
     44#include <iprt/env.h>
    4445#include "internal/fs.h"
    4546#include "internal/path.h"
     
    963964}
    964965
     966/**
     967 * Gets the temporary directory path.
     968 *
     969 * @returns iprt status code.
     970 * @param   pszPath     Buffer where to store the path.
     971 * @param   cchPath     Buffer size in bytes.
     972 */
     973RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath)
     974{
     975    char *pszResult;
     976    int rc;
     977    const char *pszTmpEnv = RTEnvGet("TMP");
     978    if (!pszTmpEnv)
     979        pszTmpEnv = RTEnvGet("TEMP");
     980    char *pszTmpDir;
     981    /* Make a copy in any case. */
     982    if (pszTmpEnv)
     983        pszTmpDir = RTStrDup(pszTmpEnv);
     984    else
     985        pszTmpDir = RTStrDup("/tmp");
     986
     987    size_t cchTmpDir = strlen(pszTmpDir);
     988    if (cchTmpDir < cchPath)
     989        memcpy(pszPath, pszTmpDir, cchTmpDir + 1);
     990    else
     991        rc = VERR_BUFFER_OVERFLOW;
     992    RTStrFree(pszTmpDir);
     993    return rc;
     994}
     995
    965996#endif /* !RT_MINI */
    966997
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette