MCPcopy Create free account
hub / github.com/NetHack/NetHack / swr_add_uricoded

Function swr_add_uricoded

src/report.c:236–281  ·  view source on GitHub ↗

On overflow, truncate to markp (but only if markp != NULL). */

Source from the content-addressed store, hash-verified

234
235/* On overflow, truncate to markp (but only if markp != NULL). */
236boolean
237swr_add_uricoded(
238 const char *in,
239 char **out,
240 int *remaining,
241 char *markp)
242{
243 while (*in) {
244 if (isalnum(*in) || strchr("_-.~", *in)) {
245 **out = *in;
246 (*out)++;
247 (*remaining)--;
248 } else if (*in == ' ') {
249 **out = '+';
250 (*out)++;
251 (*remaining)--;
252 } else {
253 if (*remaining <= 3) {
254 if (markp)
255 *out = markp, *remaining = 0;
256 **out = '\0';
257 return TRUE;
258 } else {
259 char chr[40]; /* [4] should suffice */
260 int x;
261
262 Sprintf(chr, "%%%02X", *in);
263 x = (int) strlen(chr);
264 if (x <= *remaining) {
265 Strcpy(*out, chr);
266 *out += x;
267 *remaining -= x;
268 }
269 }
270 }
271 in++;
272 if (!*remaining) {
273 if (markp)
274 *out = markp, *remaining = 0;
275 **out = '\0';
276 return TRUE;
277 }
278 **out = '\0';
279 }
280 return FALSE; /* normal return */
281}
282
283static char url[MAX_URL]; // XXX too bad this isn't allocated as needed
284static int urem = MAX_URL; // adjusted for gc.crash_urlmax below

Callers 1

win32_cr_gettraceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected