this function requires a mutable input string */
| 712 | |
| 713 | /* this function requires a mutable input string */ |
| 714 | static void convertPathnameToDirName(char *pathname) |
| 715 | { |
| 716 | size_t len = 0; |
| 717 | char* pos = NULL; |
| 718 | /* get dir name from pathname similar to 'dirname()' */ |
| 719 | assert(pathname != NULL); |
| 720 | |
| 721 | /* remove trailing '/' chars */ |
| 722 | len = strlen(pathname); |
| 723 | assert(len > 0); |
| 724 | while (pathname[len] == PATH_SEP) { |
| 725 | pathname[len] = '\0'; |
| 726 | len--; |
| 727 | } |
| 728 | if (len == 0) return; |
| 729 | |
| 730 | /* if input is a single file, return '.' instead. i.e. |
| 731 | * "xyz/abc/file.txt" => "xyz/abc" |
| 732 | "./file.txt" => "." |
| 733 | "file.txt" => "." |
| 734 | */ |
| 735 | pos = strrchr(pathname, PATH_SEP); |
| 736 | if (pos == NULL) { |
| 737 | pathname[0] = '.'; |
| 738 | pathname[1] = '\0'; |
| 739 | } else { |
| 740 | *pos = '\0'; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /* pathname must be valid */ |
| 745 | static const char* trimLeadingRootChar(const char *pathname) |
no test coverage detected