mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Add pg_strnlen() a portable implementation of strlen.
As the OS version is likely going to be more optimized, fall back to it if available, as detected by configure.
This commit is contained in:
@@ -41,3 +41,23 @@ pg_str_endswith(const char *str, const char *end)
|
||||
str += slen - elen;
|
||||
return strcmp(str, end) == 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Portable version of posix' strnlen.
|
||||
*
|
||||
* Returns the number of characters before a null-byte in the string pointed
|
||||
* to by str, unless there's no null-byte before maxlen. In the latter case
|
||||
* maxlen is returned.
|
||||
*/
|
||||
#ifndef HAVE_STRNLEN
|
||||
size_t
|
||||
pg_strnlen(const char *str, size_t maxlen)
|
||||
{
|
||||
const char *p = str;
|
||||
|
||||
while (maxlen-- > 0 && *p)
|
||||
p++;
|
||||
return p - str;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user