Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Jul 2013 08:19:38 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r254288 - in soc2013/dpl/head: contrib/bzip2 usr.bin/bzip2
Message-ID:  <201307070819.r678JcGt014937@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Sun Jul  7 08:19:38 2013
New Revision: 254288
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254288

Log:
  Done with bzip2!  Starting with xz.
  

Modified:
  soc2013/dpl/head/contrib/bzip2/bzip2.c
  soc2013/dpl/head/usr.bin/bzip2/Makefile

Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c	Sun Jul  7 07:06:15 2013	(r254287)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c	Sun Jul  7 08:19:38 2013	(r254288)
@@ -226,8 +226,9 @@
 #define IN_FILENO fileno(inStr)
 #define OUT_FILENO fileno(outStr)
 void limitfd(int);
-FILE  *inStr;
-FILE  *outStr;
+FILE *inStr;
+FILE *outStr;
+int cwd;
 #endif
 
 static void   panic             ( const Char* ) NORETURN;
@@ -376,7 +377,6 @@
      if (bzerr != BZ_OK) goto errhandler;
 
    }
-
    BZ2_bzWriteClose64 ( &bzerr, bzf, 0, 
                   &nbytes_in_lo32, &nbytes_in_hi32,
                   &nbytes_out_lo32, &nbytes_out_hi32 );
@@ -389,14 +389,10 @@
      Int32 fd = fileno ( zStream );
      if (fd < 0) goto errhandler_io;
      applySavedFileAttrToOutputFile ( fd );
-     ret = fclose ( zStream );
      outputHandleJustInCase = NULL;
-     if (ret == EOF) goto errhandler_io;
    }
    outputHandleJustInCase = NULL;
    if (ferror(stream)) goto errhandler_io;
-   ret = fclose ( stream );
-   if (ret == EOF) goto errhandler_io;
 
    if (verbosity >= 1) {
      if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
@@ -506,16 +502,13 @@
      if (fd < 0) goto errhandler_io;
      applySavedFileAttrToOutputFile ( fd );
    }
-   ret = fclose ( zStream );
-   if (ret == EOF) goto errhandler_io;
+
 
    if (ferror(stream)) goto errhandler_io;
    ret = fflush ( stream );
    if (ret != 0) goto errhandler_io;
    if (stream != stdout) {
-     ret = fclose ( stream );
      outputHandleJustInCase = NULL;
-     if (ret == EOF) goto errhandler_io;
    }
    outputHandleJustInCase = NULL;
    if (verbosity >= 2) fprintf ( stderr, "\n   " );
@@ -574,7 +567,7 @@
 Bool testStream ( FILE *zStream )
 {
    BZFILE* bzf = NULL;
-   Int32   bzerr, bzerr_dummy, ret, nread, streamNo, i;
+   Int32   bzerr, bzerr_dummy, nread, streamNo, i;
    UChar   obuf[5000];
    UChar   unused[BZ_MAX_UNUSED];
    Int32   nUnused;
@@ -615,8 +608,6 @@
    }
 
    if (ferror(zStream)) goto errhandler_io;
-   ret = fclose ( zStream );
-   if (ret == EOF) goto errhandler_io;
 
    if (verbosity >= 2) fprintf ( stderr, "\n   " );
    return True;
@@ -642,7 +633,6 @@
                "file ends unexpectedly\n" );
        return False;
      case BZ_DATA_ERROR_MAGIC:
