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 113 of file shpcommon.c.
114{
115
116
117
118
119
120
121
122
123
125 char *ptr, *optr;
126 int toescape = 0;
127 size_t size;
128
130
131
132 while (*ptr)
133 {
134 if (*ptr == '\'' || *ptr == '\\')
135 toescape++;
136
137 ptr++;
138 }
139
140
141 if (toescape == 0)
143
144 size = ptr -
str + toescape + 1;
148
149 while (*ptr)
150 {
151 if (*ptr == '\'' || *ptr == '\\')
152 *optr++ = '\\';
153
154 *optr++ = *ptr++;
155 }
156
157 *optr = '\0';
158
160}
char result[OUT_DOUBLE_BUFFER_SIZE]
References result, and str.