size_t ts_fwrite(ts_file_t *fp, const char *buf, int len) { TS_TRY(fp && buf && len > 0); switch(fp->type) { case TS_FILE_STD: return(fwrite((const void*)buf, 1, len, fp->fp.std)); case TS_FILE_ZLB: return(gzwrite(fp->fp.zlb, (const void*)buf, len)); case TS_FILE_XZ: return(xzwrite(fp->fp.xz, (const void*) buf, len)); default: (void)ts_warn(stderr, "\n"); goto fail; } fail: return(-1); }
/*@-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; }