socsvn commit: r253681 - soc2013/dpl/head/contrib/bzip2

dpl at FreeBSD.org dpl at FreeBSD.org
Sat Jun 29 13:33:23 UTC 2013


Author: dpl
Date: Sat Jun 29 13:33:23 2013
New Revision: 253681
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253681

Log:
  Trying hard with recvfd and sendfd.
  

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

Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c	Sat Jun 29 12:27:50 2013	(r253680)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c	Sat Jun 29 13:33:23 2013	(r253681)
@@ -1,6 +1,6 @@
 
 /*-----------------------------------------------------------*/
-/*--- A block-sorting, lossless compressor        bzip2.c ---*/
+/*--- A block-sorting, lossless compressor      bzip2.c ---*/
 /*-----------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
@@ -23,7 +23,7 @@
    Also works on 64-bit Unix boxes.
    This is the default.
 */
-#define BZ_UNIX      1
+#define BZ_UNIX     1
 
 /*--
   Win32, as seen by Jacob Navia's excellent
@@ -56,8 +56,8 @@
 #include <ctype.h>
 #include "bzlib.h"
 
-#define ERROR_IF_EOF(i)       { if ((i) == EOF)  ioError(); }
-#define ERROR_IF_NOT_ZERO(i)  { if ((i) != 0)    ioError(); }
+#define ERROR_IF_EOF(i)      { if ((i) == EOF)  ioError(); }
+#define ERROR_IF_NOT_ZERO(i)  { if ((i) != 0)   ioError(); }
 #define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
 
 
@@ -74,63 +74,64 @@
 #   include <sys/stat.h>
 #   include <sys/times.h>
 
-#   define PATH_SEP    '/'
-#   define MY_LSTAT    lstat
-#   define MY_STAT     stat
+#   define PATH_SEP   '/'
+#   define MY_LSTAT   lstat
+#   define MY_STAT    stat
 #   define MY_S_ISREG  S_ISREG
 #   define MY_S_ISDIR  S_ISDIR
 
 #   define APPEND_FILESPEC(root, name) \
-      root=snocString((root), (name))
+     root=snocString((root), (name))
 
 #   define APPEND_FLAG(root, name) \
-      root=snocString((root), (name))
+     root=snocString((root), (name))
 
 #   define SET_BINARY_MODE(fd) /**/
 
-#	ifdef __FreeBSD__
-#		include <osreldate.h>
-#		if __FreeBSD_version >= 900041
-#			define CAPSICUM 1
-#			include <sys/capability.h>
-#			include <sys/socket.h>
-#			include <sys/wait.h>
-#			include <sys/un.h>
-#		endif
-#	endif
+#   ifdef __FreeBSD__
+#      include <osreldate.h>
+#      if __FreeBSD_version >= 900041
+#         define CAPSICUM 1
+#         include <sys/capability.h>
+#         include <sys/socket.h>
+#         include <sys/wait.h>
+#         include <sys/un.h>
+#      endif
+#   endif
+
 
 #   ifdef __GNUC__
-#      define NORETURN __attribute__ ((noreturn))
+#     define NORETURN __attribute__ ((noreturn))
 #   else
-#      define NORETURN /**/
+#     define NORETURN /**/
 #   endif
 
 #   ifdef __DJGPP__
-#     include <io.h>
-#     include <fcntl.h>
-#     undef MY_LSTAT
-#     undef MY_STAT
-#     define MY_LSTAT stat
-#     define MY_STAT stat
-#     undef SET_BINARY_MODE
-#     define SET_BINARY_MODE(fd)                        \
-        do {                                            \
-           int retVal = setmode ( fileno ( fd ),        \
-                                  O_BINARY );           \
-           ERROR_IF_MINUS_ONE ( retVal );               \
-        } while ( 0 )
+#    include <io.h>
+#    include <fcntl.h>
+#    undef MY_LSTAT
+#    undef MY_STAT
+#    define MY_LSTAT stat
+#    define MY_STAT stat
+#    undef SET_BINARY_MODE
+#    define SET_BINARY_MODE(fd)                  \
+      do {                                 \
+         int retVal = setmode ( fileno ( fd ),      \
+                          O_BINARY );         \
+         ERROR_IF_MINUS_ONE ( retVal );            \
+      } while ( 0 )
 #   endif
 
 #   ifdef __CYGWIN__
