Skip to content

Instantly share code, notes, and snippets.

@annidy
Last active March 7, 2017 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annidy/bec8c0a6040af88957d55e1f3d03e411 to your computer and use it in GitHub Desktop.
Save annidy/bec8c0a6040af88957d55e1f3d03e411 to your computer and use it in GitHub Desktop.
static char *url_escape(char *path, int len) {
char *org_path = strdup(path);
memset(path, 0, len);
char *enc = path;
for (char *s = org_path; *s && (enc - path < len - 3); s++) {
if (strchr("!*'();:@&=+$,/?%%#[]", *s) != NULL) {
sprintf(enc, "%%%02X", *s);
} else {
sprintf(enc, "%c", *s);
}
while (*++enc);
}
free(org_path);
return path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment