Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Jul 2013 21:57:33 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r254259 - soc2013/dpl/head/contrib/bzip2
Message-ID:  <201307062157.r66LvXgZ085839@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Sat Jul  6 21:57:33 2013
New Revision: 254259
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254259

Log:
  Cleaning bugs in compressStream/uncompressStream.
  

Modified:
  soc2013/dpl/head/contrib/bzip2/bzip2.c

Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c	Sat Jul  6 21:11:01 2013	(r254258)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c	Sat Jul  6 21:57:33 2013	(r254259)
@@ -75,9 +75,8 @@
 #   include <sys/times.h>
 
 #   define PATH_SEP   '/'
-#   define MY_LSTAT   fstatat
-#   define MY_STAT    fstatat
-#   define MY_STATS    stat
+#   define MY_LSTAT   lstat
+#   define MY_STAT    stat
 #   define MY_S_ISREG  S_ISREG
 #   define MY_S_ISDIR  S_ISDIR
 
@@ -114,7 +113,6 @@
 #    undef MY_STAT
 #    define MY_LSTAT stat
 #    define MY_STAT stat
-#    define MY_STATS stat
 #    undef SET_BINARY_MODE
 #    define SET_BINARY_MODE(fd)                  \
       do {                                 \
@@ -148,7 +146,6 @@
 #   define PATH_SEP     '\\'
 #   define MY_LSTAT     _stat
 #   define MY_STAT      _stat
-#   define MY_STATS     _stat
 #   define MY_S_ISREG(x)  ((x) & _S_IFREG)
 #   define MY_S_ISDIR(x)  ((x) & _S_IFDIR)
 
@@ -732,7 +729,7 @@
 void cleanUpAndFail ( Int32 ec )
 {
    IntNative     retVal;
-   struct MY_STATS statBuf;
+   struct MY_STAT statBuf;
 
    if ( srcMode == SM_F2F 
       && opMode != OM_TEST
@@ -743,7 +740,7 @@
        January 2002.  (JRS 06-Jan-2002: other changes in 1.0.2 mean
        this is less likely to happen.  But to be ultra-paranoid, we
        do the check anyway.)  */
-     retVal = MY_STAT ( IN_FILENO, inName, &statBuf, 0 );
+     retVal = MY_STAT ( inName, &statBuf );
      if (retVal == 0) {
        if (noisy)
          fprintf ( stderr, 
@@ -1023,12 +1020,12 @@
   if in doubt, return True
 --*/
 static 
-Bool notAStandardFile (int fd, Char* name )
+Bool notAStandardFile ( Char* name )
 {
    IntNative     i;
-   struct MY_STATS statBuf;
+   struct MY_STAT statBuf;
 
-   i = MY_LSTAT ( fd, name, &statBuf, AT_SYMLINK_NOFOLLOW );
+   i = MY_LSTAT ( name, &statBuf );
    if (i != 0) return True;
    if (MY_S_ISREG(statBuf.st_mode)) return False;
    return True;
@@ -1040,12 +1037,12 @@
   rac 11/21/98 see if file has hard links to it
 --*/
 static 
-Int32 countHardLinks ( int fd, Char* name )
+Int32 countHardLinks ( Char* name )
 {  
    IntNative     i;
-   struct MY_STATS statBuf;
+   struct MY_STAT statBuf;
 
-   i = MY_LSTAT ( fd, name, &statBuf, AT_SYMLINK_NOFOLLOW );
+   i = MY_LSTAT (  name, &statBuf );
    if (i != 0) return 0;
    return (statBuf.st_nlink - 1);
 }
@@ -1076,7 +1073,7 @@
 */
 #if BZ_UNIX
 static 
-struct MY_STATS fileMetaInfo;
+struct MY_STAT fileMetaInfo;
 #endif
 
 static 
@@ -1085,23 +1082,29 @@
 #  if BZ_UNIX
    IntNative retVal;
    /* Note use of stat here, not lstat. */
-   retVal = MY_STAT( fd, srcName, &fileMetaInfo, 0 );
+   retVal = MY_STAT( srcName, &fileMetaInfo );
    ERROR_IF_NOT_ZERO ( retVal );
 #  endif
 }
 
 
 static 
-void applySavedTimeInfoToOutputFile ( Char *dstName )
+void applySavedTimeInfoToOutputFile ( int fd )
 {
 #  if BZ_UNIX
    IntNative     retVal;
-   struct utimbuf uTimBuf;
+/*   struct utimbuf uTimBuf;*/
+   struct timeval fdTime[2];
 
-   uTimBuf.actime = fileMetaInfo.st_atime;
-   uTimBuf.modtime = fileMetaInfo.st_mtime;
-
-   retVal = utime ( dstName, &uTimBuf );
+   fdTime[0].tv_sec = fileMetaInfo.st_atime;
+   fdTime[0].tv_usec = 0;
+   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
 }
@@ -1184,7 +1187,7 @@
    FILE  *outStr;
 #endif
    Int32 n, i;
-   struct MY_STATS statBuf;
+   struct MY_STAT statBuf;
 
    deleteOutputOnInterrupt = False;
 
@@ -1207,6 +1210,12 @@
        break;
    }
 
+   if (verbosity >= 1) {
+     fprintf ( stderr,  "  %s: ", inName );
+     pad ( inName );
+     fflush ( stderr );
+   }
+
    if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
      if (noisy)
      fprintf ( stderr, "%s: There are no files matching `%s'.\n",
@@ -1231,7 +1240,7 @@
      }
    }
    if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
-     MY_STAT( IN_FILENO, inName, &statBuf, 0);
+     MY_STAT( inName, &statBuf );
      if ( MY_S_ISDIR(statBuf.st_mode) ) {
        fprintf( stderr,
               "%s: Input file %s is a directory.\n",
@@ -1240,7 +1249,7 @@
        return;
      }
    }
-   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName, IN_FILENO )) {
+   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
      if (noisy)
      fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
             progName, inName );
@@ -1258,7 +1267,7 @@
      }
    }
    if ( srcMode == SM_F2F && !forceOverwrite &&
-      (n=countHardLinks ( IN_FILENO, inName )) > 0) {
+      (n=countHardLinks ( inName )) > 0) {
      fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
             progName, inName, n, n > 1 ? "s" : "" );
      setExit(1);