-#     include <io.h>
-#     include <fcntl.h>
-#     undef SET_BINARY_MODE
-#     define SET_BINARY_MODE(fd)                        \
-        do {                                            \
-           int retVal = setmode ( fileno ( fd ),        \
-                                  O_BINARY );           \
-           ERROR_IF_MINUS_ONE ( retVal );               \
-        } while ( 0 )
+#    include <io.h>
+#    include <fcntl.h>
+#    undef SET_BINARY_MODE
+#    define SET_BINARY_MODE(fd)                  \
+      do {                                 \
+         int retVal = setmode ( fileno ( fd ),      \
+                          O_BINARY );         \
+         ERROR_IF_MINUS_ONE ( retVal );            \
+      } while ( 0 )
 #   endif
 #endif /* BZ_UNIX */
 
@@ -141,25 +142,25 @@
 #   include <fcntl.h>
 #   include <sys\stat.h>
 
-#   define NORETURN       /**/
-#   define PATH_SEP       '\\'
-#   define MY_LSTAT       _stat
-#   define MY_STAT        _stat
+#   define NORETURN      /**/
+#   define PATH_SEP      '\\'
+#   define MY_LSTAT      _stat
+#   define MY_STAT      _stat
 #   define MY_S_ISREG(x)  ((x) & _S_IFREG)
 #   define MY_S_ISDIR(x)  ((x) & _S_IFDIR)
 
 #   define APPEND_FLAG(root, name) \
-      root=snocString((root), (name))
+     root=snocString((root), (name))
 
-#   define APPEND_FILESPEC(root, name)                \
-      root = snocString ((root), (name))
+#   define APPEND_FILESPEC(root, name)            \
+     root = snocString ((root), (name))
 
-#   define SET_BINARY_MODE(fd)                        \
-      do {                                            \
-         int retVal = setmode ( fileno ( fd ),        \
-                                O_BINARY );           \
-         ERROR_IF_MINUS_ONE ( retVal );               \
-      } while ( 0 )
+#   define SET_BINARY_MODE(fd)                  \
+     do {                                 \
+       int retVal = setmode ( fileno ( fd ),      \
+                        O_BINARY );         \
+       ERROR_IF_MINUS_ONE ( retVal );            \
+     } while ( 0 )
 
 #endif /* BZ_LCCWIN32 */
 
@@ -169,14 +170,14 @@
   Some more stuff for all platforms :-)
 --*/
 
-typedef char            Char;
+typedef char         Char;
 typedef unsigned char   Bool;
 typedef unsigned char   UChar;
-typedef int             Int32;
-typedef unsigned int    UInt32;
-typedef short           Int16;
+typedef int          Int32;
+typedef unsigned int   UInt32;
+typedef short         Int16;
 typedef unsigned short  UInt16;
-                                       
+                              
 #define True  ((Bool)1)
 #define False ((Bool)0)
 
@@ -188,24 +189,24 @@
 
 
 /*---------------------------------------------------*/
-/*--- Misc (file handling) data decls             ---*/
+/*--- Misc (file handling) data decls          ---*/
 /*---------------------------------------------------*/
 
 Int32   verbosity;
-Bool    keepInputFiles, smallMode, deleteOutputOnInterrupt;
-Bool    forceOverwrite, testFailsExist, unzFailsExist, noisy;
+Bool   keepInputFiles, smallMode, deleteOutputOnInterrupt;
+Bool   forceOverwrite, testFailsExist, unzFailsExist, noisy;
 Int32   numFileNames, numFilesProcessed, blockSize100k;
 Int32   exitValue;
 
 /*-- source modes; F==file, I==stdin, O==stdout --*/
-#define SM_I2O           1
-#define SM_F2O           2
-#define SM_F2F           3
+#define SM_I2O         1
+#define SM_F2O         2
+#define SM_F2F         3
 
 /*-- operation modes --*/
-#define OM_Z             1
-#define OM_UNZ           2
-#define OM_TEST          3
+#define OM_Z          1
+#define OM_UNZ         2
+#define OM_TEST        3
 
 Int32   opMode;
 Int32   srcMode;
@@ -213,12 +214,12 @@
 #define FILE_NAME_LEN 1034
 
 Int32   longestFileName;
