From aa4a1a46187d9c3fd8a115dbc54ad2a58386c8a5 Mon Sep 17 00:00:00 2001 From: Ronsor Date: Tue, 20 Dec 2022 13:10:44 -0700 Subject: [PATCH] Move `curl` from the `examples/` folder to `tool/net/`, and make it available in `cocmd`. You can now use include it conveniently for use with popen()/system() with STATIC_YOINK("_curl") --- libc/runtime/cocmd.c | 2 ++ tool/net/curl.c | 5 +++++ tool/net/curl.h | 10 ++++++++++ examples/curl.c => tool/net/curl.inc | 6 ++---- tool/net/net.mk | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tool/net/curl.c create mode 100644 tool/net/curl.h rename examples/curl.c => tool/net/curl.inc (98%) diff --git a/libc/runtime/cocmd.c b/libc/runtime/cocmd.c index 3f935d9f8..374e8f2bb 100644 --- a/libc/runtime/cocmd.c +++ b/libc/runtime/cocmd.c @@ -38,6 +38,7 @@ #include "third_party/awk/cmd.h" #include "third_party/sed/cmd.h" #include "third_party/tr/cmd.h" +#include "tool/net/curl.h" /** * @fileoverview Cosmopolitan Command Interpreter @@ -417,6 +418,7 @@ static int TryBuiltin(void) { if (_weaken(_tr) && !strcmp(args[0], "tr")) return Fake(_weaken(_tr)); if (_weaken(_sed) && !strcmp(args[0], "sed")) return Fake(_weaken(_sed)); if (_weaken(_awk) && !strcmp(args[0], "awk")) return Fake(_weaken(_awk)); + if (_weaken(_curl) && !strcmp(args[0], "curl")) return Fake(_weaken(_curl)); return -1; } diff --git a/tool/net/curl.c b/tool/net/curl.c new file mode 100644 index 000000000..903c06c0b --- /dev/null +++ b/tool/net/curl.c @@ -0,0 +1,5 @@ +#include "curl.inc" + +int main(int argc, char *argv[]) { + return _curl(argc, argv); +} diff --git a/tool/net/curl.h b/tool/net/curl.h new file mode 100644 index 000000000..410d818d8 --- /dev/null +++ b/tool/net/curl.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_TOOL_NET_CURL_CMD_H_ +#define COSMOPOLITAN_TOOL_NET_CURL_CMD_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int _curl(int, char *[]); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_TOOL_NET_CURL_CMD_H_ */ diff --git a/examples/curl.c b/tool/net/curl.inc similarity index 98% rename from examples/curl.c rename to tool/net/curl.inc index 88d1c41e4..995a0e0c8 100644 --- a/examples/curl.c +++ b/tool/net/curl.inc @@ -52,12 +52,10 @@ #include "third_party/mbedtls/pk.h" #include "third_party/mbedtls/ssl.h" #include "third_party/mbedtls/ssl_ticket.h" +#include "tool/net/curl.h" /** * @fileoverview Downloads HTTP URL to stdout. - * - * make -j8 o//examples/curl.com - * o//examples/curl.com http://justine.lol/ape.html */ #define HasHeader(H) (!!msg.headers[H].a) @@ -121,7 +119,7 @@ static wontreturn void PrintUsage(FILE *f, int rc) { exit(rc); } -int main(int argc, char *argv[]) { +int _curl(int argc, char *argv[]) { if (!NoDebug()) ShowCrashReports(); /* diff --git a/tool/net/net.mk b/tool/net/net.mk index b29a02bec..d7e624de0 100644 --- a/tool/net/net.mk +++ b/tool/net/net.mk @@ -15,6 +15,7 @@ TOOL_NET_BINS = \ $(TOOL_NET_COMS:%=%.dbg) TOOL_NET_COMS = \ + o/$(MODE)/tool/net/curl.com \ o/$(MODE)/tool/net/dig.com \ o/$(MODE)/tool/net/redbean.com \ o/$(MODE)/tool/net/redbean-demo.com \