Ticket #2086: pathDetection.2.diff
File pathDetection.2.diff, 1.5 KB (added by , 9 years ago) |
---|
-
source/lib/sysdep/os/linux/linux.cpp
7 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 8 * permit persons to whom the Software is furnished to do so, subject to 9 9 * the following conditions: 10 * 10 * 11 11 * The above copyright notice and this permission notice shall be included 12 12 * in all copies or substantial portions of the Software. 13 * 13 * 14 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. … … 27 27 #define GNU_SOURCE 28 28 #include "mocks/dlfcn.h" 29 29 #include "mocks/unistd.h" 30 31 30 #include <cstdio> 32 31 32 33 static bool getPathFromProc(char* buffer, size_t length) 34 { 35 int pos = readlink("/proc/self/exe", buffer, length-1); 36 if (pos <= 0) 37 return false; 38 39 buffer[pos] = '\0'; 40 41 char* endOfPath = strrchr(buffer, '/'); 42 if (endOfPath == NULL) 43 return false; 44 45 ++endOfPath; 46 *endOfPath = '\0'; 47 48 return true; 49 } 50 33 51 OsPath sys_ExecutablePathname() 34 52 { 53 // Try to find the Path with readlink 54 char pathBuffer[PATH_MAX]; 55 if (getPathFromProc(pathBuffer, sizeof(pathBuffer))) 56 return pathBuffer; 57 35 58 // Find the executable's filename 36 59 Dl_info dl_info; 37 60 memset(&dl_info, 0, sizeof(dl_info));