-Char    inName [FILE_NAME_LEN];
-Char    outName[FILE_NAME_LEN];
-Char    tmpName[FILE_NAME_LEN];
-Char    *progName;
-Char    progNameReally[FILE_NAME_LEN];
-FILE    *outputHandleJustInCase;
+Char   inName [FILE_NAME_LEN];
+Char   outName[FILE_NAME_LEN];
+Char   tmpName[FILE_NAME_LEN];
+Char   *progName;
+Char   progNameReally[FILE_NAME_LEN];
+FILE   *outputHandleJustInCase;
 Int32   workFactor;
 
 #if CAPSICUM
@@ -230,91 +231,82 @@
 int
 sendfd(int s, int fd)
 {
-	printf("sendfd on socket:%d fd:%d\n",s,fd);
-    struct {
-		struct cmsghdr h;
-		int fd;
-    } buffer;
-
-    struct msghdr msg;
-    char buf = 0;
-    struct iovec io;
-    struct cmsghdr *cmsg;
-
-    io.iov_base = &buf;
-    io.iov_len = 1;
-
-	bzero(&msg, sizeof msg);
-    msg.msg_iov = &io;
-    msg.msg_iovlen = 1;
-    msg.msg_control = &buffer;
-    msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int);
-
-    cmsg = CMSG_FIRSTHDR(&msg);
-    cmsg->cmsg_len = msg.msg_controllen;
-    cmsg->cmsg_level = SOL_SOCKET;
-    cmsg->cmsg_type = SCM_RIGHTS;
-	printf("Gotten this far\n");
-	/* Something breaks here */
-	memcpy(CMSG_DATA(cmsg), fd, sizeof(int));
-	if(sendmsg(s, &msg, 0) < 0)
-		return -1;
-	else
-		return 0;
+   printf("sendfd on socket:%d fd:%d\n",s,fd);
+
+   struct msghdr msg;   
+   struct cmsghdr *cmsg;
+   char buf = { 0 };
+   struct iovec io[1];
+
+   io[0].iov_base = buf;
+   io[0].iov_len = 1;
+
+   msg.msg_name = NULL;
+   msg.msg_namelen = 0;
+   msg.msg_iov = io;
+   msg.msg_iovlen = 1;
+   msg.msg_control = cmsg;
+   msg.msg_controllen = CMSG_LEN(sizeof(int));
+
+   cmsg->cmsg_len = msg.msg_controllen;
+   cmsg->cmsg_level = SOL_SOCKET;
+   cmsg->cmsg_type = SCM_RIGHTS;
+   *(int *)CMSG_DATA(cmsg) = fd;
+   /*Why does sendmsg set errno to 9 EBADF.*/
+   if(sendmsg(s, &msg, 0) < 0)
+      return -1;
+   return 0;
 }
 
 int
 recvfd(int s)
 {
-	printf("recvfd on socket: %d\n",s);
-    struct {
-		struct cmsghdr h;
-		int fd;
-    } buffer;
-    char buf = 0;
-    struct iovec io;
-    struct msghdr msg;
-    struct cmsghdr *cmsg;
-
-    io.iov_base = &buf;
-    io.iov_len = 1;
-
-	bzero(&msg, sizeof msg);
-    msg.msg_iov = &io;
-    msg.msg_iovlen = 1;
-    msg.msg_control = &buffer;
-    msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int);
-
-    cmsg = CMSG_FIRSTHDR(&msg);
-    cmsg->cmsg_len = msg.msg_controllen;
-    cmsg->cmsg_level = SOL_SOCKET;
-    cmsg->cmsg_type = SCM_RIGHTS;
-	/* Something breaks here */
-	memcpy(CMSG_DATA(cmsg), -1, sizeof(int));
-	printf("is this -1? %d", (int)CMSG_DATA(cmsg));
-    
-    if(recvmsg(s, &msg, 0) < 0)
-		return -1 ;
-    return ((int *)CMSG_DATA(cmsg));
+   printf("recvfd on socket:%d\n",s);
+
+   int fd;
+   struct msghdr msg;   
+   struct cmsghdr *cmsg;
+   char buf = { 0 };
+   struct iovec io[1];
+
+   io[0].iov_base = buf;
+   io[0].iov_len = 1;
+
+   msg.msg_name = NULL;
+   msg.msg_namelen = 0;
+   msg.msg_iov = io;
+   msg.msg_iovlen = 1;
+   msg.msg_control = cmsg;
+   msg.msg_controllen = CMSG_LEN(sizeof(int));
+
+   cmsg->cmsg_len = msg.msg_controllen;
+   cmsg->cmsg_level = SOL_SOCKET;
+   cmsg->cmsg_type = SCM_RIGHTS;
+   /*Why does sendmsg set errno to 9 EBADF.*/
+   if(recvmsg(s, &msg, 0) < 0)
+      return -1;
+   fd = *(int *)CMSG_DATA(cmsg);
+   printf("recvfd() fd recieved: %d", fd);
+   return 0;
 }
 #endif
 
