int Fclose(FD_t fd) { int rc = 0, ec = 0; if (fd == NULL) return -1; fd = fdLink(fd); fdstat_enter(fd, FDSTAT_CLOSE); while (fd->nfps >= 0) { fdio_close_function_t _close = FDIOVEC(fd, close); rc = _close ? _close(fd) : -2; if (fd->nfps == 0) break; if (ec == 0 && rc) ec = rc; fdPop(fd); } fdstat_exit(fd, FDSTAT_CLOSE, rc); DBGIO(fd, (stderr, "==>\tFclose(%p) rc %lx %s\n", (fd ? fd : NULL), (unsigned long)rc, fdbg(fd))); fdFree(fd); return ec; }
static FD_t bzdOpen(const char * path, const char * mode) { FD_t fd; BZFILE *bzfile;; if ((bzfile = BZ2_bzopen(path, mode)) == NULL) return NULL; fd = fdNew(path); fdPop(fd); fdPush(fd, bzdio, bzfile, -1); return fdLink(fd); }
static FD_t lzdOpen(const char * path, const char * mode) { FD_t fd; LZFILE *lzfile; if ((lzfile = lzopen(path, mode)) == NULL) return NULL; fd = fdNew(path); fdPop(fd); fdPush(fd, xzdio, lzfile, -1); return fdLink(fd); }
static FD_t gzdOpen(const char * path, const char * fmode) { FD_t fd; gzFile gzfile; if ((gzfile = gzopen(path, fmode)) == NULL) return NULL; fd = fdNew(path); fdPop(fd); fdPush(fd, gzdio, gzfile, -1); return fdLink(fd); }
/*@-globuse@*/ static /*@null@*/ FD_t xzdOpen(const char * path, const char * fmode) /*@globals fileSystem @*/ /*@modifies fileSystem @*/ { FD_t fd; mode_t mode = (fmode && fmode[0] == 'w' ? O_WRONLY : O_RDONLY); XZFILE * xzfile = xzopen(path, fmode); if (xzfile == NULL) return NULL; fd = fdNew("open (xzdOpen)"); fdPop(fd); fdPush(fd, xzdio, xzfile, -1); fdSetOpen(fd, path, fileno(xzfile->fp), mode); return fdLink(fd, "xzdOpen"); }