1 /*-------------------------------------------------------------------------
4 * string quoting and escaping functions
6 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
13 *-------------------------------------------------------------------------
19 * Escape (by doubling) any single quotes or backslashes in given string
21 * Note: this is used to process postgresql.conf entries and to quote
22 * string literals in pg_basebackup for creating recovery.conf.
23 * Since postgresql.conf strings are defined to treat backslashes as escapes,
24 * we have to double backslashes here.
26 * Since this function is only used for parsing or creating configuration
27 * files, we do not care about encoding considerations.
29 * Returns a malloced() string that it's the responsibility of the caller
33 escape_single_quotes_ascii(const char *src)
35 int len = strlen(src),
38 char *result = malloc(len * 2 + 1);
43 for (i = 0, j = 0; i < len; i++)
45 if (SQL_STR_DOUBLE(src[i], true))