-static void    panic                 ( const Char* ) NORETURN;
-static void    ioError               ( void )        NORETURN;
-static void    outOfMemory           ( void )        NORETURN;
-static void    configError           ( void )        NORETURN;
-static void    crcError              ( void )        NORETURN;
-static void    cleanUpAndFail        ( Int32 )       NORETURN;
-static void    compressedStreamEOF   ( void )        NORETURN;
-
-static void    copyFileName ( Char*, Char* );
-static void*   myMalloc     ( Int32 );
-static void    applySavedFileAttrToOutputFile ( IntNative fd );
+static void   panic             ( const Char* ) NORETURN;
+static void   ioError            ( void )      NORETURN;
+static void   outOfMemory         ( void )      NORETURN;
+static void   configError         ( void )      NORETURN;
+static void   crcError           ( void )      NORETURN;
+static void   cleanUpAndFail      ( Int32 )      NORETURN;
+static void   compressedStreamEOF   ( void )      NORETURN;
+
+static void   copyFileName ( Char*, Char* );
+static void*   myMalloc    ( Int32 );
+static void   applySavedFileAttrToOutputFile ( IntNative fd );
 
 
 
 /*---------------------------------------------------*/
-/*--- An implementation of 64-bit ints.  Sigh.    ---*/
+/*--- An implementation of 64-bit ints.  Sigh.   ---*/
 /*--- Roll on widespread deployment of ANSI C9X ! ---*/
 /*---------------------------------------------------*/
 
@@ -329,11 +321,11 @@
    n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
    n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
    n->b[5] = (UChar)((hi32 >> 8)  & 0xFF);
-   n->b[4] = (UChar) (hi32        & 0xFF);
+   n->b[4] = (UChar) (hi32      & 0xFF);
    n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
    n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
    n->b[1] = (UChar)((lo32 >> 8)  & 0xFF);
-   n->b[0] = (UChar) (lo32        & 0xFF);
+   n->b[0] = (UChar) (lo32      & 0xFF);
 }
 
 
@@ -344,8 +336,8 @@
    double base = 1.0;
    double sum  = 0.0;
    for (i = 0; i < 8; i++) {
-      sum  += base * (double)(n->b[i]);
-      base *= 256.0;
+     sum  += base * (double)(n->b[i]);
+     base *= 256.0;
    }
    return sum;
 }
@@ -356,7 +348,7 @@
 {
    Int32 i;
    for (i = 0; i < 8; i++)
-      if (n->b[i] != 0) return 0;
+     if (n->b[i] != 0) return 0;
    return 1;
 }
 
@@ -369,9 +361,9 @@
    Int32  i;
    rem = 0;
    for (i = 7; i >= 0; i--) {
-      tmp = rem * 256 + n->b[i];
-      n->b[i] = tmp / 10;
-      rem = tmp % 10;
+     tmp = rem * 256 + n->b[i];
+     n->b[i] = tmp / 10;
+     rem = tmp % 10;
    }
    return rem;
 }
@@ -388,18 +380,18 @@
    Int32  nBuf   = 0;
    UInt64 n_copy = *n;
    do {
-      q = uInt64_qrm10 ( &n_copy );
-      buf[nBuf] = q + '0';
-      nBuf++;
+     q = uInt64_qrm10 ( &n_copy );
+     buf[nBuf] = q + '0';
+     nBuf++;
    } while (!uInt64_isZero(&n_copy));
    outbuf[nBuf] = 0;
    for (i = 0; i < nBuf; i++) 
-      outbuf[i] = buf[nBuf-i-1];
+     outbuf[i] = buf[nBuf-i-1];
 }
 
 
 /*---------------------------------------------------*/
-/*--- Processing of complete files and streams    ---*/
+/*--- Processing of complete files and streams   ---*/
 /*---------------------------------------------------*/
 
 /*---------------------------------------------*/
@@ -431,36 +423,36 @@
    if (ferror(zStream)) goto errhandler_io;
 
    bzf = BZ2_bzWriteOpen ( &bzerr, zStream, 
-                           blockSize100k, verbosity, workFactor );   
+                     blockSize100k, verbosity, workFactor );   
    if (bzerr != BZ_OK) goto errhandler;
 
    if (verbosity >= 2) fprintf ( stderr, "\n" );
 
    while (True) {
 
-      if (myfeof(stream)) break;
-      nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
-      if (ferror(stream)) goto errhandler_io;
-      if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
-      if (bzerr != BZ_OK) goto errhandler;
+     if (myfeof(stream)) break;
+     nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
+     if (ferror(stream)) goto errhandler_io;
+     if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
+     if (bzerr != BZ_OK) goto errhandler;
 
    }
 
    BZ2_bzWriteClose64 ( &bzerr, bzf, 0, 
-                        &nbytes_in_lo32, &nbytes_in_hi32,
-                        &nbytes_out_lo32, &nbytes_out_hi32 );
+                  &nbytes_in_lo32, &nbytes_in_hi32,
+                  &nbytes_out_lo32, &nbytes_out_hi32 );
    if (bzerr != BZ_OK) goto errhandler;
 
    if (ferror(zStream)) goto errhandler_io;
    ret = fflush ( zStream );
    if (ret == EOF) goto errhandler_io;
    if (zStream != stdout) {
-      Int32 fd = fileno ( zStream );
-      if (fd < 0) goto errhandler_io;
-      applySavedFileAttrToOutputFile ( fd );
-      ret = fclose ( zStream );
-      outputHandleJustInCase = NULL;
-      if (ret == EOF) goto errhandler_io;
+     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;
@@ -468,16 +460,16 @@
    if (ret == EOF) goto errhandler_io;
 
    if (verbosity >= 1) {
-      if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
+     if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
 	 fprintf ( stderr, " no data compressed.\n");
-      } else {
+     } else {
 	 Char   buf_nin[32], buf_nout[32];
 	 UInt64 nbytes_in,   nbytes_out;
 	 double nbytes_in_d, nbytes_out_d;
 	 uInt64_from_UInt32s ( &nbytes_in, 
-			       nbytes_in_lo32, nbytes_in_hi32 );
+			      nbytes_in_lo32, nbytes_in_hi32 );
 	 uInt64_from_UInt32s ( &nbytes_out, 
-			       nbytes_out_lo32, nbytes_out_hi32 );
+			      nbytes_out_lo32, nbytes_out_hi32 );
 	 nbytes_in_d  = uInt64_to_double ( &nbytes_in );
 	 nbytes_out_d = uInt64_to_double ( &nbytes_out );
 	 uInt64_toAscii ( buf_nin, &nbytes_in );
@@ -490,25 +482,25 @@
 		   buf_nin,
 		   buf_nout
 		 );
-      }
+     }
    }
 
    return;
 
    errhandler:
    BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1, 
-                        &nbytes_in_lo32, &nbytes_in_hi32,
-                        &nbytes_out_lo32, &nbytes_out_hi32 );
+                  &nbytes_in_lo32, &nbytes_in_hi32,
+                  &nbytes_out_lo32, &nbytes_out_hi32 );
    switch (bzerr) {
-      case BZ_CONFIG_ERROR:
-         configError(); break;
-      case BZ_MEM_ERROR:
-         outOfMemory (); break;
-      case BZ_IO_ERROR:
-         errhandler_io:
-         ioError(); break;
-      default:
-         panic ( "compress:unexpected error" );
+     case BZ_CONFIG_ERROR:
+       configError(); break;
+     case BZ_MEM_ERROR:
+       outOfMemory (); break;
+     case BZ_IO_ERROR:
+       errhandler_io:
+       ioError(); break;
+     default:
+       panic ( "compress:unexpected error" );
    }
 
    panic ( "compress:end" );