@@ -1332,12 +1341,6 @@
        break;
    }
 
-   if (verbosity >= 1) {
-     fprintf ( stderr,  "  %s: ", inName );
-     pad ( inName );
-     fflush ( stderr );
-   }
-
 #  if CAPSICUM
    /* Fork and compress in sandbox. */
    if ( (forkpid = fork()) == -1 ){
@@ -1364,10 +1367,10 @@
       deleteOutputOnInterrupt = True;
       compressStream ( inStr, outStr );
       outputHandleJustInCase = NULL;
-      
+
       /*--- If there was an I/O error, we won't get here. ---*/
       if ( srcMode == SM_F2F ) {
-         applySavedTimeInfoToOutputFile ( outName );
+         applySavedTimeInfoToOutputFile ( OUT_FILENO );
          deleteOutputOnInterrupt = False;
          if ( !keepInputFiles ) {
             IntNative retVal = remove ( inName );
@@ -1396,7 +1399,7 @@
    Int32 n, i;
    Bool  magicNumberOK;
    Bool  cantGuess;
-   struct MY_STATS statBuf;
+   struct MY_STAT statBuf;
 
    deleteOutputOnInterrupt = False;
 
@@ -1439,7 +1442,7 @@
      return;
    }
    if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
-     MY_STAT(IN_FILENO, inName, &statBuf, 0);
+     MY_STAT( inName, &statBuf );
      if ( MY_S_ISDIR(statBuf.st_mode) ) {
        fprintf( stderr,
               "%s: Input file %s is a directory.\n",
@@ -1448,7 +1451,7 @@
        return;
      }
    }
-   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName, IN_FILENO )) {
+   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
      if (noisy)
      fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
             progName, inName );
@@ -1473,7 +1476,7 @@
      }
    }
    if ( srcMode == SM_F2F && !forceOverwrite &&
-      (n=countHardLinks ( IN_FILENO, inName ) ) > 0) {
+      (n=countHardLinks ( inName ) ) > 0) {
      fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
             progName, inName, n, n > 1 ? "s" : "" );
      setExit(1);
@@ -1576,7 +1579,7 @@
       /*--- If there was an I/O error, we won't get here. ---*/
       if ( magicNumberOK ) {
         if ( srcMode == SM_F2F ) {
-          applySavedTimeInfoToOutputFile ( outName );
+          applySavedTimeInfoToOutputFile ( OUT_FILENO );
           deleteOutputOnInterrupt = False;
           if ( !keepInputFiles ) {
             IntNative retVal = remove ( inName );
@@ -1619,7 +1622,7 @@
    FILE *inStr;
 #  endif
    Bool allOK;
-   struct MY_STATS statBuf;
+   struct MY_STAT statBuf;
 
    deleteOutputOnInterrupt = False;
 
@@ -1647,7 +1650,7 @@
      return;
    }
    if ( srcMode != SM_I2O ) {
-     MY_STAT(inName, IN_FILENO, &statBuf, 0);
+     MY_STAT( inName, &statBuf );
      if ( MY_S_ISDIR(statBuf.st_mode) ) {
        fprintf( stderr,
               "%s: Input file %s is a directory.\n",



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