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

Function FIO_determineDstName

freebsd/contrib/zstd/programs/fileio.c:2637–2717  ·  view source on GitHub ↗

FIO_determineDstName() : * create a destination filename from a srcFileName. * @return a pointer to it. * @return == NULL if there is an error */

Source from the content-addressed store, hash-verified

2635 * @return a pointer to it.
2636 * @return == NULL if there is an error */
2637static const char*
2638FIO_determineDstName(const char* srcFileName, const char* outDirName)
2639{
2640 static size_t dfnbCapacity = 0;
2641 static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */
2642 size_t dstFileNameEndPos;
2643 char* outDirFilename = NULL;
2644 const char* dstSuffix = "";
2645 size_t dstSuffixLen = 0;
2646
2647 size_t sfnSize = strlen(srcFileName);
2648
2649 size_t srcSuffixLen;
2650 const char* const srcSuffix = strrchr(srcFileName, '.');
2651 if (srcSuffix == NULL) {
2652 DISPLAYLEVEL(1,
2653 "zstd: %s: unknown suffix (%s expected). "
2654 "Can't derive the output file name. "
2655 "Specify it with -o dstFileName. Ignoring.\n",
2656 srcFileName, suffixListStr);
2657 return NULL;
2658 }
2659 srcSuffixLen = strlen(srcSuffix);
2660
2661 {
2662 const char** matchedSuffixPtr;
2663 for (matchedSuffixPtr = suffixList; *matchedSuffixPtr != NULL; matchedSuffixPtr++) {
2664 if (!strcmp(*matchedSuffixPtr, srcSuffix)) {
2665 break;
2666 }
2667 }
2668
2669 /* check suffix is authorized */
2670 if (sfnSize <= srcSuffixLen || *matchedSuffixPtr == NULL) {
2671 DISPLAYLEVEL(1,
2672 "zstd: %s: unknown suffix (%s expected). "
2673 "Can't derive the output file name. "
2674 "Specify it with -o dstFileName. Ignoring.\n",
2675 srcFileName, suffixListStr);
2676 return NULL;
2677 }
2678
2679 if ((*matchedSuffixPtr)[1] == 't') {
2680 dstSuffix = ".tar";
2681 dstSuffixLen = strlen(dstSuffix);
2682 }
2683 }
2684
2685 if (outDirName) {
2686 outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, 0);
2687 sfnSize = strlen(outDirFilename);
2688 assert(outDirFilename != NULL);
2689 }
2690
2691 if (dfnbCapacity+srcSuffixLen <= sfnSize+1+dstSuffixLen) {
2692 /* allocate enough space to write dstFilename into it */
2693 free(dstFileNameBuffer);
2694 dfnbCapacity = sfnSize + 20;

Callers 1

Calls 6

strrchrFunction · 0.85
strcmpFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected