aboutsummaryrefslogtreecommitdiff
path: root/sys/libn/gz.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/libn/gz.c')
-rw-r--r--sys/libn/gz.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/sys/libn/gz.c b/sys/libn/gz.c
new file mode 100644
index 0000000..86face4
--- /dev/null
+++ b/sys/libn/gz.c
@@ -0,0 +1,90 @@
+#include <u.h>
+#include <libn.h>
+
+#include <vendor/zlib.h>
+
+gz·Stream*
+gz·open(byte *path, byte *mode)
+{
+ return gzopen(path, mode);
+}
+
+error
+gz·close(gz·Stream* s)
+{
+ return gzclose(s);
+}
+
+int
+gz·read(gz·Stream *s, int sz, int n, void* buf)
+{
+ return gzread(s, buf, n*sz);
+}
+
+int
+gz·readln(gz·Stream *s, int n, byte *buf)
+{
+ byte* b;
+ b = gzgets(s, buf, n);
+
+ return strlen(b);
+}
+
+byte
+gz·getbyte(gz·Stream *s)
+{
+ // NOTE: Can't call macro
+ byte b[2];
+ gzread(s, b, 1);
+
+ return b[0];
+}
+
+error
+gz·ungetbyte(gz·Stream *s, byte c)
+{
+ return gzungetc(c, s);
+}
+
+int
+gz·write(gz·Stream *s, int sz, int n, void* buf)
+{
+ return gzwrite(s, buf, n*sz);
+}
+
+error
+gz·putbyte(gz·Stream *s, byte c)
+{
+ return gzputc(s, c);
+}
+
+error
+gz·putstring(gz·Stream *s, byte *str)
+{
+ return gzputs(s, str);
+}
+
+int
+gz·printf(gz·Stream *s, byte *fmt, ...)
+{
+ error err;
+
+ va_list args;
+ va_start(args, fmt);
+ err = gzprintf(s, fmt, args);
+ va_end(args);
+
+ return err;
+}
+
+error
+gz·flush(gz·Stream *s)
+{
+ return gzflush(s, Z_FINISH);
+}
+
+vlong
+gz·seek(gz·Stream *s, long off, enum SeekPos whence)
+{
+ return gzseek(s, off, whence);
+}