VirtualBox

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
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