VirtualBox

Changeset 11836 in vbox


Ignore:
Timestamp:
Aug 29, 2008 4:52:20 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
35668
Message:

IPRT: Implemented RTR3Init*WithProgramPath. Added RTPathParse. Cleaned up the RTPathProgram and RTProcGetExecutableName implementations.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/path.h

    r10911 r11836  
    231231 */
    232232RTDECL(void) RTPathStripTrailingSlash(char *pszPath);
     233
     234/**
     235 * Parses a path.
     236 *
     237 * It figures the length of the directory component, the offset of
     238 * the file name and the location of the suffix dot.
     239 *
     240 * @returns The path length.
     241 *
     242 * @param   pszPath     Path to find filename in.
     243 * @param   pcbDir      Where to put the length of the directory component.
     244 *                      If no directory, this will be 0. Optional.
     245 * @param   poffName    Where to store the filename offset.
     246 *                      If empty string or if it's ending with a slash this
     247 *                      will be set to -1. Optional.
     248 * @param   poffSuff    Where to store the suffix offset (the last dot).
     249 *                      If empty string or if it's ending with a slash this
     250 *                      will be set to -1. Optional.
     251 * @param   pfFlags     Where to set flags returning more information about
     252 *                      the path. For the future. Optional.
     253 */
     254RTDECL(size_t) RTPathParse(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff);
    233255
    234256/**
  • trunk/src/VBox/Runtime/Makefile.kmk

    r11814 r11836  
    310310        r3/win/process-win.cpp \
    311311        r3/win/RTLogWriteDebugger-win.cpp \
     312        r3/win/rtProcInitExePath-win.cpp \
    312313        r3/win/sched-win.cpp \
    313314        r3/win/sems-win.cpp \
     
    338339        generic/uuid-generic.cpp \
    339340        r3/linux/mp-linux.cpp \
     341        r3/linux/rtProcInitExePath-linux.cpp \
    340342        r3/linux/sched-linux.cpp \
    341343        r3/linux/time-linux.cpp \
     
    394396        r3/os2/filelock-os2.cpp \
    395397        r3/os2/mp-os2.cpp \
     398        r3/os2/rtProcInitExePath-os2.cpp \
    396399        r3/os2/sched-os2.cpp \
    397400        r3/os2/sems-os2.cpp \
     
    431434        r3/darwin/filelock-darwin.cpp \
    432435        r3/darwin/mp-darwin.cpp \
     436        r3/darwin/rtProcInitExePath-darwin.cpp \
    433437        r3/darwin/time-darwin.cpp \
    434438        r3/posix/RTSystemQueryOSInfo-posix.cpp \
     
    466470        generic/RTMpGetMaxFrequency-generic.cpp \
    467471        r3/freebsd/alloc-freebsd.cpp \
     472        r3/freebsd/rtProcInitExePath-freebsd.cpp \
    468473        r3/posix/RTSystemQueryOSInfo-posix.cpp \
    469474        r3/posix/dir-posix.cpp \
     
    523528        r3/posix/utf8-posix.cpp \
    524529        r3/solaris/alloc-solaris.cpp \
    525         r3/solaris/mp-solaris.cpp
     530        r3/solaris/mp-solaris.cpp \
     531        r3/solaris/rtProcInitExePath-solaris.cpp
    526532
    527533## PORTME: Porters add their selection of platform specific files for Ring-3 here.
     
    556562        generic/uuid-generic.cpp \
    557563        l4/l4-errno.cpp \
     564        l4/rtProcInitExePath-l4.cpp \
    558565        l4/process-l4env.cpp \
    559566        l4/sems-l4env.cpp \
  • trunk/src/VBox/Runtime/include/internal/path.h

    r8245 r11836  
    3636
    3737__BEGIN_DECLS
    38 extern char g_szrtProgramPath[RTPATH_MAX];
    3938
    4039#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
  • trunk/src/VBox/Runtime/include/internal/process.h

    r8245 r11836  
    3333
    3434#include <iprt/process.h>
     35#include <iprt/param.h>
    3536
    3637__BEGIN_DECLS
     
    3839extern RTPROCESS        g_ProcessSelf;
    3940extern RTPROCPRIORITY   g_enmProcessPriority;
     41extern char             g_szrtProcExePath[RTPATH_MAX];
     42extern size_t           g_cchrtProcExePath;
     43extern size_t           g_cchrtProcDir;
     44extern size_t           g_offrtProcName;
    4045
    4146/**
     
    5055int rtProcNativeSetPriority(RTPROCPRIORITY enmPriority);
    5156
     57/**
     58 * Determins the full path to the executable image.
     59 *
     60 * This is called by rtR3Init.
     61 *
     62 * @returns IPRT status code.
     63 *
     64 * @param   pszPath     Pointer to the g_szrtProcExePath buffer.
     65 * @param   cchPath     The size of the buffer.
     66 */
     67DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath);
     68
    5269__END_DECLS
    5370
  • trunk/src/VBox/Runtime/r3/init.cpp

    r11822 r11836  
    6969static bool volatile    g_fInitializing = false;
    7070
    71 /** Program path.
    72  * The size is hardcoded, so we'll have to check for overflow when setting it
    73  * since some hosts might support longer paths.
    74  * @internal
    75  */
    76 char        g_szrtProgramPath[RTPATH_MAX];
     71/** The process path.
     72 * This is used by RTPathProgram and RTProcGetExecutableName and set by rtProcInitName. */
     73char        g_szrtProcExePath[RTPATH_MAX];
     74/** The length of g_szrtProcExePath. */
     75size_t      g_cchrtProcExePath;
     76/** The length of directory path component of g_szrtProcExePath. */
     77size_t      g_cchrtProcDir;
     78/** The offset of the process name into g_szrtProcExePath. */
     79size_t      g_offrtProcName;
    7780
    7881/**
     
    100103 */
    101104RTPROCPRIORITY g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
     105
     106
     107
     108/**
     109 * Internal worker which initializes or re-initializes the
     110 * program path, name and directory globals.
     111 *
     112 * @returns IPRT status code.
     113 * @param   pszProgramPath  The program path, NULL if not specified.
     114 */
     115static int rtR3InitProgramPath(const char *pszProgramPath)
     116{
     117    /*
     118     * We're reserving 32 bytes here for file names as what not.
     119     */
     120    if (!pszProgramPath)
     121    {
     122        int rc = rtProcInitExePath(g_szrtProcExePath, sizeof(g_szrtProcExePath) - 32);
     123        if (RT_FAILURE(rc))
     124            return rc;
     125    }
     126    else
     127    {
     128        size_t cch = strlen(pszProgramPath);
     129        Assert(cch > 1);
     130        AssertMsgReturn(cch < sizeof(g_szrtProcExePath) - 32, ("%zu\n", cch), VERR_BUFFER_OVERFLOW);
     131        memcpy(g_szrtProcExePath, pszProgramPath, cch + 1);
     132    }
     133
     134    /*
     135     * Parse the name.
     136     */
     137    ssize_t offName;
     138    g_cchrtProcExePath = RTPathParse(g_szrtProcExePath, &g_cchrtProcDir, &offName, NULL);
     139    g_offrtProcName = offName;
     140    return VINF_SUCCESS;
     141}
    102142
    103143
     
    111151static int rtR3Init(bool fInitSUPLib, const char *pszProgramPath)
    112152{
     153    int rc = VINF_SUCCESS;
    113154    /* no entry log flow, because prefixes and thread may freak out. */
    114155
     
    128169            SUPR3Init(NULL);
    129170#endif
     171        if (pszProgramPath)
     172            rc = rtR3InitProgramPath(pszProgramPath);
     173        return rc;
    130174    }
    131175    ASMAtomicWriteBool(&g_fInitializing, true);
     
    154198     * without having initialized TLS entries and suchlike.
    155199     */
    156     int rc = rtThreadInit();
     200    rc = rtThreadInit();
    157201    if (RT_FAILURE(rc))
    158202    {
    159         AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
     203        AssertMsgFailed(("Failed to initialize threads, rc=%Rrc!\n", rc));
    160204        ASMAtomicWriteBool(&g_fInitializing, false);
    161205        ASMAtomicDecS32(&g_cUsers);
     
    181225    g_u64ProgramStartMilliTS = g_u64ProgramStartNanoTS / 1000000;
    182226
    183 #if !defined(IN_GUEST) && !defined(RT_NO_GIP)
    184     /*
    185      * The threading is initialized we can safely sleep a bit if GIP
    186      * needs some time to update itself updating.
    187      */
    188     if (fInitSUPLib && g_pSUPGlobalInfoPage)
    189     {
    190         RTThreadSleep(20);
    191         RTTimeNanoTS();
    192     }
    193 #endif
    194 
    195     /*
    196      * Get the executable path.
    197      *
    198      * We're also checking the depth here since we'll be
    199      * appending filenames to the executable path. Currently
    200      * we assume 16 bytes are what we need.
    201      */
    202     char szPath[RTPATH_MAX - 16];
    203     rc = RTPathProgram(szPath, sizeof(szPath));
    204     if (RT_FAILURE(rc))
    205     {
    206         AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
    207         ASMAtomicWriteBool(&g_fInitializing, false);
    208         ASMAtomicDecS32(&g_cUsers);
    209         return rc;
    210     }
    211 
    212227    /*
    213228     * The Process ID.
     
    220235
    221236    /*
    222      * More stuff to come.
     237     * The executable path, name and directory.
     238     */
     239    rc = rtR3InitProgramPath(pszProgramPath);
     240    if (RT_FAILURE(rc))
     241    {
     242        AssertLogRelMsgFailed(("Failed to get executable directory path, rc=%Rrc!\n", rc));
     243        ASMAtomicWriteBool(&g_fInitializing, false);
     244        ASMAtomicDecS32(&g_cUsers);
     245        return rc;
     246    }
     247
     248#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
     249    /*
     250     * The threading is initialized we can safely sleep a bit if GIP
     251     * needs some time to update itself updating.
     252     */
     253    if (fInitSUPLib && g_pSUPGlobalInfoPage)
     254    {
     255        RTThreadSleep(20);
     256        RTTimeNanoTS();
     257    }
     258#endif
     259
     260    /*
     261     * More stuff to come?
    223262     */
    224263
  • trunk/src/VBox/Runtime/r3/path.cpp

    r8245 r11836  
    4444#include "internal/fs.h"
    4545#include "internal/path.h"
     46#include "internal/process.h"
    4647
    4748
     
    121122
    122123/**
    123  * Finds the filename in a path.
    124  *
    125  * @returns Pointer to filename within pszPath.
    126  * @returns NULL if no filename (i.e. empty string or ends with a slash).
     124 * Parses a path.
     125 *
     126 * It figures the length of the directory component, the offset of
     127 * the file name and the location of the suffix dot.
     128 *
     129 * @returns The path length.
     130 *
    127131 * @param   pszPath     Path to find filename in.
    128  */
    129 RTDECL(char *) RTPathFilename(const char *pszPath)
     132 * @param   pcbDir      Where to put the length of the directory component.
     133 *                      If no directory, this will be 0. Optional.
     134 * @param   poffName    Where to store the filename offset.
     135 *                      If empty string or if it's ending with a slash this
     136 *                      will be set to -1. Optional.
     137 * @param   poffSuff    Where to store the suffix offset (the last dot).
     138 *                      If empty string or if it's ending with a slash this
     139 *                      will be set to -1. Optional.
     140 * @param   pfFlags     Where to set flags returning more information about
     141 *                      the path. For the future. Optional.
     142 */
     143RTDECL(size_t) RTPathParse(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff)
    130144{
    131145    const char *psz = pszPath;
    132     const char *pszLastComp = pszPath;
     146    ssize_t     offRoot = 0;
     147    const char *pszName = pszPath;
     148    const char *pszLastDot = NULL;
    133149
    134150    for (;; psz++)
     
    139155#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    140156            case ':':
    141                 pszLastComp = psz + 1;
     157                pszName = psz + 1;
     158                cchRoot = pszName - psz;
    142159                break;
    143160
     
    145162#endif
    146163            case '/':
    147                 pszLastComp = psz + 1;
     164                pszName = psz + 1;
     165                break;
     166
     167            case '.':
     168                pszLastDot = psz;
     169                break;
     170
     171            /*
     172             * The end. Complete the results.
     173             */
     174            case '\0':
     175            {
     176                ssize_t offName = *pszName != '\0' ? pszName - pszPath : -1;
     177                if (poffName)
     178                    *poffName = offName;
     179
     180                if (poffSuff)
     181                {
     182                    ssize_t offSuff = -1;
     183                    if (pszLastDot)
     184                    {
     185                        offSuff = pszLastDot - pszPath;
     186                        if (offSuff <= offName)
     187                            offSuff = -1;
     188                    }
     189                    *poffSuff = offSuff;
     190                }
     191
     192                if (pcchDir)
     193                {
     194                    ssize_t off = offName - 1;
     195                    while (off >= offRoot && RTPATH_IS_SLASH(pszPath[off]))
     196                        off--;
     197                    *pcchDir = RT_MAX(off, offRoot) + 1;
     198                }
     199
     200                return psz - pszPath;
     201            }
     202        }
     203    }
     204
     205    /* will never get here */
     206    return 0;
     207}
     208
     209
     210/**
     211 * Finds the filename in a path.
     212 *
     213 * @returns Pointer to filename within pszPath.
     214 * @returns NULL if no filename (i.e. empty string or ends with a slash).
     215 * @param   pszPath     Path to find filename in.
     216 */
     217RTDECL(char *) RTPathFilename(const char *pszPath)
     218{
     219    const char *psz = pszPath;
     220    const char *pszName = pszPath;
     221
     222    for (;; psz++)
     223    {
     224        switch (*psz)
     225        {
     226            /* handle separators. */
     227#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
     228            case ':':
     229                pszName = psz + 1;
     230                break;
     231
     232            case '\\':
     233#endif
     234            case '/':
     235                pszName = psz + 1;
    148236                break;
    149237
    150238            /* the end */
    151239            case '\0':
    152                 if (*pszLastComp)
    153                     return (char *)(void *)pszLastComp;
     240                if (*pszName)
     241                    return (char *)(void *)pszName;
    154242                return NULL;
    155243        }
     
    560648#ifndef RT_MINI
    561649
     650RTDECL(int) RTPathProgram(char *pszPath, unsigned cchPath)
     651{
     652    AssertReturn(g_szrtProcExePath[0], VERR_WRONG_ORDER);
     653
     654    /*
     655     * Calc the length and check if there is space before copying.
     656     */
     657    size_t cch = g_cchrtProcDir;
     658    if (cch <= cchPath)
     659    {
     660        memcpy(pszPath, g_szrtProcExePath, cch);
     661        pszPath[cch] = '\0';
     662        return VINF_SUCCESS;
     663    }
     664
     665    AssertMsgFailed(("Buffer too small (%zu <= %zu)\n", cchPath, cch));
     666    return VERR_BUFFER_OVERFLOW;
     667}
     668
     669
    562670/**
    563671 * Gets the directory for architecture-independent application data, for
  • trunk/src/VBox/Runtime/r3/posix/path-posix.cpp

    r11468 r11836  
    4343#include <sys/types.h>
    4444#include <pwd.h>
    45 #ifdef RT_OS_DARWIN
    46 # include <mach-o/dyld.h>
    47 #endif
    4845
    4946#include <iprt/path.h>
     
    5350#include <iprt/log.h>
    5451#include "internal/path.h"
     52#include "internal/process.h"
    5553#include "internal/fs.h"
    5654
     
    402400    return rc;
    403401}
    404 
    405 
    406 #ifndef RT_MINI
    407 RTDECL(int) RTPathProgram(char *pszPath, unsigned cchPath)
    408 {
    409     /*
    410      * First time only.
    411      */
    412     if (!g_szrtProgramPath[0])
    413     {     
    414         char* envPath = getenv("VBOX_PROGRAM_PATH");
    415         if (envPath)
    416         {
    417           strncpy(g_szrtProgramPath, envPath, sizeof(g_szrtProgramPath));
    418         } else {
    419         /*
    420          * Linux have no API for obtaining the executable path, but provides a symbolic link
    421          * in the proc file system. Note that readlink is one of the weirdest Unix apis around.
    422          *
    423          * OS/2 have an api for getting the program file name.
    424          */
    425 /** @todo use RTProcGetExecutableName() */
    426 #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
    427 # ifdef RT_OS_LINUX
    428         int cchLink = readlink("/proc/self/exe", &g_szrtProgramPath[0], sizeof(g_szrtProgramPath) - 1);
    429 # elif defined(RT_OS_SOLARIS)
    430         char szFileBuf[PATH_MAX + 1];
    431         sprintf(szFileBuf, "/proc/%ld/path/a.out", (long)getpid());
    432         int cchLink = readlink(szFileBuf, &g_szrtProgramPath[0], sizeof(g_szrtProgramPath) - 1);
    433 # else /* RT_OS_FREEBSD: */
    434         int cchLink = readlink("/proc/curproc/file", &g_szrtProgramPath[0], sizeof(g_szrtProgramPath) - 1);
    435 # endif
    436         if (cchLink < 0 || cchLink == sizeof(g_szrtProgramPath) - 1)
    437         {
    438             int rc = RTErrConvertFromErrno(errno);
    439             AssertMsgFailed(("couldn't read /proc/self/exe. errno=%d cchLink=%d\n", errno, cchLink));
    440             LogFlow(("RTPathProgram(%p, %u): returns %Rrc\n", pszPath, cchPath, rc));
    441             return rc;
    442         }
    443         g_szrtProgramPath[cchLink] = '\0';
    444 
    445 #elif defined(RT_OS_OS2) || defined(RT_OS_L4)
    446         _execname(g_szrtProgramPath, sizeof(g_szrtProgramPath));
    447 
    448 #elif defined(RT_OS_DARWIN)
    449         const char *pszImageName = _dyld_get_image_name(0);
    450         AssertReturn(pszImageName, VERR_INTERNAL_ERROR);
    451         size_t cchImageName = strlen(pszImageName);
    452         if (cchImageName >= sizeof(g_szrtProgramPath))
    453             AssertReturn(pszImageName, VERR_INTERNAL_ERROR);
    454         memcpy(g_szrtProgramPath, pszImageName, cchImageName + 1);
    455 
    456 #else
    457 # error needs porting.
    458 #endif
    459         }
    460         /*
    461          * Convert to UTF-8 and strip of the filename.
    462          */
    463         char *pszTmp = NULL;
    464         int rc = rtPathFromNative(&pszTmp, &g_szrtProgramPath[0]);
    465         if (RT_FAILURE(rc))
    466         {
    467             LogFlow(("RTPathProgram(%p, %u): returns %Rrc\n", pszPath, cchPath, rc));
    468             return rc;
    469         }
    470         size_t cch = strlen(pszTmp);
    471         if (cch >= sizeof(g_szrtProgramPath))
    472         {
    473             RTStrFree(pszTmp);
    474             LogFlow(("RTPathProgram(%p, %u): returns %Rrc\n", pszPath, cchPath, VERR_BUFFER_OVERFLOW));
    475             return VERR_BUFFER_OVERFLOW;
    476         }
    477         memcpy(g_szrtProgramPath, pszTmp, cch + 1);
    478         RTPathStripFilename(g_szrtProgramPath);
    479         RTStrFree(pszTmp);
    480     }
    481 
    482     /*
    483      * Calc the length and check if there is space before copying.
    484      */
    485     unsigned cch = strlen(g_szrtProgramPath) + 1;
    486     if (cch <= cchPath)
    487     {
    488         memcpy(pszPath, g_szrtProgramPath, cch + 1);
    489         LogFlow(("RTPathProgram(%p:{%s}, %u): returns %Rrc\n", pszPath, pszPath, cchPath, VINF_SUCCESS));
    490         return VINF_SUCCESS;
    491     }
    492 
    493     AssertMsgFailed(("Buffer too small (%d < %d)\n", cchPath, cch));
    494     LogFlow(("RTPathProgram(%p, %u): returns %Rrc\n", pszPath, cchPath, VERR_BUFFER_OVERFLOW));
    495     return VERR_BUFFER_OVERFLOW;
    496 }
    497 #endif /* !RT_MINI */
    498402
    499403
  • trunk/src/VBox/Runtime/r3/posix/process-posix.cpp

    r11337 r11836  
    235235
    236236
    237 RTR3DECL(char *) RTProcGetExecutableName(char *pszExecName, size_t cchExecName)
    238 {
    239     /*
    240      * I don't think there is a posix API for this, but
    241      * because I'm lazy I'm not creating OS specific code
    242      * files and code for this.
    243      */
    244 #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
    245 # ifdef RT_OS_LINUX
    246     int cchLink = readlink("/proc/self/exe", pszExecName, cchExecName - 1);
    247 # elif defined(RT_OS_SOLARIS)
    248     char szFileBuf[80];
    249     RTStrPrintf(szFileBuf, sizeof(szFileBuf), "/proc/%ld/path/a.out", (long)getpid());
    250     int cchLink = readlink(szFileBuf, pszExecName, cchExecName - 1);
    251 # else
    252     int cchLink = readlink("/proc/curproc/file", pszExecName, cchExecName - 1);
    253 # endif
    254     if (cchLink > 0 && (size_t)cchLink <= cchExecName - 1)
    255     {
    256         pszExecName[cchLink] = '\0';
    257         return pszExecName;
    258     }
    259 
    260 #elif defined(RT_OS_OS2) || defined(RT_OS_L4)
    261     if (!_execname(pszExecName, cchExecName))
    262         return pszExecName;
    263 
    264 #elif defined(RT_OS_DARWIN)
    265     const char *pszImageName = _dyld_get_image_name(0);
    266     if (pszImageName)
    267     {
    268         size_t cchImageName = strlen(pszImageName);
    269         if (cchImageName < cchExecName)
    270             return (char *)memcpy(pszExecName, pszImageName, cchImageName + 1);
    271     }
    272 
    273 #else
    274 #   error "Port me!"
    275 #endif
    276     return NULL;
    277 }
    278 
    279237/**
    280238 * Daemonize the current process, making it a background process. The current
  • trunk/src/VBox/Runtime/r3/process.cpp

    r8245 r11836  
    3737#include <iprt/assert.h>
    3838#include <iprt/err.h>
     39#include <iprt/string.h>
    3940#include "internal/process.h"
    4041#include "internal/thread.h"
     
    9495}
    9596
     97
     98RTR3DECL(char *) RTProcGetExecutableName(char *pszExecName, size_t cchExecName)
     99{
     100    AssertReturn(g_szrtProcExePath[0] != '\0', NULL);
     101
     102    /*
     103     * Calc the length and check if there is space before copying.
     104     */
     105    size_t cch = g_cchrtProcExePath;
     106    if (cch <= cchExecName)
     107    {
     108        memcpy(pszExecName, g_szrtProcExePath, cch);
     109        pszExecName[cch] = '\0';
     110        return pszExecName;
     111    }
     112
     113    AssertMsgFailed(("Buffer too small (%zu <= %zu)\n", cchExecName, cch));
     114    return NULL;
     115}
     116
  • trunk/src/VBox/Runtime/r3/win/path-win.cpp

    r10911 r11836  
    120120
    121121    return rc;
    122 }
    123 
    124 
    125 /**
    126  * Gets the program path.
    127  *
    128  * @returns iprt status code.
    129  * @param   pszPath     Buffer where to store the path.
    130  * @param   cchPath     Buffer size in bytes.
    131  */
    132 RTDECL(int) RTPathProgram(char *pszPath, unsigned cchPath)
    133 {
    134     /*
    135      * First time only.
    136      */
    137     if (!g_szrtProgramPath[0])
    138     {
    139         HMODULE hExe = GetModuleHandle(NULL);
    140         if (!GetModuleFileName(hExe, &g_szrtProgramPath[0], sizeof(g_szrtProgramPath)))
    141         {
    142             AssertMsgFailed(("Couldn't get exe module name. lasterr=%d\n", GetLastError()));
    143             return RTErrConvertFromWin32(GetLastError());
    144         }
    145         RTPathStripFilename(g_szrtProgramPath);
    146     }
    147 
    148     /*
    149      * Calc the length and check if there is space before copying.
    150      */
    151     unsigned cch = strlen(g_szrtProgramPath) + 1;
    152     if (cch <= cchPath)
    153     {
    154         memcpy(pszPath, g_szrtProgramPath, cch + 1);
    155         return VINF_SUCCESS;
    156     }
    157 
    158     AssertMsgFailed(("Buffer too small (%d < %d)\n", cchPath, cch));
    159     return VERR_BUFFER_OVERFLOW;
    160122}
    161123
  • trunk/src/VBox/Runtime/r3/win/process-win.cpp

    r8245 r11836  
    244244}
    245245
    246 
    247 RTR3DECL(char *) RTProcGetExecutableName(char *pszExecName, size_t cchExecName)
    248 {
    249     HMODULE hExe = GetModuleHandle(NULL);
    250     if (GetModuleFileName(hExe, pszExecName, cchExecName))
    251         return pszExecName;
    252     return NULL;
    253 }
    254 
  • trunk/src/VBox/Runtime/testcase/tstPath.cpp

    r8245 r11836  
    3333*******************************************************************************/
    3434#include <iprt/path.h>
    35 #include <iprt/runtime.h>
     35#include <iprt/process.h>
     36#include <iprt/initterm.h>
    3637#include <iprt/stream.h>
    3738#include <iprt/err.h>
     
    4546        { \
    4647            cErrors++; \
    47             RTPrintf("\ntstPath: FAILED calling " #method " at line %d: rc=%Vrc\n", __LINE__, rc); \
     48            RTPrintf("\ntstPath: FAILED calling " #method " at line %d: rc=%Rrc\n", __LINE__, rc); \
    4849        } \
    4950    } while (0)
     
    6162
    6263    /*
    63      * RTPathProgram, RTPathUserHome
     64     * RTPathProgram, RTPathUserHome and RTProcGetExecutableName.
    6465     */
    6566    char szPath[RTPATH_MAX];
     
    7071    if (RT_SUCCESS(rc))
    7172        RTPrintf("UserHome={%s}\n", szPath);
     73    if (RTProcGetExecutableName(szPath, sizeof(szPath)) == szPath)
     74        RTPrintf("ExecutableName={%s}\n", szPath);
     75    else
     76    {
     77        RTPrintf("tstPath: FAILED - RTProcGetExecutableName\n");
     78        cErrors++;
     79    }
     80   
    7281
    7382    /*
Note: See TracChangeset for help on using the changeset viewer.

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