PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ascii.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ascii_safe_strlcpy (char *dest, const char *src, size_t destsiz)
 

Function Documentation

void ascii_safe_strlcpy ( char *  dest,
const char *  src,
size_t  destsiz 
)

Definition at line 173 of file ascii.c.

Referenced by BackgroundWorkerStateChange(), and pgstat_get_crashed_backend_activity().

174 {
175  if (destsiz == 0) /* corner case: no room for trailing nul */
176  return;
177 
178  while (--destsiz > 0)
179  {
180  /* use unsigned char here to avoid compiler warning */
181  unsigned char ch = *src++;
182 
183  if (ch == '\0')
184  break;
185  /* Keep printable ASCII characters */
186  if (32 <= ch && ch <= 127)
187  *dest = ch;
188  /* White-space is also OK */
189  else if (ch == '\n' || ch == '\r' || ch == '\t')
190  *dest = ch;
191  /* Everything else is replaced with '?' */
192  else
193  *dest = '?';
194  dest++;
195  }
196 
197  *dest = '\0';
198 }