safeFile*: accept when suffix is already provided

This commit is contained in:
Philippe Teuwen 2019-04-28 20:42:57 +02:00
commit 1dbcb712c3
13 changed files with 77 additions and 74 deletions

View file

@ -938,16 +938,3 @@ char *strmcopy(const char *buf) {
}
return str;
}
char *filenamemcopy(const char *preferredName, const char *suffix) {
if (preferredName == NULL) return NULL;
if (suffix == NULL) return NULL;
char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t));
if (fileName == NULL)
return NULL;
strcpy(fileName, preferredName);
if (str_endswith(fileName, suffix))
return fileName;
strcat(fileName, suffix);
return fileName;
}