- Timestamp:
- Nov 18, 2008 7:09:34 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/path.cpp
r14054 r14324 51 51 * 52 52 * @param pszPath Path which filename should be extracted from. 53 * If only filename in the string a '.' will be returned. 53 54 * 54 55 */ … … 56 57 { 57 58 char *psz = pszPath; 58 char *pszLastSep = pszPath; 59 char *pszLastSep = NULL; 60 59 61 60 62 for (;; psz++) … … 66 68 case ':': 67 69 pszLastSep = psz + 1; 70 if (RTPATH_IS_SLASH(psz[1])) 71 pszPath = psz + 1; 72 else 73 pszPath = psz; 68 74 break; 69 75 … … 76 82 /* the end */ 77 83 case '\0': 78 if (pszLastSep == pszPath) 79 *pszLastSep++ = '.'; 80 *pszLastSep = '\0'; 84 if (!pszLastSep) 85 { 86 /* no directory component */ 87 pszPath[0] = '.'; 88 pszPath[1] = '\0'; 89 } 90 else if (pszLastSep == pszPath) 91 { 92 /* only root. */ 93 pszLastSep[1] = '\0'; 94 } 95 else 96 pszLastSep[0] = '\0'; 81 97 return; 82 98 } … … 253 269 * 254 270 * @param pszPath Path to strip. 271 * 272 * @todo This isn't safe for a root element! Needs fixing. 255 273 */ 256 274 RTDECL(void) RTPathStripTrailingSlash(char *pszPath) -
trunk/src/VBox/Runtime/testcase/tstPath.cpp
r13836 r14324 36 36 #include <iprt/initterm.h> 37 37 #include <iprt/stream.h> 38 #include <iprt/string.h> 38 39 #include <iprt/err.h> 39 40 #include <iprt/param.h> … … 120 121 "\\temp", "\\data", 121 122 #endif 122 123 }; 123 124 124 125 for (unsigned i = 0; i < RT_ELEMENTS(aInput); i += 2) … … 131 132 132 133 /* 134 * RTPathStripFilename 135 */ 136 RTPrintf("tstPath: RTPathStripFilename...\n"); 137 static const char *apszStripFilenameTests[] = 138 { 139 "/usr/include///", "/usr/include//", 140 "/usr/include/", "/usr/include", 141 "/usr/include", "/usr", 142 "/usr", "/", 143 "usr", ".", 144 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) 145 "c:/windows", "c:/", 146 "c:/", "c:/", 147 "D:", "D:", 148 "C:\\OS2\\DLLS", "C:\\OS2", 149 #endif 150 }; 151 for (unsigned i = 0; i < RT_ELEMENTS(apszStripFilenameTests); i += 2) 152 { 153 const char *pszInput = apszStripFilenameTests[i]; 154 const char *pszExpect = apszStripFilenameTests[i + 1]; 155 char szPath[RTPATH_MAX]; 156 strcpy(szPath, pszInput); 157 RTPathStripFilename(szPath); 158 if (strcmp(szPath, pszExpect)) 159 { 160 RTPrintf("tstPath: RTPathStripFilename failed!\n" 161 " input: '%s'\n" 162 " output: '%s'\n" 163 "expected: '%s'\n", 164 pszInput, szPath, pszExpect); 165 cErrors++; 166 } 167 } 168 169 /* 133 170 * Summary. 134 171 */ 135 172 if (!cErrors) 136 RTPrintf("tst Timer: SUCCESS\n");173 RTPrintf("tstPath: SUCCESS\n"); 137 174 else 138 RTPrintf("tst Timer: FAILURE %d errors\n", cErrors);175 RTPrintf("tstPath: FAILURE %d errors\n", cErrors); 139 176 return !!cErrors; 140 177 }
Note:
See TracChangeset
for help on using the changeset viewer.