@@ -540,40 +532,40 @@
 
    while (True) {
 
-      bzf = BZ2_bzReadOpen ( 
-               &bzerr, zStream, verbosity, 
-               (int)smallMode, unused, nUnused
-            );
-      if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
-      streamNo++;
-
-      while (bzerr == BZ_OK) {
-         nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
-         if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
-         if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
-            fwrite ( obuf, sizeof(UChar), nread, stream );
-         if (ferror(stream)) goto errhandler_io;
-      }
-      if (bzerr != BZ_STREAM_END) goto errhandler;
+     bzf = BZ2_bzReadOpen ( 
+            &bzerr, zStream, verbosity, 
+            (int)smallMode, unused, nUnused
+         );
+     if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
+     streamNo++;
 
-      BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
-      if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+     while (bzerr == BZ_OK) {
+       nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
+       if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
+       if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
+         fwrite ( obuf, sizeof(UChar), nread, stream );
+       if (ferror(stream)) goto errhandler_io;
+     }
+     if (bzerr != BZ_STREAM_END) goto errhandler;
 
-      unusedTmp = (UChar*)unusedTmpV;
-      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
+     BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
+     if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
 
-      BZ2_bzReadClose ( &bzerr, bzf );
-      if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+     unusedTmp = (UChar*)unusedTmpV;
+     for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
 
-      if (nUnused == 0 && myfeof(zStream)) break;
+     BZ2_bzReadClose ( &bzerr, bzf );
+     if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+
+     if (nUnused == 0 && myfeof(zStream)) break;
    }
 
    closeok:
    if (ferror(zStream)) goto errhandler_io;
    if (stream != stdout) {
-      Int32 fd = fileno ( stream );
-      if (fd < 0) goto errhandler_io;
-      applySavedFileAttrToOutputFile ( fd );
+     Int32 fd = fileno ( stream );
+     if (fd < 0) goto errhandler_io;
+     applySavedFileAttrToOutputFile ( fd );
    }
    ret = fclose ( zStream );
    if (ret == EOF) goto errhandler_io;
@@ -582,55 +574,55 @@
    ret = fflush ( stream );
    if (ret != 0) goto errhandler_io;
    if (stream != stdout) {
-      ret = fclose ( stream );
-      outputHandleJustInCase = NULL;
-      if (ret == EOF) goto errhandler_io;
+     ret = fclose ( stream );
+     outputHandleJustInCase = NULL;
+     if (ret == EOF) goto errhandler_io;
    }
    outputHandleJustInCase = NULL;
-   if (verbosity >= 2) fprintf ( stderr, "\n    " );
+   if (verbosity >= 2) fprintf ( stderr, "\n   " );
    return True;
 
    trycat: 
    if (forceOverwrite) {
-      rewind(zStream);
-      while (True) {
-      	 if (myfeof(zStream)) break;
-      	 nread = fread ( obuf, sizeof(UChar), 5000, zStream );
-      	 if (ferror(zStream)) goto errhandler_io;
-      	 if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
-      	 if (ferror(stream)) goto errhandler_io;
-      }
-      goto closeok;
+     rewind(zStream);
+     while (True) {
+     	 if (myfeof(zStream)) break;
+     	 nread = fread ( obuf, sizeof(UChar), 5000, zStream );
+     	 if (ferror(zStream)) goto errhandler_io;
+     	 if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
+     	 if (ferror(stream)) goto errhandler_io;
+     }
+     goto closeok;
    }
   
    errhandler:
    BZ2_bzReadClose ( &bzerr_dummy, bzf );
    switch (bzerr) {
-      case BZ_CONFIG_ERROR:
-         configError(); break;
-      case BZ_IO_ERROR:
-         errhandler_io:
-         ioError(); break;
-      case BZ_DATA_ERROR:
-         crcError();
-      case BZ_MEM_ERROR:
-         outOfMemory();
-      case BZ_UNEXPECTED_EOF:
-         compressedStreamEOF();
-      case BZ_DATA_ERROR_MAGIC:
-         if (zStream != stdin) fclose(zStream);
-         if (stream != stdout) fclose(stream);
-         if (streamNo == 1) {
-            return False;
-         } else {
-            if (noisy)
-            fprintf ( stderr, 
-                      "\n%s: %s: trailing garbage after EOF ignored\n",
-                      progName, inName );
-            return True;       
-         }
-      default:
-         panic ( "decompress:unexpected error" );
+     case BZ_CONFIG_ERROR:
+       configError(); break;
+     case BZ_IO_ERROR:
+       errhandler_io:
+       ioError(); break;
+     case BZ_DATA_ERROR:
+       crcError();
+     case BZ_MEM_ERROR:
+       outOfMemory();
+     case BZ_UNEXPECTED_EOF:
+       compressedStreamEOF();
+     case BZ_DATA_ERROR_MAGIC:
+       if (zStream != stdin) fclose(zStream);
+       if (stream != stdout) fclose(stream);
+       if (streamNo == 1) {
+         return False;
+       } else {
+         if (noisy)
+         fprintf ( stderr, 
+                 "\n%s: %s: trailing garbage after EOF ignored\n",
+                 progName, inName );
+         return True;      
+       }
+     default:
+       panic ( "decompress:unexpected error" );
    }
 
    panic ( "decompress:end" );
