+#endif
+
+lisp_object_t* lisp_read_from_gzfile(const char* filename)
+{
+ bool done = false;
+ lisp_object_t* root_obj = 0;
+ int chunk_size = 128 * 1024;
+ int buf_pos = 0;
+ int try_number = 1;
+ char* buf = static_cast<char*>(malloc(chunk_size));
+ assert(buf);
+
+ gzFile in = gzopen(filename, "r");
+
+ while (!done)
+ {
+ int ret = gzread(in, buf + buf_pos, chunk_size);
+ if (ret == -1)
+ {
+ free (buf);
+ assert(!"Error while reading from file");
+ }
+ else if (ret == chunk_size) // buffer got full, eof not yet there so resize
+ {
+ buf_pos = chunk_size * try_number;
+ try_number += 1;
+ buf = static_cast<char*>(realloc(buf, chunk_size * try_number));
+ assert(buf);
+ }
+ else
+ {
+ // everything fine, encountered EOF
+ done = true;
+ }
+ }
+
+ lisp_stream_t stream;
+ lisp_stream_init_string (&stream, buf);
+ root_obj = lisp_read (&stream);
+
+ free(buf);
+ gzclose(in);
+
+ return root_obj;
+}