Mercurial > codedump
comparison decodeurl.c @ 72:23d0073daa79
Create decodeurl.c
committer: GitHub <noreply@github.com>
| author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
|---|---|
| date | Wed, 22 Jun 2022 19:37:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 71:a9776ed0538b | 72:23d0073daa79 |
|---|---|
| 1 // C port of decodeurl.cpp | |
| 2 #include <curl/curl.h> | |
| 3 #include <string.h> | |
| 4 #include <stdio.h> | |
| 5 #include <stdlib.h> | |
| 6 | |
| 7 #define ENCODED_SIZE 8192 | |
| 8 | |
| 9 int main(int argc, char* argv[]) { | |
| 10 int c; | |
| 11 if (argc != 3) { | |
| 12 printf("usage: %s <input> <output>\n", argv[0]); | |
| 13 return 1; | |
| 14 } | |
| 15 char encoded[ENCODED_SIZE] = {'\0'}; | |
| 16 CURL* curl = curl_easy_init(); | |
| 17 char data[256]; | |
| 18 FILE* in = fopen(argv[1], "r"); // this is unsafe, but meh | |
| 19 FILE* out = fopen(argv[2], "w"); | |
| 20 if (in == NULL || out == NULL) { | |
| 21 printf("Failed to open file(s)!\n"); | |
| 22 return 1; | |
| 23 } | |
| 24 char* p = &encoded[strlen(encoded)]; | |
| 25 while ((c = fgetc(in)) != EOF) { | |
| 26 *p++ = c; | |
| 27 if (p == &encoded[ENCODED_SIZE-1]) break; | |
| 28 } | |
| 29 *p = '\0'; | |
| 30 rewind(in); // we probably don't need this!! | |
| 31 char* decoded = curl_easy_unescape(curl, encoded, 0, NULL); | |
| 32 fprintf(out, "%s", decoded); | |
| 33 // fwrite(decoded, sizeof(char), sizeof(decoded), in); | |
| 34 curl_easy_cleanup(curl); | |
| 35 fclose(in); | |
| 36 fclose(out); | |
| 37 return 0; | |
| 38 } |
