PostgreSQL Source Code  git master
string.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool pg_str_endswith (const char *str, const char *end)
 
int strtoint (const char *pg_restrict str, char **pg_restrict endptr, int base)
 
void pg_clean_ascii (char *str)
 
int pg_strip_crlf (char *str)
 

Function Documentation

◆ pg_clean_ascii()

void pg_clean_ascii ( char *  str)

Definition at line 82 of file string.c.

Referenced by check_application_name(), check_cluster_name(), and ProcessStartupPacket().

83 {
84  /* Only allow clean ASCII chars in the string */
85  char *p;
86 
87  for (p = str; *p != '\0'; p++)
88  {
89  if (*p < 32 || *p > 126)
90  *p = '?';
91  }
92 }

◆ pg_str_endswith()

bool pg_str_endswith ( const char *  str,
const char *  end 
)

Definition at line 31 of file string.c.

Referenced by process_source_file(), ReceiveAndUnpackTarFile(), and StartupReplicationSlots().

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 }

◆ pg_strip_crlf()

int pg_strip_crlf ( char *  str)

Definition at line 105 of file string.c.

Referenced by adjust_data_dir(), CheckDataVersion(), get_prompt(), get_sock_dir(), passwordFromFile(), and run_ssl_passphrase_command().

106 {
107  int len = strlen(str);
108 
109  while (len > 0 && (str[len - 1] == '\n' ||
110  str[len - 1] == '\r'))
111  str[--len] = '\0';
112 
113  return len;
114 }

◆ strtoint()

int strtoint ( const char *pg_restrict  str,
char **pg_restrict  endptr,
int  base 
)

Definition at line 50 of file string.c.

References val.

Referenced by DecodeDateTime(), DecodeInterval(), DecodeNumber(), DecodeNumberField(), DecodeTime(), DecodeTimeOnly(), DecodeTimezone(), and nodeTokenType().

51 {
52  long val;
53 
54  val = strtol(str, endptr, base);
55  if (val != (int) val)
56  errno = ERANGE;
57  return (int) val;
58 }
long val
Definition: informix.c:684