@@ -658,28 +650,28 @@
 
    while (True) {
 
-      bzf = BZ2_bzReadOpen ( 
-               &bzerr, zStream, verbosity, 
-               (int)smallMode, unused, nUnused
-            );
-      if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
-      streamNo++;
-
-      while (bzerr == BZ_OK) {
-         nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
-         if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
-      }
-      if (bzerr != BZ_STREAM_END) goto errhandler;
+     bzf = BZ2_bzReadOpen ( 
+            &bzerr, zStream, verbosity, 
+            (int)smallMode, unused, nUnused
+         );
+     if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
+     streamNo++;
 
-      BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
-      if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
+     while (bzerr == BZ_OK) {
+       nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
+       if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
+     }
+     if (bzerr != BZ_STREAM_END) goto errhandler;
+
+     BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
+     if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
 
-      unusedTmp = (UChar*)unusedTmpV;
-      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
+     unusedTmp = (UChar*)unusedTmpV;
+     for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
 
-      BZ2_bzReadClose ( &bzerr, bzf );
-      if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
-      if (nUnused == 0 && myfeof(zStream)) break;
+     BZ2_bzReadClose ( &bzerr, bzf );
+     if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
+     if (nUnused == 0 && myfeof(zStream)) break;
 
    }
 
@@ -687,43 +679,43 @@
    ret = fclose ( zStream );
    if (ret == EOF) goto errhandler_io;
 
-   if (verbosity >= 2) fprintf ( stderr, "\n    " );
+   if (verbosity >= 2) fprintf ( stderr, "\n   " );
    return True;
 
    errhandler:
    BZ2_bzReadClose ( &bzerr_dummy, bzf );
    if (verbosity == 0) 
-      fprintf ( stderr, "%s: %s: ", progName, inName );
+     fprintf ( stderr, "%s: %s: ", progName, inName );
    switch (bzerr) {
-      case BZ_CONFIG_ERROR:
-         configError(); break;
-      case BZ_IO_ERROR:
-         errhandler_io:
-         ioError(); break;
-      case BZ_DATA_ERROR:
-         fprintf ( stderr,
-                   "data integrity (CRC) error in data\n" );
+     case BZ_CONFIG_ERROR:
+       configError(); break;
+     case BZ_IO_ERROR:
+       errhandler_io:
+       ioError(); break;
+     case BZ_DATA_ERROR:
+       fprintf ( stderr,
+               "data integrity (CRC) error in data\n" );
+       return False;
+     case BZ_MEM_ERROR:
+       outOfMemory();
+     case BZ_UNEXPECTED_EOF:
+       fprintf ( stderr,
+               "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" );
          return False;
-      case BZ_MEM_ERROR:
-         outOfMemory();
-      case BZ_UNEXPECTED_EOF:
-         fprintf ( stderr,
-                   "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" );
-            return False;
-         } else {
-            if (noisy)
-            fprintf ( stderr, 
-                      "trailing garbage after EOF ignored\n" );
-            return True;       
-         }
-      default:
-         panic ( "test:unexpected error" );
+       } else {
+         if (noisy)
+         fprintf ( stderr, 
+                 "trailing garbage after EOF ignored\n" );
+         return True;      
+       }
+     default:
+       panic ( "test:unexpected error" );
    }
 
    panic ( "test:end" );
@@ -732,7 +724,7 @@
 
 
 /*---------------------------------------------------*/
-/*--- Error [non-] handling grunge                ---*/
+/*--- Error [non-] handling grunge            ---*/
 /*---------------------------------------------------*/
 
 /*---------------------------------------------*/
