From afd4daf9217ba7e8dcc9ca31ceb32f93ded7f12c Mon Sep 17 00:00:00 2001 From: Nakidai Date: Thu, 24 Oct 2024 16:24:33 +0300 Subject: Add code --- througha.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 througha.c (limited to 'througha.c') diff --git a/througha.c b/througha.c new file mode 100644 index 0000000..f12793c --- /dev/null +++ b/througha.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +#include + + +void usage(const char *name, const char *message) +{ + fprintf( + stderr, + "usage: %1$s proxy command [arg [arg [...]]]\n" + " the proxy parameter may be set to '-' so no proxy will be used\n" + "%1$s: %2$s\n", + name, message + ); + exit(1); +} + +int main(int argc, char **argv, char **env) +{ + if (argc < 2) + usage(argv[0], "no proxy was specified"); + else if (argc < 3) + usage(argv[0], "no command was specified"); + + for (char **envp = env; *envp != NULL; ++envp) + { + *strchr(*envp, '=') = '\0'; + + for (char *cp = *envp; *cp != '\0'; ++cp) + *cp = tolower(*cp); + + if (strstr(*envp, "_proxy")) + unsetenv(*envp); + } + + if (strcmp(argv[1], "-")) + setenv("all_proxy", argv[1], 1); + + return execvp(argv[2], &argv[2]); +} -- cgit 1.4.1