- Timestamp:
- Mar 9, 2007 9:39:20 AM (18 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMDevice.cpp
r838 r1354 573 573 { 574 574 /* make filename */ 575 char *pszFilename = pdmR3FileR3("VBoxDD" );575 char *pszFilename = pdmR3FileR3("VBoxDD", /*fShared=*/true); 576 576 if (!pszFilename) 577 577 return VERR_NO_TMP_MEMORY; … … 582 582 583 583 /* make filename */ 584 pszFilename = pdmR3FileR3("VBoxDD2" );584 pszFilename = pdmR3FileR3("VBoxDD2", /*fShared=*/true); 585 585 if (!pszFilename) 586 586 return VERR_NO_TMP_MEMORY; -
trunk/src/VBox/VMM/PDMDriver.cpp
r914 r1354 204 204 { 205 205 /* make filename */ 206 char *pszFilename = pdmR3FileR3("VBoxDD" );206 char *pszFilename = pdmR3FileR3("VBoxDD", /*fShared=*/true); 207 207 if (!pszFilename) 208 208 return VERR_NO_TMP_MEMORY; -
trunk/src/VBox/VMM/PDMInternal.h
r526 r1354 724 724 int pdmR3LdrInit(PVM pVM); 725 725 void pdmR3LdrTerm(PVM pVM); 726 char * pdmR3FileR3(const char *pszFile );726 char * pdmR3FileR3(const char *pszFile, bool fShared=false); 727 727 int pdmR3LoadR3(PVM pVM, const char *pszFilename, const char *pszName); 728 728 -
trunk/src/VBox/VMM/PDMLdr.cpp
r1308 r1354 67 67 static char * pdmR3FileGC(const char *pszFile); 68 68 static char * pdmR3FileR0(const char *pszFile); 69 static char * pdmR3File(const char *pszFile, const char *pszDefaultExt );69 static char * pdmR3File(const char *pszFile, const char *pszDefaultExt, bool fShared); 70 70 static DECLCALLBACK(int) pdmR3QueryModFromEIPEnumSymbols(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser); 71 71 … … 834 834 * @todo We'll have this elsewhere than in the root later! 835 835 */ 836 char *pdmR3FileR3(const char *pszFile )837 { 838 return pdmR3File(pszFile, NULL );836 char *pdmR3FileR3(const char *pszFile, bool fShared) 837 { 838 return pdmR3File(pszFile, NULL, fShared); 839 839 } 840 840 … … 851 851 char * pdmR3FileR0(const char *pszFile) 852 852 { 853 return pdmR3File(pszFile, NULL );853 return pdmR3File(pszFile, NULL, /*fShared=*/false); 854 854 } 855 855 … … 866 866 char * pdmR3FileGC(const char *pszFile) 867 867 { 868 return pdmR3File(pszFile, NULL); 869 } 870 868 return pdmR3File(pszFile, NULL, /*fShared=*/false); 869 } 870 871 /** 872 * Worker for pdmR3File(). 873 * 874 * @returns Pointer to temporary memory containing the filename. 875 * Caller must free this using RTMemTmpFree(). 876 * @returns NULL on failure. 877 * @param pszDir Directory part 878 * @param pszFile File name part 879 * @param pszDefaultExt Extension part 880 */ 881 static char * pdmR3FileConstruct(const char *pszDir, const char *pszFile, const char *pszDefaultExt) 882 { 883 /* 884 * Allocate temp memory for return buffer. 885 */ 886 unsigned cchDir = strlen(pszDir); 887 unsigned cchFile = strlen(pszFile); 888 unsigned cchDefaultExt; 889 890 /* 891 * Default extention? 892 */ 893 if (!pszDefaultExt || strchr(pszFile, '.')) 894 cchDefaultExt = 0; 895 else 896 cchDefaultExt = strlen(pszDefaultExt); 897 898 unsigned cchPath = cchDir + 1 + cchFile + cchDefaultExt + 1; 899 if (cchPath > RTPATH_MAX) 900 { 901 AssertMsgFailed("Path too long!\n"); 902 return NULL; 903 } 904 905 char *pszRet = (char *)RTMemTmpAlloc(cchDir + 1 + cchFile + cchDefaultExt + 1); 906 if (!pszRet) 907 { 908 AssertMsgFailed(("Out of temporary memory!\n")); 909 return NULL; 910 } 911 912 /* 913 * Construct the filename. 914 */ 915 memcpy(pszRet, pszDir, cchDir); 916 pszRet[cchDir++] = '/'; /* this works everywhere */ 917 memcpy(pszRet + cchDir, pszFile, cchFile + 1); 918 if (cchDefaultExt) 919 memcpy(pszRet + cchDir + cchFile, pszDefaultExt, cchDefaultExt + 1); 920 921 return pszRet; 922 } 871 923 872 924 /** … … 878 930 * @param pszFile File name (no path). 879 931 * @param pszDefaultExt The default extention, NULL if none. 932 * @param fShared If true, search in the shared directory (/usr/lib on Unix), else 933 * search in the private directory (/usr/lib/virtualbox on Unix). 934 * Ignored if VBOX_PATH_SHARED_LIBS is not defined. 880 935 * @todo We'll have this elsewhere than in the root later! 881 */ 882 static char * pdmR3File(const char *pszFile, const char *pszDefaultExt) 883 { 884 /* 885 * Default extention? 886 */ 887 unsigned cchDefaultExt; 888 if (!pszDefaultExt || strchr(pszFile, '.')) 889 cchDefaultExt = 0; 890 else 891 cchDefaultExt = strlen(pszDefaultExt); 892 893 /* 894 * Query program path. 895 */ 896 unsigned cchFile = strlen(pszFile); 897 char szPath[RTPATH_MAX]; 898 int rc = RTPathProgram(szPath, sizeof(szPath) - cchFile - cchDefaultExt - 1); 936 * @todo Remove the fShared hack again once we don't need to link against VBoxDD anymore! 937 */ 938 static char * pdmR3File(const char *pszFile, const char *pszDefaultExt, bool fShared) 939 { 940 char *pszRet; 941 942 #ifdef VBOX_PATH_PRIVATE_LIBS 943 944 /* 945 * Unix: Search in /usr/lib/virtualbox 946 */ 947 pszRet = pdmR3FileConstruct( 948 # ifdef VBOX_PATH_SHARED_LIBS 949 fShared ? VBOX_PATH_SHARED_LIBS : VBOX_PATH_PRIVATE_LIBS, 950 # else 951 VBOX_PATH_PRIVATE_LIBS, 952 # endif 953 pszFile, pszDefaultExt); 954 955 #else 956 957 NOREF(fShared); 958 959 /* 960 * Default: Search in the program path. 961 */ 962 char szPath[RTPATH_MAX]; 963 int rc = RTPathProgram(szPath, sizeof(szPath)); 899 964 if (!VBOX_SUCCESS(rc)) 900 965 { … … 903 968 } 904 969 905 /* 906 * Allocate temp memory for return buffer. 907 */ 908 unsigned cch = strlen(szPath); 909 char *pszRet = (char *)RTMemTmpAlloc(cch + 1 + cchFile + cchDefaultExt + 1); 910 if (!pszRet) 911 { 912 AssertMsgFailed(("Out of temporary memory!\n")); 913 return NULL; 914 } 915 916 /* 917 * Construct the filename. 918 */ 919 memcpy(pszRet, szPath, cch); 920 pszRet[cch++] = '/'; /* this works everywhere */ 921 memcpy(pszRet + cch, pszFile, cchFile + 1); 922 if (cchDefaultExt) 923 memcpy(pszRet + cch + cchFile, pszDefaultExt, cchDefaultExt + 1); 970 pszRet = pdmR3FileConstruct(szPath, pszFile, pszDefaultExt); 971 972 #endif 973 924 974 return pszRet; 925 975 }
Note:
See TracChangeset
for help on using the changeset viewer.