+static const char *basepath; /* as passed in by caller */
+static pid_t dbzcat;
+
+int dbfile_gzopen(const char *basepath_spec) {
+ assert(!dbfile);
+
+ basepath= basepath_spec;
+ //uncomppath= masprintf("%s (uncompressed)", basepath);
+
+ char *zpath= masprintf("%s.gz", basepath);
+ int zfd= open(zpath, O_RDONLY);
+ free(zpath);
+
+ if (zfd<0) { sysassert(errno==ENOENT); return 0; }
+
+ int pipefds[2];
+ sysassert(! pipe(pipefds) );
+
+ sysassert( (dbzcat=fork()) != -1 );
+ if (!dbzcat) {
+ sysassert( dup2(zfd,0)==0 );
+ sysassert( dup2(pipefds[1],1)==1 );
+ sysassert(! close(zfd) );
+ sysassert(! close(pipefds[0]) );
+ sysassert(! close(pipefds[1]) );
+ execlp("zcat","zcat",(char*)0);
+ sysassert(!"execlp zcat");
+ }
+ sysassert(! close(zfd) );
+ sysassert(! close(pipefds[1]) );
+ sysassert( dbfile= fdopen(pipefds[0], "r") );
+
+ return 1;
+}