@@ -749,12 +741,12 @@
 {
    if (noisy)
    fprintf (
-      stderr,
-      "\nIt is possible that the compressed file(s) have become corrupted.\n"
-        "You can use the -tvv option to test integrity of such files.\n\n"
-        "You can use the `bzip2recover' program to attempt to recover\n"
-        "data from undamaged sections of corrupted files.\n\n"
-    );
+     stderr,
+     "\nIt is possible that the compressed file(s) have become corrupted.\n"
+      "You can use the -tvv option to test integrity of such files.\n\n"
+      "You can use the `bzip2recover' program to attempt to recover\n"
+      "data from undamaged sections of corrupted files.\n\n"
+   );
 }
 
 
@@ -764,9 +756,9 @@
 {
    if (noisy)
    fprintf (
-      stderr,
-      "\tInput file = %s, output file = %s\n",
-      inName, outName 
+     stderr,
+     "\tInput file = %s, output file = %s\n",
+     inName, outName 
    );
 }
 
@@ -775,55 +767,55 @@
 static 
 void cleanUpAndFail ( Int32 ec )
 {
-   IntNative      retVal;
+   IntNative     retVal;
    struct MY_STAT statBuf;
 
    if ( srcMode == SM_F2F 
-        && opMode != OM_TEST
-        && deleteOutputOnInterrupt ) {
+      && opMode != OM_TEST
+      && deleteOutputOnInterrupt ) {
 
-      /* Check whether input file still exists.  Delete output file
-         only if input exists to avoid loss of data.  Joerg Prante, 5
-         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 ( inName, &statBuf );
-      if (retVal == 0) {
-         if (noisy)
-            fprintf ( stderr, 
-                      "%s: Deleting output file %s, if it exists.\n",
-                      progName, outName );
-         if (outputHandleJustInCase != NULL)
-            fclose ( outputHandleJustInCase );
-         retVal = remove ( outName );
-         if (retVal != 0)
-            fprintf ( stderr,
-                      "%s: WARNING: deletion of output file "
-                      "(apparently) failed.\n",
-                      progName );
-      } else {
-         fprintf ( stderr,
-                   "%s: WARNING: deletion of output file suppressed\n",
-                    progName );
-         fprintf ( stderr,
-                   "%s:    since input file no longer exists.  Output file\n",
-                   progName );
-         fprintf ( stderr,
-                   "%s:    `%s' may be incomplete.\n",
-                   progName, outName );
+     /* Check whether input file still exists.  Delete output file
+       only if input exists to avoid loss of data.  Joerg Prante, 5
+       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 ( inName, &statBuf );
+     if (retVal == 0) {
+       if (noisy)
          fprintf ( stderr, 
-                   "%s:    I suggest doing an integrity test (bzip2 -tv)"
-                   " of it.\n",
-                   progName );
-      }
+                 "%s: Deleting output file %s, if it exists.\n",
+                 progName, outName );
+       if (outputHandleJustInCase != NULL)
+         fclose ( outputHandleJustInCase );
+       retVal = remove ( outName );
+       if (retVal != 0)
+         fprintf ( stderr,
+                 "%s: WARNING: deletion of output file "
+                 "(apparently) failed.\n",
+                 progName );
+     } else {
+       fprintf ( stderr,
+               "%s: WARNING: deletion of output file suppressed\n",
+               progName );
+       fprintf ( stderr,
+               "%s:   since input file no longer exists.  Output file\n",
+               progName );
+       fprintf ( stderr,
+               "%s:   `%s' may be incomplete.\n",
+               progName, outName );
+       fprintf ( stderr, 
+               "%s:   I suggest doing an integrity test (bzip2 -tv)"
+               " of it.\n",
+               progName );
+     }
    }
 
    if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) {
-      fprintf ( stderr, 
-                "%s: WARNING: some files have not been processed:\n"
-                "%s:    %d specified on command line, %d not processed yet.\n\n",
-                progName, progName,
-                numFileNames, numFileNames - numFilesProcessed );
+     fprintf ( stderr, 
+            "%s: WARNING: some files have not been processed:\n"
+            "%s:   %d specified on command line, %d not processed yet.\n\n",
+            progName, progName,
+            numFileNames, numFileNames - numFilesProcessed );

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-soc-all mailing list