MCPcopy Create free account
hub / github.com/F-Stack/f-stack / convertPathnameToDirName

Function convertPathnameToDirName

freebsd/contrib/zstd/programs/util.c:714–742  ·  view source on GitHub ↗

this function requires a mutable input string */

Source from the content-addressed store, hash-verified

712
713/* this function requires a mutable input string */
714static 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 */
745static const char* trimLeadingRootChar(const char *pathname)

Callers 2

makeMirroredDestDirsFunction · 0.85

Calls 1

strrchrFunction · 0.85

Tested by

no test coverage detected