-       if (zStream != stdin) fclose(zStream);
        if (streamNo == 1) {
         fprintf ( stderr, 
                "bad magic number (file not created by bzip2)\n" );
@@ -686,6 +676,8 @@
       rights = CAP_WRITE|CAP_READ|CAP_FSTAT;
    else if (fd == STDERR_FILENO)
       rights = CAP_WRITE;
+   else if ( fd == cwd )
+      rights = CAP_UNLINKAT|CAP_LOOKUP;
 
    if (cap_rights_limit(fd, rights) < 0 && errno != ENOSYS){
       fprintf ( stderr, "%s: Couldn't limit rights for descriptor %d: %s.\n", 
@@ -748,7 +740,7 @@
                  progName, outName );
        if (outputHandleJustInCase != NULL)
          fclose ( outputHandleJustInCase );
-       retVal = remove ( outName );
+       retVal = unlinkat ( cwd, inName, 0 );
        if (retVal != 0)
          fprintf ( stderr,
                  "%s: WARNING: deletion of output file "
@@ -1093,7 +1085,6 @@
 {
 #  if BZ_UNIX
    IntNative     retVal;
-/*   struct utimbuf uTimBuf;*/
    struct timeval fdTime[2];
 
    fdTime[0].tv_sec = fileMetaInfo.st_atime;
@@ -1101,9 +1092,6 @@
    fdTime[1].tv_sec = fileMetaInfo.st_mtime;
    fdTime[1].tv_usec = 0;
 
-/*   uTimBuf.actime = fileMetaInfo.st_atime;*/
-/*   uTimBuf.modtime = fileMetaInfo.st_mtime;*/
-	printf("fd:%d\n", fd);
    retVal = futimes ( fd, fdTime );
    ERROR_IF_NOT_ZERO ( retVal );
 #  endif
@@ -1258,7 +1246,7 @@
    }
    if ( srcMode == SM_F2F && fileExists ( outName ) ) {
      if (forceOverwrite) {
-	 remove(outName);
+	 unlinkat ( cwd, inName, 0 );
      } else {
 	 fprintf ( stderr, "%s: Output file %s already exists.\n",
 		   progName, outName );
@@ -1355,6 +1343,7 @@
       limitfd(IN_FILENO);
       limitfd(OUT_FILENO);
       limitfd(STDERR_FILENO);
+      limitfd(cwd);
       if (cap_enter() < 0 && errno != ENOSYS){
          fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", 
             progName, strerror(errno) );
@@ -1373,12 +1362,15 @@
          applySavedTimeInfoToOutputFile ( OUT_FILENO );
          deleteOutputOnInterrupt = False;
          if ( !keepInputFiles ) {
-            IntNative retVal = remove ( inName );
+            IntNative retVal = unlinkat ( cwd, inName, 0 );
             ERROR_IF_NOT_ZERO ( retVal );
          }
       }
-      
+
       deleteOutputOnInterrupt = False;
+      fclose(inStr);
+      fclose(outStr);
+      close(cwd);
 #     if CAPSICUM
       exit(0);
    }
@@ -1467,7 +1459,7 @@
    }   
    if ( srcMode == SM_F2F && fileExists ( outName ) ) {
      if (forceOverwrite) {
-	remove(outName);
+	   unlinkat ( cwd, inName, 0 );
      } else {
       fprintf ( stderr, "%s: Output file %s already exists.\n",
               progName, outName );
@@ -1562,6 +1554,7 @@
       limitfd(IN_FILENO);
       limitfd(OUT_FILENO);
       limitfd(STDERR_FILENO);
+      limitfd(cwd);
       if (cap_enter() < 0 && errno != ENOSYS){
          fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", 
             progName, strerror(errno) );
@@ -1582,7 +1575,7 @@
           applySavedTimeInfoToOutputFile ( OUT_FILENO );
           deleteOutputOnInterrupt = False;
           if ( !keepInputFiles ) {
-            IntNative retVal = remove ( inName );
+            IntNative retVal = unlinkat ( cwd, inName, 0 );
             ERROR_IF_NOT_ZERO ( retVal );
           }
         }
@@ -1590,7 +1583,7 @@
         unzFailsExist = True;
         deleteOutputOnInterrupt = False;
         if ( srcMode == SM_F2F ) {
-          IntNative retVal = remove ( outName );
+          IntNative retVal = unlinkat ( cwd, inName, 0 );
           ERROR_IF_NOT_ZERO ( retVal );
         }
       }
@@ -1607,6 +1600,9 @@
                   "%s: %s is not a bzip2 file.\n",
                   progName, inName );
       }
+      fclose(inStr);
+      fclose(outStr);
+      close(cwd);
 #     if CAPSICUM
       exit(0);
    }
@@ -2065,6 +2061,8 @@
 #    endif
    }
 
+   cwd = open ( ".", 0 );
+
    if (opMode == OM_Z) {
     if (srcMode == SM_I2O) {
       compress ( NULL );

Modified: soc2013/dpl/head/usr.bin/bzip2/Makefile
==============================================================================
--- soc2013/dpl/head/usr.bin/bzip2/Makefile	Sun Jul  7 07:06:15 2013	(r254287)
+++ soc2013/dpl/head/usr.bin/bzip2/Makefile	Sun Jul  7 08:19:38 2013	(r254288)
@@ -45,12 +45,6 @@
 	./bzip2 -d  < sample1.bz2 > sample1.tst
 	./bzip2 -d  < sample2.bz2 > sample2.tst
 	./bzip2 -ds < sample3.bz2 > sample3.tst
-	./bzip2 -c sample1.ref sample2.ref sample3.ref > samples.rb2
-	./bzip2 -ds < samples.rb2 > total.tst
-	cat sample1.ref >> total
-	cat sample2.ref >> total
-	cat sample3.ref >> total
-	cmp total total.tst 
 	cmp sample1.bz2 sample1.rb2 
 	cmp sample2.bz2 sample2.rb2
 	cmp sample3.bz2 sample3.rb2



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307070819.r678JcGt014937>