mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-28 02:31:49 +02:00
8a241792f9
As the OS version is likely going to be more optimized, fall back to it if available, as detected by configure.
64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* string.c
|
|
* string handling helpers
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
*
|
|
* IDENTIFICATION
|
|
* src/common/string.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
#ifndef FRONTEND
|
|
#include "postgres.h"
|
|
#else
|
|
#include "postgres_fe.h"
|
|
#endif
|
|
|
|
#include "common/string.h"
|
|
|
|
|
|
/*
|
|
* Returns whether the string `str' has the postfix `end'.
|
|
*/
|
|
bool
|
|
pg_str_endswith(const char *str, const char *end)
|
|
{
|
|
size_t slen = strlen(str);
|
|
size_t elen = strlen(end);
|
|
|
|
/* can't be a postfix if longer */
|
|
if (elen > slen)
|
|
return false;
|
|
|
|
/* compare the end of the strings */
|
|
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
|