Escape strings that are to be used as part of a PostgreSQL connection string.
If no characters require escaping, simply return the input pointer. Otherwise return a new allocated string.
Definition at line 109 of file shpcommon.c.
110{
111
112
113
114
115
116
117
118
119
120 char *result;
121 char *ptr, *optr;
122 int toescape = 0;
123 size_t size;
124
126
127
128 while (*ptr)
129 {
130 if (*ptr == '\'' || *ptr == '\\')
131 toescape++;
132
133 ptr++;
134 }
135
136
137 if (toescape == 0)
139
140 size = ptr -
str + toescape + 1;
141 result = calloc(1, size);
142 optr = result;
144
145 while (*ptr)
146 {
147 if (*ptr == '\'' || *ptr == '\\')
148 *optr++ = '\\';
149
150 *optr++ = *ptr++;
151 }
152
153 *optr = '\0';
154
155 return result;
156}
References str.