about summary refs log tree commit diff stats
path: root/src/extern/stdio.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-30 02:51:13 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-30 03:07:15 +0200
commit8048a943706ee32f5970e461dda0a01aeb55c27f (patch)
treea9456532629274491e7ccfdc0b7773da247e58a1 /src/extern/stdio.nim
parentef8124638b6b056a4721918b47fc00a349ab0da1 (diff)
downloadchawan-8048a943706ee32f5970e461dda0a01aeb55c27f.tar.gz
loader: add local-cgi
Add w3m-style local CGI support.

It is not quite as powerful as w3m's local CGI, because it lacks an
equivalent to W3m-control. Not sure if it's worth adding; we certainly
shouldn't allow passing JS in headers, but a custom language for
headers does not sound like a great idea either...

eh, idk. also, TODO add multipart
Diffstat (limited to 'src/extern/stdio.nim')
-rw-r--r--src/extern/stdio.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/extern/stdio.nim b/src/extern/stdio.nim
new file mode 100644
index 00000000..63c0e88d
--- /dev/null
+++ b/src/extern/stdio.nim
@@ -0,0 +1,17 @@
+import posix
+
+proc closeHandle(fd, flags: cint) =
+  let devnull = open("/dev/null", flags)
+  doAssert devnull != -1
+  if devnull != fd:
+    discard dup2(devnull, fd)
+    discard close(devnull)
+
+proc closeStdin*() =
+  closeHandle(0, O_RDONLY)
+
+proc closeStdout*() =
+  closeHandle(1, O_WRONLY)
+
+proc closeStderr*() =
+  closeHandle(2, O_WRONLY)