VirtualBox

Changeset 20111 in vbox for trunk/src


Ignore:
Timestamp:
May 28, 2009 12:34:52 AM (16 years ago)
Author:
vboxsync
Message:

IPRT: Use the generic RTDirCreateTemp implementation - made it a bit more flexible and added a testcase for it.

Location:
trunk/src/VBox/Runtime
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r20051 r20111  
    275275        generic/critsect-generic.cpp \
    276276        generic/env-generic.cpp \
     277        generic/RTDirCreateTemp-generic.cpp \
    277278        generic/RTFileCopy-generic.cpp \
    278279        generic/RTFileReadAll-generic.cpp \
  • trunk/src/VBox/Runtime/generic/RTDirCreateTemp-generic.cpp

    r20104 r20111  
    3737#include <iprt/assert.h>
    3838#include <iprt/err.h>
     39#include <iprt/path.h>
    3940#include <iprt/rand.h>
    4041#include <iprt/string.h>
     
    4445{
    4546    /*
    46      * Validate input.
     47     * Validate input and count X'es.
     48     *
     49     * The X'es may be trailing, or they may be a cluster of 3 or more inside
     50     * the file name.
    4751     */
    4852    AssertPtr(pszTemplate);
    4953    unsigned    cXes = 0;
    5054    char       *pszX = strchr(pszTemplate, '\0');
    51     while (pszX != pszTemplate && pszX[-1] == 'X')
     55    if (   pszX != pszTemplate
     56        && pszX[-1] != 'X')
     57    {
     58        /* look inside the file name. */
     59        char *pszFilename = RTPathFilename(pszTemplate);
     60        if (   pszFilename
     61            && (size_t)(pszX - pszFilename) > 3)
     62        {
     63            char *pszXEnd = pszX - 1;
     64            pszFilename += 3;
     65            do
     66            {
     67                if (    pszXEnd[-1] == 'X'
     68                    &&  pszXEnd[-2] == 'X'
     69                    &&  pszXEnd[-3] == 'X')
     70                {
     71                    pszX = pszXEnd - 3;
     72                    cXes = 3;
     73                    break;
     74                }
     75            } while (pszXEnd-- != pszFilename);
     76        }
     77    }
     78
     79    /* count them */
     80    while (   pszX != pszTemplate
     81           && pszX[-1] == 'X')
    5282    {
    5383        pszX--;
    5484        cXes++;
    5585    }
     86
     87    /* fail if none found. */
    5688    if (!cXes)
    5789    {
     
    70102        unsigned j = cXes;
    71103        while (j-- > 0)
    72             pszX[j] = s_sz[RTRandU32Ex(0, RT_ELEMENTS(s_sz) - 1)];
     104            pszX[j] = s_sz[RTRandU32Ex(0, RT_ELEMENTS(s_sz) - 2)];
    73105        int rc = RTDirCreate(pszTemplate, 0700);
    74106        if (RT_SUCCESS(rc))
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r20102 r20111  
    107107    LogFlow(("RTDirCreate(%p={%s}, %RTfmode): returns %Rrc\n", pszPath, pszPath, fMode, rc));
    108108    return rc;
    109 }
    110 
    111 
    112 RTDECL(int) RTDirCreateTemp(char *pszTemplate)
    113 {
    114     if (mkdtemp(pszTemplate))
    115         return VINF_SUCCESS;
    116 
    117     return RTErrConvertFromErrno(errno);
    118109}
    119110
  • trunk/src/VBox/Runtime/r3/win/dir-win.cpp

    r20103 r20111  
    129129
    130130
    131 RTDECL(int) RTDirCreateTemp(char *pszTemplate)
    132 {
    133     /** @todo r=bird: this doesn't work for more than 26 calls and it's racy:
    134      *        http://msdn.microsoft.com/en-us/library/34wc6k1f(VS.80).aspx */
    135     if (_mktemp(pszTemplate))
    136     {
    137         int rc = RTDirCreate(pszTemplate, 0700);
    138         return rc;
    139     }
    140     return RTErrConvertFromErrno(errno);
    141 }
    142 
    143 
    144131RTDECL(int) RTDirRemove(const char *pszPath)
    145132{
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r20108 r20111  
    8989        tstStrToNum \
    9090        tstSystemQueryOsInfo \
     91        tstRTTemp \
    9192        tstTermCallbacks \
    9293        tstThread-1 \
     
    348349tstSystemQueryOsInfo_SOURCES = tstSystemQueryOsInfo.cpp
    349350
     351tstRTTemp_TEMPLATE = VBOXR3TSTEXE
     352tstRTTemp_SOURCES = tstRTTemp.cpp
     353
    350354tstTermCallbacks_SOURCES = tstTermCallbacks.cpp
    351355
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