RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   02-Jun-2017 05:49:52
  Branch: rpm-5_4                          Handle: 2017060203495100

  Modified files:           (Branch: rpm-5_4)
    rpm                     CHANGES
    rpm/rpmio               tzstd.c zstdio.c

  Log:
    - zstd: fix: *Close decompress exit code.
    - zstd: fix: fopen the input/output file, as appropriate.

  Summary:
    Revision    Changes     Path
    1.3501.2.570+2  -0      rpm/CHANGES
    1.1.2.4     +39 -1      rpm/rpmio/tzstd.c
    1.1.2.3     +43 -56     rpm/rpmio/zstdio.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3501.2.569 -r1.3501.2.570 CHANGES
  --- rpm/CHANGES       1 Jun 2017 21:10:28 -0000       1.3501.2.569
  +++ rpm/CHANGES       2 Jun 2017 03:49:51 -0000       1.3501.2.570
  @@ -1,4 +1,6 @@
   5.4.17 -> 5.4.18:
  +    - jbj: zstd: fix: *Close decompress exit code.
  +    - jbj: zstd: fix: fopen the input/output file, as appropriate.
       - jbj: zstd: rearrange the code into final form.
       - jbj: zstd: fix: rename from "zstio" to "zstdio".
       - jbj: zstd: stub in zstd compression framework.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/tzstd.c
  ============================================================================
  $ cvs diff -u -r1.1.2.3 -r1.1.2.4 tzstd.c
  --- rpm/rpmio/tzstd.c 1 Jun 2017 21:10:29 -0000       1.1.2.3
  +++ rpm/rpmio/tzstd.c 2 Jun 2017 03:49:51 -0000       1.1.2.4
  @@ -112,6 +112,42 @@
       return rc;
   }
   
  +static int readFile(const char *ifn, const char *fmode)
  +{
  +    char b[BUFSIZ];
  +    size_t nb = sizeof(b);
  +    int rc = -2;
  +
  +    FD_t ifd = Fopen(ifn, fmode);
  +    if (ifd) {
  +     size_t nr = Fread(b, 1, nb, ifd);
  +     if (nr > 0)
  +         fprintf(stderr, "*** %s: nr %zd \"%.*s\"\n", __FUNCTION__, nr, 
(int)nr, b);
  +     rc = Fclose(ifd);
  +    }
  +    return rc;
  +}
  +
  +static int writeFile(const char *ofn, const char *fmode)
  +{
  +    char b[BUFSIZ];
  +    size_t nb = sizeof(b);
  +    int rc = -2;
  +
  +    strncpy(b, "abcdefghijklmnopqrstuvwxyz\n", nb);
  +    size_t blen = strlen(b);
  +
  +    FD_t ofd = Fopen(ofn, fmode);
  +    if (ofd) {
  +     size_t nw = Fwrite(b, 1, blen, ofd);
  +assert(nw == blen);
  +     if (nw > 0)
  +         fprintf(stderr, "*** %s: nw %zd \"%s\"\n", __FUNCTION__, nw, b);
  +     rc = Fclose(ofd);
  +    }
  +    return rc;
  +}
  +
   /*==============================================================*/
   #if !defined(POPT_BIT_XOR)
   #define      POPT_BIT_XOR    (POPT_ARG_VAL|POPT_ARGFLAG_XOR)
  @@ -152,9 +188,11 @@
       oflags = rpmioOflags;
   #endif
   
  -    switch (2) {
  +    switch (4) {
       case 1:  ec = compressFile(ifn, "w3?.zstdio");   break;
       case 2:  ec = decompressFile(ifn, "r?.zstdio");  break;
  +    case 3:  ec = readFile(ifn, "rb?.zstdio");       break;
  +    case 4:  ec = writeFile(ifn, "wb?.zstdio");      break;
       }
   
       ifn = _free(ifn);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/zstdio.c
  ============================================================================
  $ cvs diff -u -r1.1.2.2 -r1.1.2.3 zstdio.c
  --- rpm/rpmio/zstdio.c        1 Jun 2017 21:10:29 -0000       1.1.2.2
  +++ rpm/rpmio/zstdio.c        2 Jun 2017 03:49:51 -0000       1.1.2.3
  @@ -249,20 +249,31 @@
   assert(fmode != NULL);               /* XXX return NULL instead? */
   
       const char * s = fmode;
  -    int c;
       int oflags = 0;
       int omode = 0644;
       int level = 3;   /* XXX zstd permits 1-19 (default: 3) */
   
  +    char stdio[32];
  +    char *t = stdio;
  +    char *te = t + sizeof(stdio) - 2;
  +    int c;
  +
  +SPEW("--> %s(%s,%s,%d,0x%x)\n", __FUNCTION__, path, fmode, fdno, flags);
       switch ((c = *s++)) {
       case 'a':
  +     *t++ = (char)c;
        oflags = O_WRONLY | O_CREAT | O_APPEND;
  +     flags &= ~RPMZSTD_FLAGS_DECOMPRESS;     /* XXX */
        break;
       case 'w':
  +     *t++ = (char)c;
        oflags = O_WRONLY | O_CREAT | O_TRUNC;
  +     flags &= ~RPMZSTD_FLAGS_DECOMPRESS;     /* XXX */
        break;
       case 'r':
  +     *t++ = (char)c;
        oflags = O_RDONLY;
  +     flags |= RPMZSTD_FLAGS_DECOMPRESS;      /* XXX */
        break;
       }
        
  @@ -271,14 +282,21 @@
        case '.':
            break;
        case '+':
  +         if (t < te) *t++ = c;
            oflags &= ~(O_RDONLY|O_WRONLY);
            oflags |= O_RDWR;
            continue;
            break;
  +     case 'b':       /* XXX binary */
  +         if (t < te) *t++ = c;
  +         continue;
  +         break;
        case 'c':       /* XXX no cancel */
  +         if (t < te) *t++ = c;
            continue;
            break;
        case 'm':       /* XXX mmap */
  +         if (t < te) *t++ = c;
            continue;
            break;
        case 'e':       /* O_CLOEXEC */
  @@ -294,6 +312,7 @@
            break;
        case 'x':
            oflags |= O_EXCL;
  +         if (t < te) *t++ = c;
            continue;
            break;
        case '?':
  @@ -310,12 +329,24 @@
        }
        break;
       }
  +    *t = '\0';
   
  -    zstd->path = xstrdup(path);
       zstd->fmode = xstrdup(fmode);
  -    zstd->fdno = fdno;
       zstd->flags = flags;
   
  +    if (fdno >= 0) {
  +     zstd->path == NULL;
  +     zstd->fdno = fdno;
  +fprintf(stderr, "\tflags 0x%x stdio \"%s\" %s\n", zstd->flags, stdio, 
(ZSTDF_ISSET(DECOMPRESS) ? "decompress" : "compress"));
  +     if (ZSTDF_ISSET(DECOMPRESS)) {
  +assert((zstd->ifp = fdopen(fdno, stdio)) != NULL);
  +     } else {
  +assert((zstd->ofp = fdopen(fdno, stdio)) != NULL);
  +     }
  +    } else {
  +     zstd->path = xstrdup(path);
  +     zstd->fdno = -1;
  +    }
       zstd->oflags = oflags;
       zstd->omode = omode;
   
  @@ -417,6 +448,7 @@
   SPEW("-->\t%s(%p)\n", __FUNCTION__, zstd);
       if (ZSTDF_ISSET(DECOMPRESS)) {   /* decompress */
   assert(zstd->dstream);
  +     rc = 0;
       } else {                         /* compress */
   assert(zstd->cstream);
        /* close frame */
  @@ -429,9 +461,11 @@
   fprintf(stderr, "not fully flushed");
            rc = -1;
        } else {
  -         zstd->nw = fwrite(zstd->ob, 1, zstd->zob.pos, zstd->ofp);
  +         if (zstd->ofp) {
  +             zstd->nw = fwrite(zstd->ob, 1, zstd->zob.pos, zstd->ofp);
   assert(zstd->nw == zstd->zob.pos);
   SPEW("<--\tfwrite(%p, 1, %zu, %p) nw %zd\n", zstd->ob, zstd->zob.pos, 
zstd->ofp, zstd->nw);
  +         }
            rc = 0;
        }
        rpmzstdFini(zstd);      /* XXX rpmzstdFree? */
  @@ -443,9 +477,11 @@
   
   ssize_t rpmzstdRead(rpmzstd zstd, void *b, size_t nb)
   {
  -    ssize_t rc = 0;
  +    ssize_t rc = -2;
   
  -SPEW("-->\t%s(%p,%p[%zd])\n", __FUNCTION__, zstd, b, nb);
  +SPEW("-->\t%s(%p,%p[%zd]) ifp %p\n", __FUNCTION__, zstd, b, nb, (zstd ? 
zstd->ifp : NULL));
  +    if (zstd->ifp == NULL)
  +     goto exit;
   
       zstd->zob.dst  = b;
       zstd->zob.size = nb;
  @@ -478,6 +514,7 @@
       }
        rc = (rc >= 0 ? (ssize_t)zstd->zob.pos : rc);
    
  +exit:
   SPEW("<--\t%s(%p,%p[%zd]) rc %ld\n", __FUNCTION__, zstd, b, nb, rc);
       return rc;
   }
  @@ -551,56 +588,6 @@
   }
   
   /* =============================================================== */
  -static
  -const char * rpmzsfError(gzFile gz, int *errnum)
  -{
  -    return "";
  -}
  -
  -static
  -gzFile rpmzsfOpen(const char *path, const char * fmode, int fdno)
  -{
  -    return NULL;
  -}
  -
  -static
  -int rpmzsfRead(gzFile gz, const void *buf, size_t len)
  -{
  -    int rc = -1;
  -
  -    return rc;
  -}
  -
  -static
  -int rpmzsfWrite(gzFile gz, void *buf, unsigned len)
  -{
  -    int rc = -1;
  -
  -    return rc;
  -}
  -
  -static
  -int rpmzsfSeek(gzFile gz, off_t offset, int whence)
  -{
  -    int rc = -1;
  -    return rc;
  -}
  -
  -static
  -int rpmzsfClose(gzFile gz)
  -{
  -    int rc = -1;
  -    return rc;
  -}
  -
  -static
  -int rpmzsfFlush(gzFile gz)
  -{
  -    int rc = -1;
  -    return rc;
  -}
  -
  -/* =============================================================== */
   /* from ../lib/cpio.h */
   #define CPIO_NEWC_MAGIC "070701"
   #define PHYS_HDR_SIZE 110
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to