given a path, it cleans it up (if the path is c:\windows\..\dos it would make it c:\dos) srcPath is the original path dest is the finished cleaned path. dest should be at least _MAX_PATH in size
| 381 | // dest is the finished cleaned path. |
| 382 | // dest should be at least _MAX_PATH in size |
| 383 | void ddio_CleanPath(char *dest, const char *srcPath) { |
| 384 | strcpy(dest, srcPath); |
| 385 | |
| 386 | // break the path into directories |
| 387 | char **directories; |
| 388 | int dirs; |
| 389 | int path_length; |
| 390 | |
| 391 | // make sure the path ends with a \ for sanity |
| 392 | path_length = strlen(dest); |
| 393 | |
| 394 | if (dest[path_length - 1] != '\\') { |
| 395 | dest[path_length] = '\\'; |
| 396 | dest[path_length + 1] = '\0'; |
| 397 | path_length++; |
| 398 | } |
| 399 | |
| 400 | // now divide the full path into seperate NULL terminated strings,counting the number |
| 401 | // of directories in the process |
| 402 | dirs = 0; |
| 403 | char *strptr = dest; |
| 404 | while (*strptr != '\0') { |
| 405 | if (*strptr == '\\') { |
| 406 | *strptr = '\0'; |
| 407 | dirs++; |
| 408 | } |
| 409 | strptr++; |
| 410 | } |
| 411 | |
| 412 | // check to make sure we have a directory, if we don't then return the original path given |
| 413 | if (dirs == 0) { |
| 414 | strcpy(dest, srcPath); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | // allocate the memory needed for the seperate strings of each directory |
| 419 | directories = (char **)mem_malloc(sizeof(char *) * dirs); |
| 420 | if (!directories) { |
| 421 | strcpy(dest, srcPath); |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | // now get all the directories, and place into the individual strings |
| 426 | strptr = dest; |
| 427 | int count = 0; |
| 428 | while (count < dirs) { |
| 429 | directories[count] = mem_strdup(strptr); |
| 430 | strptr += strlen(strptr) + 1; |
| 431 | count++; |
| 432 | } |
| 433 | |
| 434 | // now the fun part, figure out the correct order of the directories |
| 435 | int *dir_order; |
| 436 | |
| 437 | dir_order = (int *)mem_malloc(sizeof(int) * dirs); |
| 438 | if (!dir_order) { |
| 439 | strcpy(dest, srcPath); |
| 440 | return; |
no outgoing calls
no test coverage detected