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

Function mallocAndJoin2Dir

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

Source from the content-addressed store, hash-verified

779}
780
781static char* mallocAndJoin2Dir(const char *dir1, const char *dir2)
782{
783 const size_t dir1Size = strlen(dir1);
784 const size_t dir2Size = strlen(dir2);
785 char *outDirBuffer, *buffer, trailingChar;
786
787 assert(dir1 != NULL && dir2 != NULL);
788 outDirBuffer = (char *) malloc(dir1Size + dir2Size + 2);
789 CONTROL(outDirBuffer != NULL);
790
791 memcpy(outDirBuffer, dir1, dir1Size);
792 outDirBuffer[dir1Size] = '\0';
793
794 if (dir2[0] == '.')
795 return outDirBuffer;
796
797 buffer = outDirBuffer + dir1Size;
798 trailingChar = *(buffer - 1);
799 if (trailingChar != PATH_SEP) {
800 *buffer = PATH_SEP;
801 buffer++;
802 }
803 memcpy(buffer, dir2, dir2Size);
804 buffer[dir2Size] = '\0';
805
806 return outDirBuffer;
807}
808
809/* this function will return NULL if input srcFileName is not valid name for mirrored output path */
810char* UTIL_createMirroredDestDirName(const char* srcFileName, const char* outDirRootName)

Callers 2

mirrorSrcDirFunction · 0.85

Calls 2

mallocFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected