summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2024-03-10 02:35:08 +0100
committerJulian Hurst <ark@mansus.space>2024-03-10 02:35:08 +0100
commit89173069e85416539b1256ed1ae1c77e89550ae6 (patch)
treed2f42c63b91306ad1b4693737ab1e35514d746b9 /cmd
parent69712258bafda1258454e6336faabf527f207e3b (diff)
downloadhacurl-89173069e85416539b1256ed1ae1c77e89550ae6.tar.gz
Allow retrieving in memory response struct, and cleanup
Diffstat (limited to 'cmd')
-rw-r--r--cmd/main.ha25
1 files changed, 25 insertions, 0 deletions
diff --git a/cmd/main.ha b/cmd/main.ha
new file mode 100644
index 0000000..95d1cad
--- /dev/null
+++ b/cmd/main.ha
@@ -0,0 +1,25 @@
+use fmt;
+use os;
+use internal::curl;
+use memio;
+use io;
+
+export fn main() void = {
+ if (len(os::args) != 2) {
+ fmt::fatalf("USAGE: {} <url>", os::args[0]);
+ };
+ let resp = curl::newresponse();
+ defer curl::closeresponse(resp)!;
+ match (curl::get(os::args[1], &resp)) {
+ case void =>
+ yield;
+ case let err: curl::setopterr =>
+ fmt::fatalf("setopt returned {} instead of 0", err: int);
+ case let err: curl::performerr =>
+ fmt::fatalf("perform returned {} instead of 0", err: int);
+ case let err: curl::getinfoerr =>
+ fmt::fatalf("getinfo returned {} instead of 0", err: int);
+ };
+ fmt::print(memio::string(&resp.data)!)!;
+ fmt::printfln("status: {}, size: {}", resp.status, resp.sz)!;
+};