Changeset 26476 in vbox
- Timestamp:
- Feb 13, 2010 2:06:41 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 57643
- Location:
- trunk
- Files:
-
- 5 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/getopt.h
r25351 r26476 358 358 RTDECL(int) RTGetOptPrintError(int ch, PCRTGETOPTUNION pValueUnion); 359 359 360 /** 361 * Parses the @a pszCmdLine string into an argv array. 362 * 363 * This is useful for converting a response file or similar to an argument 364 * vector that can be used with RTGetOptInit(). 365 * 366 * This function aims at following the bourn shell string quoting rules. 367 * 368 * @returns IPRT status code. 369 * 370 * @param ppapszArgv Where to return the argument vector. This must be 371 * freed by calling RTGetOptArgvFree. 372 * @param pcArgs Where to return the argument count. 373 * @param pszCmdLine The string to parse. 374 * @param pszSeparators String containing the argument separators. If NULL, 375 * then space, tab, line feed (\\n) and return (\\r) 376 * are used. 377 */ 378 RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine, const char *pszSeparators); 379 380 /** 381 * Frees and argument vector returned by RTGetOptStringToArgv. 382 * 383 * @param papszArgv Argument vector. NULL is fine. 384 */ 385 RTDECL(void) RTGetOptArgvFree(char **paArgv); 386 360 387 /** @} */ 361 388 -
trunk/include/iprt/path.h
r26133 r26476 320 320 321 321 /** 322 * Counts the components in the specified path. 323 * 324 * An empty string has zero components. A lone root slash is considered have 325 * one. The paths "/init" and "/bin/" are considered having two components. An 326 * UNC share specifier like "\\myserver\share" will be considered as one single 327 * component. 328 * 329 * @returns The number of path components. 330 * @param pszPath The path to parse. 331 */ 332 RTDECL(size_t) RTPathCountComponents(const char *pszPath); 333 334 /** 335 * Copies the specified number of path components from @a pszSrc and into @a 336 * pszDst. 337 * 338 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. In the latter case the buffer 339 * is not touched. 340 * 341 * @param pszDst The destination buffer. 342 * @param cbDst The size of the destination buffer. 343 * @param pszSrc The source path. 344 * @param cComponents The number of components to copy from @a pszSrc. 345 */ 346 RTDECL(int) RTPathCopyComponents(char *pszDst, size_t cbDst, const char *pszSrc, size_t cComponents); 347 348 /** 322 349 * Compares two paths. 323 350 * -
trunk/src/VBox/Runtime/Makefile.kmk
r26416 r26476 252 252 common/misc/cidr.cpp \ 253 253 common/misc/getopt.cpp \ 254 common/misc/getoptargv.cpp \ 254 255 common/misc/handletable.cpp \ 255 256 common/misc/handletablectx.cpp \ … … 266 267 common/misc/term.cpp \ 267 268 common/misc/tar.cpp \ 269 common/path/rtPathRootSpecLen.cpp \ 268 270 common/path/rtPathVolumeSpecLen.cpp \ 269 271 common/path/RTPathAbsDup.cpp \ … … 271 273 common/path/RTPathAbsExDup.cpp \ 272 274 common/path/RTPathAppend.cpp \ 275 common/path/RTPathCopyComponents.cpp \ 276 common/path/RTPathCountComponents.cpp \ 273 277 common/path/RTPathExt.cpp \ 274 278 common/path/RTPathFilename.cpp \ -
trunk/src/VBox/Runtime/common/path/RTPathAppend.cpp
r21676 r26476 35 35 #include "internal/iprt.h" 36 36 #include <iprt/path.h> 37 37 38 #include <iprt/assert.h> 38 39 #include <iprt/ctype.h> … … 50 51 * 51 52 * @remarks Unnecessary root slashes will not be counted. The caller will have 52 * to deal with it where it matters. 53 * to deal with it where it matters. (Unlike rtPathRootSpecLen which 54 * counts them.) 53 55 */ 54 static size_t rtPathRootSpecLen (const char *pszPath)56 static size_t rtPathRootSpecLen2(const char *pszPath) 55 57 { 56 58 /* fend of wildlife. */ … … 170 172 /* In the leading path we can skip unnecessary trailing slashes, but 171 173 be sure to leave one. */ 172 size_t const cchRoot = rtPathRootSpecLen (pszPath);174 size_t const cchRoot = rtPathRootSpecLen2(pszPath); 173 175 while ( (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot) 174 176 && RTPATH_IS_SLASH(pszPathEnd[-2])) -
trunk/src/VBox/Runtime/common/path/rtPathVolumeSpecLen.cpp
r21678 r26476 44 44 * If no such specifier zero is returned. 45 45 */ 46 size_trtPathVolumeSpecLen(const char *pszPath)46 DECLHIDDEN(size_t) rtPathVolumeSpecLen(const char *pszPath) 47 47 { 48 48 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) -
trunk/src/VBox/Runtime/include/internal/path.h
r21675 r26476 43 43 44 44 45 size_t rtPathVolumeSpecLen(const char *pszPath); 46 int rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType); 47 int rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType); 45 DECLHIDDEN(size_t) rtPathRootSpecLen(const char *pszPath); 46 DECLHIDDEN(size_t) rtPathVolumeSpecLen(const char *pszPath); 47 DECLHIDDEN(int) rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType); 48 DECLHIDDEN(int) rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType); 48 49 49 50 -
trunk/src/VBox/Runtime/r3/posix/path-posix.cpp
r25898 r26476 662 662 * not a directory (we are NOT checking whether it's a file). 663 663 */ 664 intrtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType)664 DECLHIDDEN(int) rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType) 665 665 { 666 666 /* -
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r23375 r26476 455 455 * not a directory (we are NOT checking whether it's a file). 456 456 */ 457 intrtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType)457 DECLHIDDEN(int) rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType) 458 458 { 459 459 /* -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r26419 r26476 66 66 tstFork \ 67 67 tstGetOpt \ 68 tstRTGetOptArgv \ 68 69 tstHandleTable \ 69 70 tstRTHeapOffset \ … … 202 203 tstGetOpt_SOURCES = tstGetOpt.cpp 203 204 205 tstRTGetOptArgv_TEMPLATE = VBOXR3TSTEXE 206 tstRTGetOptArgv_SOURCES = tstRTGetOptArgv.cpp 207 204 208 tstHandleTable_SOURCES = tstHandleTable.cpp 205 209 -
trunk/src/VBox/Runtime/testcase/tstRTPath.cpp
r26133 r26476 414 414 415 415 /* 416 * RTPathCountComponents 417 */ 418 RTTestSub(hTest, "RTPathCountComponents"); 419 RTTESTI_CHECK(RTPathCountComponents("") == 0); 420 RTTESTI_CHECK(RTPathCountComponents("/") == 1); 421 RTTESTI_CHECK(RTPathCountComponents("//") == 1); 422 RTTESTI_CHECK(RTPathCountComponents("//////////////") == 1); 423 RTTESTI_CHECK(RTPathCountComponents("//////////////bin") == 2); 424 RTTESTI_CHECK(RTPathCountComponents("//////////////bin/") == 2); 425 RTTESTI_CHECK(RTPathCountComponents("//////////////bin/////") == 2); 426 RTTESTI_CHECK(RTPathCountComponents("..") == 1); 427 RTTESTI_CHECK(RTPathCountComponents("../") == 1); 428 RTTESTI_CHECK(RTPathCountComponents("../..") == 2); 429 RTTESTI_CHECK(RTPathCountComponents("../../") == 2); 430 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) 431 RTTESTI_CHECK(RTPathCountComponents("d:") == 1); 432 RTTESTI_CHECK(RTPathCountComponents("d:/") == 1); 433 RTTESTI_CHECK(RTPathCountComponents("d:/\\") == 1); 434 RTTESTI_CHECK(RTPathCountComponents("d:\\") == 1); 435 RTTESTI_CHECK(RTPathCountComponents("c:\\config.sys") == 2); 436 RTTESTI_CHECK(RTPathCountComponents("c:\\windows") == 2); 437 RTTESTI_CHECK(RTPathCountComponents("c:\\windows\\") == 2); 438 RTTESTI_CHECK(RTPathCountComponents("c:\\windows\\system32") == 3); 439 RTTESTI_CHECK(RTPathCountComponents("//./C$") == 1); 440 RTTESTI_CHECK(RTPathCountComponents("\\\\.\\C$") == 1); 441 RTTESTI_CHECK(RTPathCountComponents("/\\.\\C$") == 1); 442 RTTESTI_CHECK(RTPathCountComponents("//myserver") == 1); 443 RTTESTI_CHECK(RTPathCountComponents("//myserver/") == 1); 444 RTTESTI_CHECK(RTPathCountComponents("//myserver/share") == 1); 445 RTTESTI_CHECK(RTPathCountComponents("//myserver/share/") == 1); 446 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\") == 1); 447 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\x") == 2); 448 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\x\\y") == 3); 449 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\x\\y\\") == 3); 450 #endif 451 452 /* 453 * RTPathCopyComponents 454 */ 455 struct 456 { 457 const char *pszSrc; 458 size_t cComponents; 459 const char *pszResult; 460 } s_aCopyComponents[] = 461 { 462 { "", 0, "" }, 463 { "", 5, "" }, 464 { "/", 0, "" }, 465 { "/", 1, "/" }, 466 { "/", 2, "/" }, 467 { "/usr/bin/sed", 0, "" }, 468 { "/usr/bin/sed", 1, "/" }, 469 { "/usr/bin/sed", 2, "/usr/" }, 470 { "/usr/bin/sed", 3, "/usr/bin/" }, 471 { "/usr/bin/sed", 4, "/usr/bin/sed" }, 472 { "/usr/bin/sed", 5, "/usr/bin/sed" }, 473 { "/usr/bin/sed", 6, "/usr/bin/sed" }, 474 { "/usr///bin/sed", 2, "/usr///" }, 475 }; 476 for (unsigned i = 0; i < RT_ELEMENTS(s_aCopyComponents); i++) 477 { 478 const char *pszInput = s_aCopyComponents[i].pszSrc; 479 size_t cComponents = s_aCopyComponents[i].cComponents; 480 const char *pszResult = s_aCopyComponents[i].pszResult; 481 482 memset(szPath, 'a', sizeof(szPath)); 483 rc = RTPathCopyComponents(szPath, sizeof(szPath), pszInput, cComponents); 484 RTTESTI_CHECK_RC(rc, VINF_SUCCESS); 485 if (RT_SUCCESS(rc) && strcmp(szPath, pszResult)) 486 RTTestIFailed("Unexpected result\n" 487 " input: '%s' cComponents=%u\n" 488 " output: '%s'\n" 489 "expected: '%s'", 490 pszInput, cComponents, szPath, pszResult); 491 else if (RT_SUCCESS(rc)) 492 { 493 RTTESTI_CHECK_RC(RTPathCopyComponents(szPath, strlen(pszResult) + 1, pszInput, cComponents), VINF_SUCCESS); 494 RTTESTI_CHECK_RC(RTPathCopyComponents(szPath, strlen(pszResult), pszInput, cComponents), VERR_BUFFER_OVERFLOW); 495 } 496 } 497 498 /* 416 499 * Summary. 417 500 */
Note:
See TracChangeset
for help on using the changeset viewer.