mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Rename strNewN() to strNewZN().
Make the function name consistent with other functions that accept zero-terminated strings, e.g. strNewZ() and strCatZN().
This commit is contained in:
parent
b7e17d80ea
commit
ed68792e76
@ -136,7 +136,7 @@ archiveAsyncStatus(ArchiveMode archiveMode, const String *walSegment, bool throw
|
||||
THROW_FMT(FormatError, "%s message must be > 0", strZ(statusFile));
|
||||
|
||||
// Get contents
|
||||
code = varIntForce(VARSTR(strNewN(strZ(content), (size_t)(linefeedPtr - strZ(content)))));
|
||||
code = varIntForce(VARSTR(strNewZN(strZ(content), (size_t)(linefeedPtr - strZ(content)))));
|
||||
message = strTrim(strNewZ(linefeedPtr + 1));
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ cmdStop(void)
|
||||
char contents[LOCK_BUFFER_SIZE];
|
||||
ssize_t actualBytes = read(fd, contents, sizeof(contents));
|
||||
String *processId = actualBytes > 0 ?
|
||||
strTrim(strLstGet(strLstNewSplitZ(strNewN(contents, (size_t)actualBytes), LF_Z), 0)) : NULL;
|
||||
strTrim(strLstGet(strLstNewSplitZ(strNewZN(contents, (size_t)actualBytes), LF_Z), 0)) : NULL;
|
||||
|
||||
// If the process id is defined then assume this is a valid lock file
|
||||
if (processId != NULL && strSize(processId) > 0)
|
||||
|
@ -67,7 +67,7 @@ helpRenderSplitSize(const String *string, const char *delimiter, size_t size)
|
||||
if (stringMatchLast != NULL)
|
||||
stringMatch = stringMatchLast - strlen(delimiter);
|
||||
|
||||
strLstAdd(this, strNewN(stringBase, (size_t)(stringMatch - stringBase)));
|
||||
strLstAdd(this, strNewZN(stringBase, (size_t)(stringMatch - stringBase)));
|
||||
stringBase = stringMatch + strlen(delimiter);
|
||||
stringMatchLast = NULL;
|
||||
}
|
||||
@ -79,7 +79,7 @@ helpRenderSplitSize(const String *string, const char *delimiter, size_t size)
|
||||
{
|
||||
if (stringMatchLast != NULL && strlen(stringBase) - strlen(delimiter) >= size)
|
||||
{
|
||||
strLstAdd(this, strNewN(stringBase, (size_t)((stringMatchLast - strlen(delimiter)) - stringBase)));
|
||||
strLstAdd(this, strNewZN(stringBase, (size_t)((stringMatchLast - strlen(delimiter)) - stringBase)));
|
||||
stringBase = stringMatchLast;
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ iniParse(Ini *this, const String *content)
|
||||
THROW_FMT(FormatError, "ini section should end with ] at line %u: %s", lineIdx + 1, linePtr);
|
||||
|
||||
// Assign section
|
||||
section = strNewN(linePtr + 1, strSize(line) - 2);
|
||||
section = strNewZN(linePtr + 1, strSize(line) - 2);
|
||||
}
|
||||
// Else it should be a key/value
|
||||
else
|
||||
@ -272,7 +272,7 @@ iniParse(Ini *this, const String *content)
|
||||
THROW_FMT(FormatError, "missing '=' in key/value at line %u: %s", lineIdx + 1, linePtr);
|
||||
|
||||
// Extract the key
|
||||
String *key = strTrim(strNewN(linePtr, (size_t)(lineEqual - linePtr)));
|
||||
String *key = strTrim(strNewZN(linePtr, (size_t)(lineEqual - linePtr)));
|
||||
|
||||
if (strSize(key) == 0)
|
||||
THROW_FMT(FormatError, "key is zero-length at line %u: %s", lineIdx++, linePtr);
|
||||
@ -363,7 +363,7 @@ iniLoad(
|
||||
// Assign section
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
{
|
||||
section = strNewN(linePtr + 1, strSize(line) - 2);
|
||||
section = strNewZN(linePtr + 1, strSize(line) - 2);
|
||||
}
|
||||
MEM_CONTEXT_PRIOR_END();
|
||||
}
|
||||
@ -394,7 +394,7 @@ iniLoad(
|
||||
retry = false;
|
||||
|
||||
// Get key/value
|
||||
key = strNewN(linePtr, (size_t)(lineEqual - linePtr));
|
||||
key = strNewZN(linePtr, (size_t)(lineEqual - linePtr));
|
||||
value = strNewZ(lineEqual + 1);
|
||||
|
||||
// Check that the value is valid JSON
|
||||
|
@ -315,7 +315,7 @@ ioReadLineParam(IoRead *this, bool allowEof)
|
||||
size_t size = (size_t)(linefeed - outputPtr);
|
||||
|
||||
// Create the string
|
||||
result = strNewN(outputPtr, size);
|
||||
result = strNewZN(outputPtr, size);
|
||||
this->outputPos += size + 1;
|
||||
}
|
||||
}
|
||||
@ -342,7 +342,7 @@ ioReadLineParam(IoRead *this, bool allowEof)
|
||||
if (ioReadEof(this))
|
||||
{
|
||||
if (allowEof)
|
||||
result = strNewN((char *)bufPtr(this->output), bufUsed(this->output));
|
||||
result = strNewZN((char *)bufPtr(this->output), bufUsed(this->output));
|
||||
else
|
||||
THROW(FileReadError, "unexpected eof while reading line");
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ asn1ToStr(ASN1_STRING *nameAsn1)
|
||||
THROW(CryptoError, "TLS certificate name entry is missing");
|
||||
|
||||
FUNCTION_TEST_RETURN( // {vm_covered}
|
||||
strNewN(
|
||||
strNewZN(
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
(const char *)ASN1_STRING_data(nameAsn1),
|
||||
#else
|
||||
|
@ -108,7 +108,7 @@ lockAcquireFile(const String *lockFile, const String *execId, TimeMSec lockTimeo
|
||||
THROW_ON_SYS_ERROR_FMT(actualBytes == -1, FileReadError, "unable to read '%s", strZ(lockFile));
|
||||
|
||||
// Parse the file and see if the exec id matches
|
||||
const StringList *parse = strLstNewSplitZ(strNewN(buffer, (size_t)actualBytes), LF_Z);
|
||||
const StringList *parse = strLstNewSplitZ(strNewZN(buffer, (size_t)actualBytes), LF_Z);
|
||||
|
||||
if (strLstSize(parse) == 3 && strEq(strLstGet(parse, 1), execId))
|
||||
result = LOCK_ON_EXEC_ID;
|
||||
|
@ -164,7 +164,7 @@ regExpMatchStr(RegExp *this)
|
||||
|
||||
ASSERT(this != NULL);
|
||||
|
||||
FUNCTION_TEST_RETURN(this->matchPtr == NULL ? NULL : strNewN(regExpMatchPtr(this), regExpMatchSize(this)));
|
||||
FUNCTION_TEST_RETURN(this->matchPtr == NULL ? NULL : strNewZN(regExpMatchPtr(this), regExpMatchSize(this)));
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
|
@ -111,7 +111,7 @@ jsonToNumberInternal(const char *json, unsigned int *jsonPos)
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Extract the numeric as a string
|
||||
String *resultStr = strNewN(json + beginPos, *jsonPos - beginPos);
|
||||
String *resultStr = strNewZN(json + beginPos, *jsonPos - beginPos);
|
||||
|
||||
// Convert the string to a integer variant
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
@ -300,7 +300,7 @@ jsonToStrInternal(const char *json, unsigned int *jsonPos)
|
||||
|
||||
// Decode char
|
||||
(*jsonPos) += 2;
|
||||
strCatChr(result, (char)cvtZToUIntBase(strZ(strNewN(json + *jsonPos, 2)), 16));
|
||||
strCatChr(result, (char)cvtZToUIntBase(strZ(strNewZN(json + *jsonPos, 2)), 16));
|
||||
(*jsonPos) += 1;
|
||||
|
||||
break;
|
||||
|
@ -225,7 +225,7 @@ strNewFmt(const char *format, ...)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
String *
|
||||
strNewN(const char *string, size_t size)
|
||||
strNewZN(const char *string, size_t size)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM_P(CHARDATA, string);
|
||||
@ -739,7 +739,7 @@ strPath(const String *this)
|
||||
end--;
|
||||
|
||||
FUNCTION_TEST_RETURN(
|
||||
strNewN(
|
||||
strNewZN(
|
||||
this->pub.buffer,
|
||||
end - this->pub.buffer <= 1 ? (size_t)(end - this->pub.buffer) : (size_t)(end - this->pub.buffer - 1)));
|
||||
}
|
||||
@ -918,7 +918,7 @@ strSubN(const String *this, size_t start, size_t size)
|
||||
ASSERT(start <= strSize(this));
|
||||
ASSERT(start + size <= strSize(this));
|
||||
|
||||
FUNCTION_TEST_RETURN(strNewN(strZ(this) + start, size));
|
||||
FUNCTION_TEST_RETURN(strNewZN(strZ(this) + start, size));
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
|
@ -8,7 +8,7 @@ old context and then back. Below is a simplified example:
|
||||
String *result = NULL; <--- is created in the current memory context (referred to as "old context" below)
|
||||
MEM_CONTEXT_TEMP_BEGIN() <--- begins a new temporary context
|
||||
{
|
||||
String *resultStr = strNewN("myNewStr"); <--- creates a string in the temporary memory context
|
||||
String *resultStr = strNewZN("myNewStr"); <--- creates a string in the temporary memory context
|
||||
|
||||
MEM_CONTEXT_PRIOR_BEGIN() <--- switch to the old context so the duplication of the string is in that context
|
||||
{
|
||||
@ -55,6 +55,10 @@ String *strNew(void);
|
||||
// Create a new fixed length string from a zero-terminated string
|
||||
String *strNewZ(const char *const string);
|
||||
|
||||
// Create a new fixed length string from a zero-terminated string with a specific length. The string may or may not be
|
||||
// zero-terminated but we'll use that nomenclature since we're not concerned about the end of the string.
|
||||
String *strNewZN(const char *string, size_t size);
|
||||
|
||||
// Create a new fixed length string from a buffer. If the buffer has a NULL character this may not work as expected. All the data
|
||||
// will be copied but only the data before the NULL character will be used as a string.
|
||||
String *strNewBuf(const Buffer *buffer);
|
||||
@ -68,10 +72,6 @@ String *strNewEncode(EncodeType type, const Buffer *buffer);
|
||||
// Create a new fixed length string from a format string with parameters (i.e. sprintf)
|
||||
String *strNewFmt(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
// Create a new fixed length string from a zero-terminated string with a specific length. The string may or may not be
|
||||
// zero-terminated but we'll use that nomenclature since we're not concerned about the end of the string.
|
||||
String *strNewN(const char *string, size_t size);
|
||||
|
||||
// Create a new fixed length string from a string
|
||||
String *strDup(const String *this);
|
||||
|
||||
|
@ -61,7 +61,7 @@ strLstNewSplitZ(const String *string, const char *delimiter)
|
||||
// If a match was found then add the string
|
||||
if (stringMatch != NULL)
|
||||
{
|
||||
strLstAddInternal(this, strNewN(stringBase, (size_t)(stringMatch - stringBase)));
|
||||
strLstAddInternal(this, strNewZN(stringBase, (size_t)(stringMatch - stringBase)));
|
||||
stringBase = stringMatch + strlen(delimiter);
|
||||
}
|
||||
// Else make whatever is left the last string
|
||||
|
@ -8,7 +8,7 @@ old context and then back. Below is a simplified example:
|
||||
Variant *result = NULL; <--- is created in the current memory context (referred to as "old context" below)
|
||||
MEM_CONTEXT_TEMP_BEGIN() <--- begins a new temporary context
|
||||
{
|
||||
String *resultStr = strNewN("myNewStr"); <--- creates a string in the temporary memory context
|
||||
String *resultStr = strNewZN("myNewStr"); <--- creates a string in the temporary memory context
|
||||
|
||||
MEM_CONTEXT_PRIOR_BEGIN() <--- switch to old context so creation of the variant from the string is in old context
|
||||
{
|
||||
|
@ -1214,7 +1214,7 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
|
||||
|
||||
if (equalPtr)
|
||||
{
|
||||
optionName = strNewN(arg, (size_t)(equalPtr - arg));
|
||||
optionName = strNewZN(arg, (size_t)(equalPtr - arg));
|
||||
optionArg = strNewZ(equalPtr + 1);
|
||||
}
|
||||
else
|
||||
@ -1435,7 +1435,7 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
|
||||
|
||||
// Get key and value
|
||||
const String *key = strReplaceChr(
|
||||
strLower(strNewN(keyValue + PGBACKREST_ENV_SIZE, (size_t)(equalPtr - (keyValue + PGBACKREST_ENV_SIZE)))),
|
||||
strLower(strNewZN(keyValue + PGBACKREST_ENV_SIZE, (size_t)(equalPtr - (keyValue + PGBACKREST_ENV_SIZE)))),
|
||||
'_', '-');
|
||||
const String *value = STR(equalPtr + 1);
|
||||
|
||||
@ -1944,7 +1944,7 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
|
||||
cfgParseOptionKeyIdxName(optionId, optionKeyIdx));
|
||||
}
|
||||
|
||||
kvPut(keyValue, VARSTR(strNewN(pair, (size_t)(equal - pair))), VARSTRZ(equal + 1));
|
||||
kvPut(keyValue, VARSTR(strNewZN(pair, (size_t)(equal - pair))), VARSTRZ(equal + 1));
|
||||
}
|
||||
|
||||
configOptionValue->value = value;
|
||||
|
@ -104,7 +104,7 @@ storagePosixInfo(THIS_VOID, const String *file, StorageInfoLevel level, StorageI
|
||||
(linkDestinationSize = readlink(strZ(file), linkDestination, sizeof(linkDestination) - 1)) == -1,
|
||||
FileReadError, "unable to get destination for link '%s'", strZ(file));
|
||||
|
||||
result.linkDestination = strNewN(linkDestination, (size_t)linkDestinationSize);
|
||||
result.linkDestination = strNewZN(linkDestination, (size_t)linkDestinationSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -727,7 +727,7 @@ storagePath(const Storage *this, const String *pathExp, StoragePathParam param)
|
||||
THROW_FMT(AssertError, "end > not found in path expression '%s'", strZ(pathExp));
|
||||
|
||||
// Create a string from the expression
|
||||
String *expression = strNewN(strZ(pathExp), (size_t)(end - strZ(pathExp) + 1));
|
||||
String *expression = strNewZN(strZ(pathExp), (size_t)(end - strZ(pathExp) + 1));
|
||||
|
||||
// Create a string from the path if there is anything left after the expression
|
||||
String *path = NULL;
|
||||
|
@ -197,7 +197,7 @@ testRun(void)
|
||||
|
||||
TEST_ERROR(
|
||||
tlsClientHostVerifyName(
|
||||
STRDEF("host"), strNewN("ab\0cd", 5)), CryptoError, "TLS certificate name contains embedded null");
|
||||
STRDEF("host"), strNewZN("ab\0cd", 5)), CryptoError, "TLS certificate name contains embedded null");
|
||||
|
||||
TEST_ERROR(tlsClientHostVerify(STRDEF("host"), NULL), CryptoError, "No certificate presented by the TLS server");
|
||||
|
||||
|
@ -178,7 +178,7 @@ testRun(void)
|
||||
TEST_RESULT_VOID(
|
||||
logInternal(logLevelWarn, LOG_LEVEL_MIN, LOG_LEVEL_MAX, 0, "file", "function", 0, "TEST"), "log timestamp");
|
||||
|
||||
String *logTime = strNewN(logBuffer, 23);
|
||||
String *logTime = strNewZN(logBuffer, 23);
|
||||
TEST_RESULT_BOOL(
|
||||
regExpMatchOne(
|
||||
STRDEF("^20[0-9]{2}\\-[0-1][0-9]\\-[0-3][0-9] [0-2][0-9]\\:[0-5][0-9]\\:[0-5][0-9]\\.[0-9]{3}$"), logTime),
|
||||
|
@ -52,7 +52,7 @@ testRun(void)
|
||||
TEST_RESULT_VOID(strFree(string), "free string");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_STR_Z(strNewN("testmorestring", 4), "test", "new string with size limit");
|
||||
TEST_RESULT_STR_Z(strNewZN("testmorestring", 4), "test", "new string with size limit");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
Buffer *buffer = bufNew(8);
|
||||
|
Loading…
Reference in New Issue
Block a user