diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-26 22:53:51 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-26 22:53:51 -0700 |
commit | e23478755d418e5f80384dbfa2536f2aaa3c888b (patch) | |
tree | 104c35ac486eb0d312835616096e5036152558af /gzio.c | |
parent | e48572f574e24bae076c909c066f42c4d1f3b3aa (diff) | |
download | txr-e23478755d418e5f80384dbfa2536f2aaa3c888b.tar.gz txr-e23478755d418e5f80384dbfa2536f2aaa3c888b.tar.bz2 txr-e23478755d418e5f80384dbfa2536f2aaa3c888b.zip |
gzio: support more modes in open-file.
* gzio.c (w_gzopen_mode): Use w_open_mode if available, in order
to support most of the flags (including "x" which Zlib has,
but which we are not passing through).
* stream.c (w_open_mode): New function formed from w_fopen_mode
content.
(w_fopen_mode): Call w_open_mode.
* stream.c (w_open_mode): Declared.
Diffstat (limited to 'gzio.c')
-rw-r--r-- | gzio.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -479,6 +479,13 @@ gzFile w_gzopen_mode(const wchar_t *wname, const wchar_t *wmode, uw_throwf(file_error_s, lit("~a: gzip stream cannot both read and write"), self, nao); } + +#if HAVE_FCNTL + { + int fd = w_open_mode(wname, m); + return (fd < 0) ? NULL : w_gzdopen_mode(fd, wmode, m, self); + } +#else { char *name = utf8_dup_to(wname); char *mode = utf8_dup_to(wmode); @@ -487,6 +494,34 @@ gzFile w_gzopen_mode(const wchar_t *wname, const wchar_t *wmode, free(mode); return f; } +#endif +} + +gzFile w_gzdopen_mode(int fd, const wchar_t *wmode, + const struct stdio_mode m, val self) +{ + if (m.buforder >= 0 || m.nonblock || m.notrunc || m.unbuf || + m.linebuf || m.interactive) + { + goto badmode; + } + + if (m.read && m.write) { + uw_throwf(file_error_s, + lit("~a: gzip stream cannot both read and write"), self, nao); + } + + { + char *mode = utf8_dup_to(wmode); + gzFile f = gzdopen(fd, mode); + free(mode); + if (f) + return f; + } + +badmode: + uw_throwf(file_error_s, + lit("~a: invalid modes for gzip stream"), self, nao); } val make_gzio_stream(gzFile f, int fd, val descr, int is_output) |