PostgreSQL Source Code  git master
string.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * string.c
4  * string handling helpers
5  *
6  *
7  * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  *
11  * IDENTIFICATION
12  * src/common/string.c
13  *
14  *-------------------------------------------------------------------------
15  */
16 
17 
18 #ifndef FRONTEND
19 #include "postgres.h"
20 #else
21 #include "postgres_fe.h"
22 #endif
23 
24 #include "common/string.h"
25 
26 
27 /*
28  * Returns whether the string `str' has the postfix `end'.
29  */
30 bool
31 pg_str_endswith(const char *str, const char *end)
32 {
33  size_t slen = strlen(str);
34  size_t elen = strlen(end);
35 
36  /* can't be a postfix if longer */
37  if (elen > slen)
38  return false;
39 
40  /* compare the end of the strings */
41  str += slen - elen;
42  return strcmp(str, end) == 0;
43 }
44 
45 
46 /*
47  * strtoint --- just like strtol, but returns int not long
48  */
49 int
50 strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
51 {
52  long val;
53 
54  val = strtol(str, endptr, base);
55  if (val != (int) val)
56  errno = ERANGE;
57  return (int) val;
58 }
bool pg_str_endswith(const char *str, const char *end)
Definition: string.c:31
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
Definition: string.c:50
long val
Definition: informix.c:689