1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-06-04 23:07:27 +02:00

Add strBaseZ().

Since the base name is at the end of the filename it is possible to return the char pointer without making a copy, which is preferred in some cases.
This commit is contained in:
David Steele 2020-07-25 13:37:39 -04:00
parent 8e140ad7e0
commit aa37a21084
3 changed files with 17 additions and 3 deletions

View File

@ -203,12 +203,24 @@ strBase(const String *this)
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(strNew(strBaseZ(this)));
}
const char *
strBaseZ(const String *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
const char *end = this->buffer + this->size;
while (end > this->buffer && *(end - 1) != '/')
end--;
FUNCTION_TEST_RETURN(strNew(end));
FUNCTION_TEST_RETURN(end);
}
/**********************************************************************************************************************************/

View File

@ -77,8 +77,10 @@ String *strDup(const String *this);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Return the file part of a string (i.e. everything after the last / or the entire string if there is no /)
// Return the file part of a string (i.e. everything after the last / or the entire string if there is no /). strBaseZ() does not
// make a copy of the string so it may be more appropriate for large loops where saving memory is important.
String *strBase(const String *this);
const char *strBaseZ(const String *this);
// Does the string begin with the specified string?
bool strBeginsWith(const String *this, const String *beginsWith);

View File

@ -316,7 +316,7 @@ cfgFileLoad( // NOTE: Pas
if (optionList[cfgOptConfigPath].found)
{
optConfigDefault =
strNewFmt("%s/%s", strPtr(strLstGet(optionList[cfgOptConfigPath].valueList, 0)), strPtr(strBase(optConfigDefault)));
strNewFmt("%s/%s", strPtr(strLstGet(optionList[cfgOptConfigPath].valueList, 0)), strBaseZ(optConfigDefault));
optConfigIncludePathDefault =
strNewFmt("%s/%s", strPtr(strLstGet(optionList[cfgOptConfigPath].valueList, 0)), PGBACKREST_CONFIG_INCLUDE_PATH);
}