static int xzdClose( /*@only@*/ void * cookie) /*@globals fileSystem, internalState @*/ /*@modifies fileSystem, internalState @*/ { FD_t fd = c2f(cookie); XZFILE *xzfile; const char * errcookie; int rc; xzfile = xzdFileno(fd); if (xzfile == NULL) return -2; errcookie = strerror(ferror(xzfile->fp)); fdstat_enter(fd, FDSTAT_CLOSE); /*@-dependenttrans@*/ rc = xzclose(xzfile); /*@=dependenttrans@*/ fdstat_exit(fd, FDSTAT_CLOSE, rc); if (fd && rc == -1) fd->errcookie = errcookie; DBGIO(fd, (stderr, "==>\txzdClose(%p) rc %lx %s\n", cookie, (unsigned long)rc, fdbg(fd))); if (_rpmio_debug || rpmIsDebug()) fdstat_print(fd, "XZDIO", stderr); /*@-branchstate@*/ if (rc == 0) fd = fdFree(fd, "open (xzdClose)"); /*@=branchstate@*/ return rc; }
/*@-mustmod@*/ /* LCL: *buf is modified */ static ssize_t xzdRead(void * cookie, /*@out@*/ char * buf, size_t count) /*@globals fileSystem, internalState @*/ /*@modifies *buf, fileSystem, internalState @*/ { FD_t fd = c2f(cookie); XZFILE *xzfile; ssize_t rc = -1; assert(fd != NULL); if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ xzfile = xzdFileno(fd); assert(xzfile != NULL); fdstat_enter(fd, FDSTAT_READ); /*@-compdef@*/ rc = xzread(xzfile, buf, count); /*@=compdef@*/ DBGIO(fd, (stderr, "==>\txzdRead(%p,%p,%u) rc %lx %s\n", cookie, buf, (unsigned)count, (unsigned long)rc, fdbg(fd))); if (rc == -1) { fd->errcookie = "Lzma: decoding error"; } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); /*@-compdef@*/ if (fd->ndigests > 0 && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); /*@=compdef@*/ } return rc; }
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 void fdUpdateDigests(FD_t fd, const void * buf, size_t buflen) { if (fd && fd->digests) { fdstat_enter(fd, FDSTAT_DIGEST); rpmDigestBundleUpdate(fd->digests, buf, buflen); fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) buflen); } }
void fdFiniDigest(FD_t fd, int hashalgo, void ** datap, size_t * lenp, int asAscii) { if (fd && fd->digests) { fdstat_enter(fd, FDSTAT_DIGEST); rpmDigestBundleFinal(fd->digests, hashalgo, datap, lenp, asAscii); fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); } }
void fdInitDigest(FD_t fd, int hashalgo, rpmDigestFlags flags) { if (fd->digests == NULL) { fd->digests = rpmDigestBundleNew(); } fdstat_enter(fd, FDSTAT_DIGEST); rpmDigestBundleAdd(fd->digests, hashalgo, flags); fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); }
int Fseek(FD_t fd, off_t offset, int whence) { int rc = -1; if (fd != NULL) { fdio_seek_function_t _seek = FDIOVEC(fd, seek); fdstat_enter(fd, FDSTAT_SEEK); rc = (_seek ? _seek(fd, offset, whence) : -2); fdstat_exit(fd, FDSTAT_SEEK, rc); } DBGIO(fd, (stderr, "==>\tFseek(%p,%ld,%d) rc %lx %s\n", fd, (long)offset, whence, (unsigned long)rc, fdbg(fd))); return rc; }
ssize_t Fwrite(const void *buf, size_t size, size_t nmemb, FD_t fd) { ssize_t rc = -1; if (fd != NULL) { fdio_write_function_t _write = FDIOVEC(fd, write); fdstat_enter(fd, FDSTAT_WRITE); rc = (_write ? _write(fd, buf, size * nmemb) : -2); fdstat_exit(fd, FDSTAT_WRITE, rc); if (fd->digests && rc > 0) fdUpdateDigests(fd, buf, rc); } DBGIO(fd, (stderr, "==>\tFwrite(%p,%p,%ld) rc %ld %s\n", fd, buf, (long)size * nmemb, (long)rc, fdbg(fd))); return rc; }
ssize_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd) { ssize_t rc = -1; if (fd != NULL) { fdio_read_function_t _read = FDIOVEC(fd, read); fdstat_enter(fd, FDSTAT_READ); rc = (_read ? (*_read) (fd, buf, size * nmemb) : -2); fdstat_exit(fd, FDSTAT_READ, rc); if (fd->digests && rc > 0) fdUpdateDigests(fd, buf, rc); } DBGIO(fd, (stderr, "==>\tFread(%p,%p,%ld) rc %ld %s\n", fd, buf, (long)size * nmemb, (long)rc, fdbg(fd))); return rc; }
/*@-globuse@*/ static ssize_t xzdWrite(void * cookie, const char * buf, size_t count) /*@globals fileSystem, internalState @*/ /*@modifies fileSystem, internalState @*/ { FD_t fd = c2f(cookie); XZFILE *xzfile; ssize_t rc = 0; if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ if (fd->ndigests > 0 && count > 0) fdUpdateDigests(fd, (void *)buf, count); xzfile = xzdFileno(fd); fdstat_enter(fd, FDSTAT_WRITE); rc = xzwrite(xzfile, (void *)buf, count); DBGIO(fd, (stderr, "==>\txzdWrite(%p,%p,%u) rc %lx %s\n", cookie, buf, (unsigned)count, (unsigned long)rc, fdbg(fd))); if (rc < 0) { fd->errcookie = "Lzma: encoding error"; } else if (rc > 0) { fdstat_exit(fd, FDSTAT_WRITE, rc); } return rc; }