ReactOS  0.4.14-dev-77-gd9e7c48
bzip2.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include "bzlib.h"
#include <fcntl.h>
#include <sys/types.h>
#include <utime.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/times.h>
Include dependency graph for bzip2.c:

Go to the source code of this file.

Classes

struct  zzzz
 

Macros

#define BZ_UNIX   1
 
#define BZ_LCCWIN32   0
 
#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(); }
 
#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))
 
#define APPEND_FLAG(root, name)   root=snocString((root), (name))
 
#define SET_BINARY_MODE(fd)
 
#define NORETURN
 
#define True   ((Bool)1)
 
#define False   ((Bool)0)
 
#define SM_I2O   1
 
#define SM_F2O   2
 
#define SM_F2F   3
 
#define OM_Z   1
 
#define OM_UNZ   2
 
#define OM_TEST   3
 
#define FILE_NAME_LEN   1034
 
#define BZ_N_SUFFIX_PAIRS   4
 
#define ISFLAG(s)   (strcmp(aa->name, (s))==0)
 

Typedefs

typedef char Char
 
typedef unsigned char Bool
 
typedef unsigned char UChar
 
typedef int Int32
 
typedef unsigned int UInt32
 
typedef short Int16
 
typedef unsigned short UInt16
 
typedef int IntNative
 
typedef struct zzzz Cell
 

Functions

static void panic (const Char *)
 
static void uInt64_from_UInt32s (UInt64 *n, UInt32 lo32, UInt32 hi32)
 
static double uInt64_to_double (UInt64 *n)
 
static Bool uInt64_isZero (UInt64 *n)
 
static Int32 uInt64_qrm10 (UInt64 *n)
 
static void uInt64_toAscii (char *outbuf, UInt64 *n)
 
static Bool myfeof (FILE *f)
 
static void compressStream (FILE *stream, FILE *zStream)
 
static Bool uncompressStream (FILE *zStream, FILE *stream)
 
static Bool testStream (FILE *zStream)
 
static void setExit (Int32 v)
 
static void cadvise (void)
 
static void showFileNames (void)
 
static void cleanUpAndFail (Int32 ec)
 
static void crcError (void)
 
static void compressedStreamEOF (void)
 
static void ioError (void)
 
static void mySignalCatcher (IntNative n)
 
static void mySIGSEGVorSIGBUScatcher (IntNative n)
 
static void outOfMemory (void)
 
static void configError (void)
 
static void pad (Char *s)
 
static void copyFileName (Char *to, Char *from)
 
static Bool fileExists (Char *name)
 
static FILEfopen_output_safely (Char *name, const char *mode)
 
static Bool notAStandardFile (Char *name)
 
static Int32 countHardLinks (Char *name)
 
static void saveInputFileMetaInfo (Char *srcName)
 
static void applySavedTimeInfoToOutputFile (Char *dstName)
 
static void applySavedFileAttrToOutputFile (IntNative fd)
 
static Bool containsDubiousChars (Char *name)
 
static Bool hasSuffix (Char *s, const Char *suffix)
 
static Bool mapSuffix (Char *name, const Char *oldSuffix, const Char *newSuffix)
 
static void compress (Char *name)
 
static void uncompress (Char *name)
 
static void testf (Char *name)
 
static void license (void)
 
static void usage (Char *fullProgName)
 
static void redundant (Char *flag)
 
static voidmyMalloc (Int32 n)
 
static CellmkCell (void)
 
static CellsnocString (Cell *root, Char *name)
 
static void addFlagsFromEnvVar (Cell **argList, Char *varName)
 
IntNative main (IntNative argc, Char *argv[])
 

Variables

Int32 verbosity
 
Bool keepInputFiles
 
Bool smallMode
 
Bool deleteOutputOnInterrupt
 
Bool forceOverwrite
 
Bool testFailsExist
 
Bool unzFailsExist
 
Bool noisy
 
Int32 numFileNames
 
Int32 numFilesProcessed
 
Int32 blockSize100k
 
Int32 exitValue
 
Int32 opMode
 
Int32 srcMode
 
Int32 longestFileName
 
Char inName [FILE_NAME_LEN]
 
Char outName [FILE_NAME_LEN]
 
Char tmpName [FILE_NAME_LEN]
 
CharprogName
 
Char progNameReally [FILE_NAME_LEN]
 
FILEoutputHandleJustInCase
 
Int32 workFactor
 
 UInt64
 
static struct MY_STAT fileMetaInfo
 
const CharzSuffix [BZ_N_SUFFIX_PAIRS] = { ".bz2", ".bz", ".tbz2", ".tbz" }
 
const CharunzSuffix [BZ_N_SUFFIX_PAIRS] = { "", "", ".tar", ".tar" }
 

Macro Definition Documentation

◆ APPEND_FILESPEC

#define APPEND_FILESPEC (   root,
  name 
)    root=snocString((root), (name))

Definition at line 83 of file bzip2.c.

◆ APPEND_FLAG

#define APPEND_FLAG (   root,
  name 
)    root=snocString((root), (name))

Definition at line 86 of file bzip2.c.

◆ BZ_LCCWIN32

#define BZ_LCCWIN32   0

Definition at line 35 of file bzip2.c.

◆ BZ_N_SUFFIX_PAIRS

#define BZ_N_SUFFIX_PAIRS   4

Definition at line 1102 of file bzip2.c.

◆ BZ_UNIX

#define BZ_UNIX   1

Definition at line 26 of file bzip2.c.

◆ ERROR_IF_EOF

#define ERROR_IF_EOF (   i)    { if ((i) == EOF) ioError(); }

Definition at line 59 of file bzip2.c.

◆ ERROR_IF_MINUS_ONE

#define ERROR_IF_MINUS_ONE (   i)    { if ((i) == (-1)) ioError(); }

Definition at line 61 of file bzip2.c.

◆ ERROR_IF_NOT_ZERO

#define ERROR_IF_NOT_ZERO (   i)    { if ((i) != 0) ioError(); }

Definition at line 60 of file bzip2.c.

◆ False

#define False   ((Bool)0)

Definition at line 170 of file bzip2.c.

◆ FILE_NAME_LEN

#define FILE_NAME_LEN   1034

Definition at line 202 of file bzip2.c.

◆ ISFLAG

#define ISFLAG (   s)    (strcmp(aa->name, (s))==0)

Definition at line 1774 of file bzip2.c.

◆ MY_LSTAT

#define MY_LSTAT   lstat

Definition at line 78 of file bzip2.c.

◆ MY_S_ISDIR

#define MY_S_ISDIR   S_ISDIR

Definition at line 81 of file bzip2.c.

◆ MY_S_ISREG

#define MY_S_ISREG   S_ISREG

Definition at line 80 of file bzip2.c.

◆ MY_STAT

#define MY_STAT   stat

Definition at line 79 of file bzip2.c.

◆ NORETURN

#define NORETURN

Definition at line 94 of file bzip2.c.

◆ OM_TEST

#define OM_TEST   3

Definition at line 197 of file bzip2.c.

◆ OM_UNZ

#define OM_UNZ   2

Definition at line 196 of file bzip2.c.

◆ OM_Z

#define OM_Z   1

Definition at line 195 of file bzip2.c.

◆ PATH_SEP

#define PATH_SEP   '/'

Definition at line 77 of file bzip2.c.

◆ SET_BINARY_MODE

#define SET_BINARY_MODE (   fd)

Definition at line 89 of file bzip2.c.

◆ SM_F2F

#define SM_F2F   3

Definition at line 192 of file bzip2.c.

◆ SM_F2O

#define SM_F2O   2

Definition at line 191 of file bzip2.c.

◆ SM_I2O

#define SM_I2O   1

Definition at line 190 of file bzip2.c.

◆ True

#define True   ((Bool)1)

Definition at line 169 of file bzip2.c.

Typedef Documentation

◆ Bool

typedef unsigned char Bool

Definition at line 162 of file bzip2.c.

◆ Cell

typedef struct zzzz Cell

◆ Char

typedef char Char

Definition at line 161 of file bzip2.c.

◆ Int16

typedef short Int16

Definition at line 166 of file bzip2.c.

◆ Int32

typedef int Int32

Definition at line 164 of file bzip2.c.

◆ IntNative

typedef int IntNative

Definition at line 176 of file bzip2.c.

◆ UChar

typedef unsigned char UChar

Definition at line 163 of file bzip2.c.

◆ UInt16

typedef unsigned short UInt16

Definition at line 167 of file bzip2.c.

◆ UInt32

typedef unsigned int UInt32

Definition at line 165 of file bzip2.c.

Function Documentation

◆ addFlagsFromEnvVar()

static void addFlagsFromEnvVar ( Cell **  argList,
Char varName 
)
static

Definition at line 1747 of file bzip2.c.

1748 {
1749  Int32 i, j, k;
1750  Char *envbase, *p;
1751 
1752  envbase = getenv(varName);
1753  if (envbase != NULL) {
1754  p = envbase;
1755  i = 0;
1756  while (True) {
1757  if (p[i] == 0) break;
1758  p += i;
1759  i = 0;
1760  while (isspace((Int32)(p[0]))) p++;
1761  while (p[i] != 0 && !isspace((Int32)(p[i]))) i++;
1762  if (i > 0) {
1763  k = i; if (k > FILE_NAME_LEN-10) k = FILE_NAME_LEN-10;
1764  for (j = 0; j < k; j++) tmpName[j] = p[j];
1765  tmpName[k] = 0;
1766  APPEND_FLAG(*argList, tmpName);
1767  }
1768  }
1769  }
1770 }
#define isspace(c)
Definition: acclib.h:69
Char tmpName[FILE_NAME_LEN]
Definition: bzip2.c:207
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
char Char
Definition: bzip2.c:161
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define True
Definition: bzip2.c:169
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
LONG Int32
Definition: chm_lib.c:105
#define FILE_NAME_LEN
Definition: bzip2.c:202
GLfloat GLfloat p
Definition: glext.h:8902
#define APPEND_FLAG(root, name)
Definition: bzip2.c:86
int k
Definition: mpi.c:3369

Referenced by main().

◆ applySavedFileAttrToOutputFile()

static void applySavedFileAttrToOutputFile ( IntNative  fd)
static

Definition at line 1065 of file bzip2.c.

1066 {
1067 # if BZ_UNIX
1068  IntNative retVal;
1069 
1070  retVal = fchmod ( fd, fileMetaInfo.st_mode );
1071  ERROR_IF_NOT_ZERO ( retVal );
1072 
1073  (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
1074  /* chown() will in many cases return with EPERM, which can
1075  be safely ignored.
1076  */
1077 # endif
1078 }
#define ERROR_IF_NOT_ZERO(i)
Definition: bzip2.c:60
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int IntNative
Definition: bzip2.c:176
static int fd
Definition: io.c:51
static struct MY_STAT fileMetaInfo
Definition: bzip2.c:1034

Referenced by compressStream(), and uncompressStream().

◆ applySavedTimeInfoToOutputFile()

static void applySavedTimeInfoToOutputFile ( Char dstName)
static

Definition at line 1050 of file bzip2.c.

1051 {
1052 # if BZ_UNIX
1053  IntNative retVal;
1054  struct utimbuf uTimBuf;
1055 
1056  uTimBuf.actime = fileMetaInfo.st_atime;
1057  uTimBuf.modtime = fileMetaInfo.st_mtime;
1058 
1059  retVal = utime ( dstName, &uTimBuf );
1060  ERROR_IF_NOT_ZERO ( retVal );
1061 # endif
1062 }
#define ERROR_IF_NOT_ZERO(i)
Definition: bzip2.c:60
int IntNative
Definition: bzip2.c:176
GLenum GLint GLint GLint GLint GLuint dstName
Definition: glext.h:11259
__CRT_INLINE int __cdecl utime(const char *_Filename, struct utimbuf *_Utimbuf)
Definition: utime.h:136
time_t actime
Definition: syshdrs.h:132
static struct MY_STAT fileMetaInfo
Definition: bzip2.c:1034

Referenced by compress(), and uncompress().

◆ cadvise()

static void cadvise ( void  )
static

Definition at line 659 of file bzip2.c.

660 {
661  if (noisy)
662  fprintf (
663  stderr,
664  "\nIt is possible that the compressed file(s) have become corrupted.\n"
665  "You can use the -tvv option to test integrity of such files.\n\n"
666  "You can use the `bzip2recover' program to attempt to recover\n"
667  "data from undamaged sections of corrupted files.\n\n"
668  );
669 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
FILE * stderr
Bool noisy
Definition: bzip2.c:185

Referenced by compressedStreamEOF(), crcError(), and mySIGSEGVorSIGBUScatcher().

◆ cleanUpAndFail()

static void cleanUpAndFail ( Int32  ec)
static

Definition at line 687 of file bzip2.c.

688 {
689  IntNative retVal;
690  struct MY_STAT statBuf;
691 
692  if ( srcMode == SM_F2F
693  && opMode != OM_TEST
695 
696  /* Check whether input file still exists. Delete output file
697  only if input exists to avoid loss of data. Joerg Prante, 5
698  January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean
699  this is less likely to happen. But to be ultra-paranoid, we
700  do the check anyway.) */
701  retVal = MY_STAT ( inName, &statBuf );
702  if (retVal == 0) {
703  if (noisy)
704  fprintf ( stderr,
705  "%s: Deleting output file %s, if it exists.\n",
706  progName, outName );
709  retVal = remove ( outName );
710  if (retVal != 0)
711  fprintf ( stderr,
712  "%s: WARNING: deletion of output file "
713  "(apparently) failed.\n",
714  progName );
715  } else {
716  fprintf ( stderr,
717  "%s: WARNING: deletion of output file suppressed\n",
718  progName );
719  fprintf ( stderr,
720  "%s: since input file no longer exists. Output file\n",
721  progName );
722  fprintf ( stderr,
723  "%s: `%s' may be incomplete.\n",
724  progName, outName );
725  fprintf ( stderr,
726  "%s: I suggest doing an integrity test (bzip2 -tv)"
727  " of it.\n",
728  progName );
729  }
730  }
731 
733  fprintf ( stderr,
734  "%s: WARNING: some files have not been processed:\n"
735  "%s: %d specified on command line, %d not processed yet.\n\n",
738  }
739  setExit(ec);
740  exit(exitValue);
741 }
Int32 opMode
Definition: bzip2.c:199
Bool deleteOutputOnInterrupt
Definition: bzip2.c:184
Int32 srcMode
Definition: bzip2.c:200
int IntNative
Definition: bzip2.c:176
FILE * outputHandleJustInCase
Definition: bzip2.c:210
#define OM_TEST
Definition: bzip2.c:197
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
Int32 numFilesProcessed
Definition: bzip2.c:186
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
#define MY_STAT
Definition: bzip2.c:79
#define SM_F2F
Definition: bzip2.c:192
Char * progName
Definition: bzip2.c:208
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
Int32 exitValue
Definition: bzip2.c:187
Int32 numFileNames
Definition: bzip2.c:186
Char outName[FILE_NAME_LEN]
Definition: bzip2.c:206
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
int remove
Definition: msacm.c:1353
Bool noisy
Definition: bzip2.c:185
static void setExit(Int32 v)
Definition: bzip2.c:651

Referenced by compressedStreamEOF(), crcError(), ioError(), mySignalCatcher(), mySIGSEGVorSIGBUScatcher(), and outOfMemory().

◆ compress()

static void compress ( Char name)
static

Definition at line 1133 of file bzip2.c.

1134 {
1135  FILE *inStr;
1136  FILE *outStr;
1137  Int32 n, i;
1138  struct MY_STAT statBuf;
1139 
1141 
1142  if (name == NULL && srcMode != SM_I2O)
1143  panic ( "compress: bad modes\n" );
1144 
1145  switch (srcMode) {
1146  case SM_I2O:
1147  copyFileName ( inName, (Char*)"(stdin)" );
1148  copyFileName ( outName, (Char*)"(stdout)" );
1149  break;
1150  case SM_F2F:
1151  copyFileName ( inName, name );
1152  copyFileName ( outName, name );
1153  strcat ( outName, ".bz2" );
1154  break;
1155  case SM_F2O:
1156  copyFileName ( inName, name );
1157  copyFileName ( outName, (Char*)"(stdout)" );
1158  break;
1159  }
1160 
1161  if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
1162  if (noisy)
1163  fprintf ( stderr, "%s: There are no files matching `%s'.\n",
1164  progName, inName );
1165  setExit(1);
1166  return;
1167  }
1168  if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
1169  fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
1171  setExit(1);
1172  return;
1173  }
1174  for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
1175  if (hasSuffix(inName, zSuffix[i])) {
1176  if (noisy)
1177  fprintf ( stderr,
1178  "%s: Input file %s already has %s suffix.\n",
1179  progName, inName, zSuffix[i] );
1180  setExit(1);
1181  return;
1182  }
1183  }
1184  if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
1185  MY_STAT(inName, &statBuf);
1186  if ( MY_S_ISDIR(statBuf.st_mode) ) {
1187  fprintf( stderr,
1188  "%s: Input file %s is a directory.\n",
1189  progName,inName);
1190  setExit(1);
1191  return;
1192  }
1193  }
1194  if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
1195  if (noisy)
1196  fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
1197  progName, inName );
1198  setExit(1);
1199  return;
1200  }
1201  if ( srcMode == SM_F2F && fileExists ( outName ) ) {
1202  if (forceOverwrite) {
1203  remove(outName);
1204  } else {
1205  fprintf ( stderr, "%s: Output file %s already exists.\n",
1206  progName, outName );
1207  setExit(1);
1208  return;
1209  }
1210  }
1211  if ( srcMode == SM_F2F && !forceOverwrite &&
1212  (n=countHardLinks ( inName )) > 0) {
1213  fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
1214  progName, inName, n, n > 1 ? "s" : "" );
1215  setExit(1);
1216  return;
1217  }
1218 
1219  if ( srcMode == SM_F2F ) {
1220  /* Save the file's meta-info before we open it. Doing it later
1221  means we mess up the access times. */
1223  }
1224 
1225  switch ( srcMode ) {
1226 
1227  case SM_I2O:
1228  inStr = stdin;
1229  outStr = stdout;
1230  if ( isatty ( fileno ( stdout ) ) ) {
1231  fprintf ( stderr,
1232  "%s: I won't write compressed data to a terminal.\n",
1233  progName );
1234  fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
1235  progName, progName );
1236  setExit(1);
1237  return;
1238  };
1239  break;
1240 
1241  case SM_F2O:
1242  inStr = fopen ( inName, "rb" );
1243  outStr = stdout;
1244  if ( isatty ( fileno ( stdout ) ) ) {
1245  fprintf ( stderr,
1246  "%s: I won't write compressed data to a terminal.\n",
1247  progName );
1248  fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
1249  progName, progName );
1250  if ( inStr != NULL ) fclose ( inStr );
1251  setExit(1);
1252  return;
1253  };
1254  if ( inStr == NULL ) {
1255  fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
1257  setExit(1);
1258  return;
1259  };
1260  break;
1261 
1262  case SM_F2F:
1263  inStr = fopen ( inName, "rb" );
1264  outStr = fopen_output_safely ( outName, "wb" );
1265  if ( outStr == NULL) {
1266  fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
1268  if ( inStr != NULL ) fclose ( inStr );
1269  setExit(1);
1270  return;
1271  }
1272  if ( inStr == NULL ) {
1273  fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
1275  if ( outStr != NULL ) fclose ( outStr );
1276  setExit(1);
1277  return;
1278  };
1279  break;
1280 
1281  default:
1282  panic ( "compress: bad srcMode" );
1283  break;
1284  }
1285 
1286  if (verbosity >= 1) {
1287  fprintf ( stderr, " %s: ", inName );
1288  pad ( inName );
1289  fflush ( stderr );
1290  }
1291 
1292  /*--- Now the input and output handles are sane. Do the Biz. ---*/
1293  outputHandleJustInCase = outStr;
1295  compressStream ( inStr, outStr );
1297 
1298  /*--- If there was an I/O error, we won't get here. ---*/
1299  if ( srcMode == SM_F2F ) {
1302  if ( !keepInputFiles ) {
1303  IntNative retVal = remove ( inName );
1304  ERROR_IF_NOT_ZERO ( retVal );
1305  }
1306  }
1307 
1309 }
static Bool containsDubiousChars(Char *name)
Definition: bzip2.c:1083
#define ERROR_IF_NOT_ZERO(i)
Definition: bzip2.c:60
static FILE * fopen_output_safely(Char *name, const char *mode)
Definition: bzip2.c:960
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
Bool deleteOutputOnInterrupt
Definition: bzip2.c:184
Int32 srcMode
Definition: bzip2.c:200
#define SM_I2O
Definition: bzip2.c:190
int IntNative
Definition: bzip2.c:176
GLdouble n
Definition: glext.h:7729
static void copyFileName(Char *to, Char *from)
Definition: bzip2.c:919
static Bool fileExists(Char *name)
Definition: bzip2.c:940
FILE * stdin
int errno
FILE * outputHandleJustInCase
Definition: bzip2.c:210
const char * strerror(int err)
Definition: compat_str.c:23
Bool keepInputFiles
Definition: bzip2.c:184
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
FILE * stdout
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char Char
Definition: bzip2.c:161
static Bool hasSuffix(Char *s, const Char *suffix)
Definition: bzip2.c:1110
_Check_return_ _CRTIMP int __cdecl isatty(_In_ int _FileHandle)
smooth NULL
Definition: ftsmooth.c:416
#define MY_STAT
Definition: bzip2.c:79
static Int32 countHardLinks(Char *name)
Definition: bzip2.c:998
Int32 verbosity
Definition: bzip2.c:183
#define SM_F2O
Definition: bzip2.c:191
static void pad(Char *s)
Definition: bzip2.c:908
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
#define SM_F2F
Definition: bzip2.c:192
Char * progName
Definition: bzip2.c:208
#define True
Definition: bzip2.c:169
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define BZ_N_SUFFIX_PAIRS
Definition: bzip2.c:1102
static Bool notAStandardFile(Char *name)
Definition: bzip2.c:981
static void saveInputFileMetaInfo(Char *srcName)
Definition: bzip2.c:1038
static void panic(const Char *)
Definition: bzip2.c:213
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
const Char * zSuffix[BZ_N_SUFFIX_PAIRS]
Definition: bzip2.c:1105
Char outName[FILE_NAME_LEN]
Definition: bzip2.c:206
LONG Int32
Definition: chm_lib.c:105
Definition: name.c:36
static void compressStream(FILE *stream, FILE *zStream)
Definition: bzip2.c:329
#define MY_S_ISDIR
Definition: bzip2.c:81
static void applySavedTimeInfoToOutputFile(Char *dstName)
Definition: bzip2.c:1050
FILE * stderr
#define False
Definition: bzip2.c:170
int remove
Definition: msacm.c:1353
Bool forceOverwrite
Definition: bzip2.c:185
Bool noisy
Definition: bzip2.c:185
static void setExit(Int32 v)
Definition: bzip2.c:651

Referenced by main().

◆ compressedStreamEOF()

static void compressedStreamEOF ( void  )
static

Definition at line 774 of file bzip2.c.

775 {
776  if (noisy) {
777  fprintf ( stderr,
778  "\n%s: Compressed file ends unexpectedly;\n\t"
779  "perhaps it is corrupted? *Possible* reason follows.\n",
780  progName );
781  perror ( progName );
782  showFileNames();
783  cadvise();
784  }
785  cleanUpAndFail( 2 );
786 }
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
static void cadvise(void)
Definition: bzip2.c:659
static void showFileNames(void)
Definition: bzip2.c:674
static void cleanUpAndFail(Int32 ec)
Definition: bzip2.c:687
FILE * stderr
Bool noisy
Definition: bzip2.c:185

Referenced by uncompressStream().

◆ compressStream()

static void compressStream ( FILE stream,
FILE zStream 
)
static

Definition at line 329 of file bzip2.c.

330 {
331  BZFILE* bzf = NULL;
332  UChar ibuf[5000];
333  Int32 nIbuf;
334  UInt32 nbytes_in_lo32, nbytes_in_hi32;
335  UInt32 nbytes_out_lo32, nbytes_out_hi32;
336  Int32 bzerr, bzerr_dummy, ret;
337 
339  SET_BINARY_MODE(zStream);
340 
341  if (ferror(stream)) goto errhandler_io;
342  if (ferror(zStream)) goto errhandler_io;
343 
344  bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
346  if (bzerr != BZ_OK) goto errhandler;
347 
348  if (verbosity >= 2) fprintf ( stderr, "\n" );
349 
350  while (True) {
351 
352  if (myfeof(stream)) break;
353  nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
354  if (ferror(stream)) goto errhandler_io;
355  if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
356  if (bzerr != BZ_OK) goto errhandler;
357 
358  }
359 
360  BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
361  &nbytes_in_lo32, &nbytes_in_hi32,
362  &nbytes_out_lo32, &nbytes_out_hi32 );
363  if (bzerr != BZ_OK) goto errhandler;
364 
365  if (ferror(zStream)) goto errhandler_io;
366  ret = fflush ( zStream );
367  if (ret == EOF) goto errhandler_io;
368  if (zStream != stdout) {
369  Int32 fd = fileno ( zStream );
370  if (fd < 0) goto errhandler_io;
372  ret = fclose ( zStream );
374  if (ret == EOF) goto errhandler_io;
375  }
377  if (ferror(stream)) goto errhandler_io;
378  ret = fclose ( stream );
379  if (ret == EOF) goto errhandler_io;
380 
381  if (verbosity >= 1) {
382  if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
383  fprintf ( stderr, " no data compressed.\n");
384  } else {
385  Char buf_nin[32], buf_nout[32];
386  UInt64 nbytes_in, nbytes_out;
387  double nbytes_in_d, nbytes_out_d;
388  uInt64_from_UInt32s ( &nbytes_in,
389  nbytes_in_lo32, nbytes_in_hi32 );
390  uInt64_from_UInt32s ( &nbytes_out,
391  nbytes_out_lo32, nbytes_out_hi32 );
392  nbytes_in_d = uInt64_to_double ( &nbytes_in );
393  nbytes_out_d = uInt64_to_double ( &nbytes_out );
394  uInt64_toAscii ( buf_nin, &nbytes_in );
395  uInt64_toAscii ( buf_nout, &nbytes_out );
396  fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
397  "%5.2f%% saved, %s in, %s out.\n",
398  nbytes_in_d / nbytes_out_d,
399  (8.0 * nbytes_out_d) / nbytes_in_d,
400  100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
401  buf_nin,
402  buf_nout
403  );
404  }
405  }
406 
407  return;
408 
409  errhandler:
410  BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
411  &nbytes_in_lo32, &nbytes_in_hi32,
412  &nbytes_out_lo32, &nbytes_out_hi32 );
413  switch (bzerr) {
414  case BZ_CONFIG_ERROR:
415  configError(); break;
416  case BZ_MEM_ERROR:
417  outOfMemory (); break;
418  case BZ_IO_ERROR:
419  errhandler_io:
420  ioError(); break;
421  default:
422  panic ( "compress:unexpected error" );
423  }
424 
425  panic ( "compress:end" );
426  /*notreached*/
427 }
void BZ_API() BZ2_bzWrite(int *bzerror, BZFILE *b, void *buf, int len)
Definition: bzlib.c:980
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define BZ_MEM_ERROR
Definition: bzlib.h:40
static Bool myfeof(FILE *f)
Definition: bzip2.c:318
DWORD UInt32
Definition: chm_lib.c:106
#define SET_BINARY_MODE(fd)
Definition: bzip2.c:89
static void applySavedFileAttrToOutputFile(IntNative fd)
Definition: bzip2.c:1065
ULONGLONG UInt64
Definition: chm_lib.c:108
Int32 workFactor
Definition: bzip2.c:211
static int fd
Definition: io.c:51
Int32 blockSize100k
Definition: bzip2.c:186
BYTE UChar
Definition: chm_lib.c:102
FILE * outputHandleJustInCase
Definition: bzip2.c:210
FILE * stdout
BZFILE *BZ_API() BZ2_bzWriteOpen(int *bzerror, FILE *f, int blockSize100k, int verbosity, int workFactor)
Definition: bzlib.c:932
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char Char
Definition: bzip2.c:161
smooth NULL
Definition: ftsmooth.c:416
static void ioError(void)
Definition: bzip2.c:791
#define BZ_OK
Definition: bzlib.h:33
Int32 verbosity
Definition: bzip2.c:183
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
void BZ_API() BZ2_bzWriteClose64(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in_lo32, unsigned int *nbytes_in_hi32, unsigned int *nbytes_out_lo32, unsigned int *nbytes_out_hi32)
Definition: bzlib.c:1037
#define True
Definition: bzip2.c:169
static void outOfMemory(void)
Definition: bzip2.c:872
#define BZ_CONFIG_ERROR
Definition: bzlib.h:46
int ret
static void uInt64_toAscii(char *outbuf, UInt64 *n)
Definition: bzip2.c:295
Definition: parse.h:22
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static double uInt64_to_double(UInt64 *n)
Definition: bzip2.c:252
static void panic(const Char *)
Definition: bzip2.c:213
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
#define BZ_IO_ERROR
Definition: bzlib.h:43
FILE * stderr
static void uInt64_from_UInt32s(UInt64 *n, UInt32 lo32, UInt32 hi32)
Definition: bzip2.c:238
static void configError(void)
Definition: bzip2.c:884

Referenced by compress().

◆ configError()

static void configError ( void  )
static

Definition at line 884 of file bzip2.c.

885 {
886  fprintf ( stderr,
887  "bzip2: I'm not configured correctly for this platform!\n"
888  "\tI require Int32, Int16 and Char to have sizes\n"
889  "\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
890  "\tProbably you can fix this by defining them correctly,\n"
891  "\tand recompiling. Bye!\n" );
892  setExit(3);
893  exit(exitValue);
894 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Int32 exitValue
Definition: bzip2.c:187
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
static void setExit(Int32 v)
Definition: bzip2.c:651

Referenced by compressStream(), main(), testStream(), and uncompressStream().

◆ containsDubiousChars()

static Bool containsDubiousChars ( Char name)
static

Definition at line 1083 of file bzip2.c.

1084 {
1085 # if BZ_UNIX
1086  /* On unix, files can contain any characters and the file expansion
1087  * is performed by the shell.
1088  */
1089  return False;
1090 # else /* ! BZ_UNIX */
1091  /* On non-unix (Win* platforms), wildcard characters are not allowed in
1092  * filenames.
1093  */
1094  for (; *name != '\0'; name++)
1095  if (*name == '?' || *name == '*') return True;
1096  return False;
1097 # endif /* BZ_UNIX */
1098 }
#define True
Definition: bzip2.c:169
Definition: name.c:36
#define False
Definition: bzip2.c:170

Referenced by compress(), testf(), and uncompress().

◆ copyFileName()

static void copyFileName ( Char to,
Char from 
)
static

Definition at line 919 of file bzip2.c.

920 {
921  if ( strlen(from) > FILE_NAME_LEN-10 ) {
922  fprintf (
923  stderr,
924  "bzip2: file name\n`%s'\n"
925  "is suspiciously (more than %d chars) long.\n"
926  "Try using a reasonable file name instead. Sorry! :-)\n",
927  from, FILE_NAME_LEN-10
928  );
929  setExit(1);
930  exit(exitValue);
931  }
932 
933  strncpy(to,from,FILE_NAME_LEN-10);
934  to[FILE_NAME_LEN-10]='\0';
935 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Int32 exitValue
Definition: bzip2.c:187
#define FILE_NAME_LEN
Definition: bzip2.c:202
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
CardRegion * from
Definition: spigame.cpp:19
static void setExit(Int32 v)
Definition: bzip2.c:651

Referenced by compress(), main(), testf(), and uncompress().

◆ countHardLinks()

static Int32 countHardLinks ( Char name)
static

Definition at line 998 of file bzip2.c.

999 {
1000  IntNative i;
1001  struct MY_STAT statBuf;
1002 
1003  i = MY_LSTAT ( name, &statBuf );
1004  if (i != 0) return 0;
1005  return (statBuf.st_nlink - 1);
1006 }
#define MY_LSTAT
Definition: bzip2.c:78
int IntNative
Definition: bzip2.c:176
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MY_STAT
Definition: bzip2.c:79
Definition: name.c:36

Referenced by compress(), and uncompress().

◆ crcError()

static void crcError ( void  )
static

Definition at line 761 of file bzip2.c.

762 {
763  fprintf ( stderr,
764  "\n%s: Data integrity error when decompressing.\n",
765  progName );
766  showFileNames();
767  cadvise();
768  cleanUpAndFail( 2 );
769 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
static void cadvise(void)
Definition: bzip2.c:659
static void showFileNames(void)
Definition: bzip2.c:674
static void cleanUpAndFail(Int32 ec)
Definition: bzip2.c:687
FILE * stderr

Referenced by uncompressStream().

◆ fileExists()

static Bool fileExists ( Char name)
static

Definition at line 940 of file bzip2.c.

941 {
942  FILE *tmp = fopen ( name, "rb" );
943  Bool exists = (tmp != NULL);
944  if (tmp != NULL) fclose ( tmp );
945  return exists;
946 }
smooth NULL
Definition: ftsmooth.c:416
unsigned char Bool
Definition: bzip2.c:162
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
Definition: name.c:36

Referenced by compress(), testf(), and uncompress().

◆ fopen_output_safely()

static FILE* fopen_output_safely ( Char name,
const char mode 
)
static

Definition at line 960 of file bzip2.c.

961 {
962 # if BZ_UNIX
963  FILE* fp;
964  IntNative fh;
966  if (fh == -1) return NULL;
967  fp = fdopen(fh, mode);
968  if (fp == NULL) close(fh);
969  return fp;
970 # else
971  return fopen(name, mode);
972 # endif
973 }
#define open
Definition: acwin.h:95
int IntNative
Definition: bzip2.c:176
#define O_WRONLY
Definition: acwin.h:111
smooth NULL
Definition: ftsmooth.c:416
#define O_EXCL
Definition: fcntl.h:40
#define S_IWUSR
Definition: propsheet.h:33
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define close
Definition: acwin.h:98
GLenum mode
Definition: glext.h:6217
#define S_IRUSR
Definition: propsheet.h:29
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
Definition: name.c:36
#define O_CREAT
Definition: acwin.h:110

Referenced by compress(), and uncompress().

◆ hasSuffix()

static Bool hasSuffix ( Char s,
const Char suffix 
)
static

Definition at line 1110 of file bzip2.c.

1111 {
1112  Int32 ns = strlen(s);
1113  Int32 nx = strlen(suffix);
1114  if (ns < nx) return False;
1115  if (strcmp(s + ns - nx, suffix) == 0) return True;
1116  return False;
1117 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define True
Definition: bzip2.c:169
Definition: mxnamespace.c:44
GLdouble s
Definition: gl.h:2039
GLfloat GLfloat GLfloat GLfloat nx
Definition: glext.h:8898
LONG Int32
Definition: chm_lib.c:105
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define False
Definition: bzip2.c:170

Referenced by compress(), and mapSuffix().

◆ ioError()

static void ioError ( void  )
static

Definition at line 791 of file bzip2.c.

792 {
793  fprintf ( stderr,
794  "\n%s: I/O or other error, bailing out. "
795  "Possible reason follows.\n",
796  progName );
797  perror ( progName );
798  showFileNames();
799  cleanUpAndFail( 1 );
800 }
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
static void showFileNames(void)
Definition: bzip2.c:674
static void cleanUpAndFail(Int32 ec)
Definition: bzip2.c:687
FILE * stderr

Referenced by compressStream(), testStream(), and uncompressStream().

◆ license()

static void license ( void  )
static

Definition at line 1601 of file bzip2.c.

1602 {
1603  fprintf ( stderr,
1604 
1605  "bzip2, a block-sorting file compressor. "
1606  "Version %s.\n"
1607  " \n"
1608  " Copyright (C) 1996-2010 by Julian Seward.\n"
1609  " \n"
1610  " This program is free software; you can redistribute it and/or modify\n"
1611  " it under the terms set out in the LICENSE file, which is included\n"
1612  " in the bzip2-1.0.6 source distribution.\n"
1613  " \n"
1614  " This program is distributed in the hope that it will be useful,\n"
1615  " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1616  " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1617  " LICENSE file for more details.\n"
1618  " \n",
1620  );
1621 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
const char *BZ_API() BZ2_bzlibVersion(void)
Definition: bzlib.c:1383
FILE * stderr

Referenced by main().

◆ main()

IntNative main ( IntNative argc  ,
Char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 1776 of file bzip2.c.

1777 {
1778  Int32 i, j;
1779  Char *tmp;
1780  Cell *argList;
1781  Cell *aa;
1782  Bool decode;
1783 
1784  /*-- Be really really really paranoid :-) --*/
1785  if (sizeof(Int32) != 4 || sizeof(UInt32) != 4 ||
1786  sizeof(Int16) != 2 || sizeof(UInt16) != 2 ||
1787  sizeof(Char) != 1 || sizeof(UChar) != 1)
1788  configError();
1789 
1790  /*-- Initialise --*/
1792  smallMode = False;
1795  noisy = True;
1796  verbosity = 0;
1797  blockSize100k = 9;
1799  unzFailsExist = False;
1800  numFileNames = 0;
1801  numFilesProcessed = 0;
1802  workFactor = 30;
1804  exitValue = 0;
1805  i = j = 0; /* avoid bogus warning from egcs-1.1.X */
1806 
1807  /*-- Set up signal handlers for mem access errors --*/
1809 # if BZ_UNIX
1810 # ifndef __DJGPP__
1812 # endif
1813 # endif
1814 
1815  copyFileName ( inName, (Char*)"(none)" );
1816  copyFileName ( outName, (Char*)"(none)" );
1817 
1819  progName = &progNameReally[0];
1820  for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
1821  if (*tmp == PATH_SEP) progName = tmp + 1;
1822 
1823 
1824  /*-- Copy flags from env var BZIP2, and
1825  expand filename wildcards in arg list.
1826  --*/
1827  argList = NULL;
1828  addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
1829  addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
1830  for (i = 1; i <= argc-1; i++)
1831  APPEND_FILESPEC(argList, argv[i]);
1832 
1833 
1834  /*-- Find the length of the longest filename --*/
1835  longestFileName = 7;
1836  numFileNames = 0;
1837  decode = True;
1838  for (aa = argList; aa != NULL; aa = aa->link) {
1839  if (ISFLAG("--")) { decode = False; continue; }
1840  if (aa->name[0] == '-' && decode) continue;
1841  numFileNames++;
1842  if (longestFileName < (Int32)strlen(aa->name) )
1843  longestFileName = (Int32)strlen(aa->name);
1844  }
1845 
1846 
1847  /*-- Determine source modes; flag handling may change this too. --*/
1848  if (numFileNames == 0)
1849  srcMode = SM_I2O; else srcMode = SM_F2F;
1850 
1851 
1852  /*-- Determine what to do (compress/uncompress/test/cat). --*/
1853  /*-- Note that subsequent flag handling may change this. --*/
1854  opMode = OM_Z;
1855 
1856  if ( (strstr ( progName, "unzip" ) != 0) ||
1857  (strstr ( progName, "UNZIP" ) != 0) )
1858  opMode = OM_UNZ;
1859 
1860  if ( (strstr ( progName, "z2cat" ) != 0) ||
1861  (strstr ( progName, "Z2CAT" ) != 0) ||
1862  (strstr ( progName, "zcat" ) != 0) ||
1863  (strstr ( progName, "ZCAT" ) != 0) ) {
1864  opMode = OM_UNZ;
1865  srcMode = (numFileNames == 0) ? SM_I2O : SM_F2O;
1866  }
1867 
1868 
1869  /*-- Look at the flags. --*/
1870  for (aa = argList; aa != NULL; aa = aa->link) {
1871  if (ISFLAG("--")) break;
1872  if (aa->name[0] == '-' && aa->name[1] != '-') {
1873  for (j = 1; aa->name[j] != '\0'; j++) {
1874  switch (aa->name[j]) {
1875  case 'c': srcMode = SM_F2O; break;
1876  case 'd': opMode = OM_UNZ; break;
1877  case 'z': opMode = OM_Z; break;
1878  case 'f': forceOverwrite = True; break;
1879  case 't': opMode = OM_TEST; break;
1880  case 'k': keepInputFiles = True; break;
1881  case 's': smallMode = True; break;
1882  case 'q': noisy = False; break;
1883  case '1': blockSize100k = 1; break;
1884  case '2': blockSize100k = 2; break;
1885  case '3': blockSize100k = 3; break;
1886  case '4': blockSize100k = 4; break;
1887  case '5': blockSize100k = 5; break;
1888  case '6': blockSize100k = 6; break;
1889  case '7': blockSize100k = 7; break;
1890  case '8': blockSize100k = 8; break;
1891  case '9': blockSize100k = 9; break;
1892  case 'V':
1893  case 'L': license(); break;
1894  case 'v': verbosity++; break;
1895  case 'h': usage ( progName );
1896  exit ( 0 );
1897  break;
1898  default: fprintf ( stderr, "%s: Bad flag `%s'\n",
1899  progName, aa->name );
1900  usage ( progName );
1901  exit ( 1 );
1902  break;
1903  }
1904  }
1905  }
1906  }
1907 
1908  /*-- And again ... --*/
1909  for (aa = argList; aa != NULL; aa = aa->link) {
1910  if (ISFLAG("--")) break;
1911  if (ISFLAG("--stdout")) srcMode = SM_F2O; else
1912  if (ISFLAG("--decompress")) opMode = OM_UNZ; else
1913  if (ISFLAG("--compress")) opMode = OM_Z; else
1914  if (ISFLAG("--force")) forceOverwrite = True; else
1915  if (ISFLAG("--test")) opMode = OM_TEST; else
1916  if (ISFLAG("--keep")) keepInputFiles = True; else
1917  if (ISFLAG("--small")) smallMode = True; else
1918  if (ISFLAG("--quiet")) noisy = False; else
1919  if (ISFLAG("--version")) license(); else
1920  if (ISFLAG("--license")) license(); else
1921  if (ISFLAG("--exponential")) workFactor = 1; else
1922  if (ISFLAG("--repetitive-best")) redundant(aa->name); else
1923  if (ISFLAG("--repetitive-fast")) redundant(aa->name); else
1924  if (ISFLAG("--fast")) blockSize100k = 1; else
1925  if (ISFLAG("--best")) blockSize100k = 9; else
1926  if (ISFLAG("--verbose")) verbosity++; else
1927  if (ISFLAG("--help")) { usage ( progName ); exit ( 0 ); }
1928  else
1929  if (strncmp ( aa->name, "--", 2) == 0) {
1930  fprintf ( stderr, "%s: Bad flag `%s'\n", progName, aa->name );
1931  usage ( progName );
1932  exit ( 1 );
1933  }
1934  }
1935 
1936  if (verbosity > 4) verbosity = 4;
1937  if (opMode == OM_Z && smallMode && blockSize100k > 2)
1938  blockSize100k = 2;
1939 
1940  if (opMode == OM_TEST && srcMode == SM_F2O) {
1941  fprintf ( stderr, "%s: -c and -t cannot be used together.\n",
1942  progName );
1943  exit ( 1 );
1944  }
1945 
1946  if (srcMode == SM_F2O && numFileNames == 0)
1947  srcMode = SM_I2O;
1948 
1949  if (opMode != OM_Z) blockSize100k = 0;
1950 
1951  if (srcMode == SM_F2F) {
1954 # if BZ_UNIX
1956 # endif
1957  }
1958 
1959  if (opMode == OM_Z) {
1960  if (srcMode == SM_I2O) {
1961  compress ( NULL );
1962  } else {
1963  decode = True;
1964  for (aa = argList; aa != NULL; aa = aa->link) {
1965  if (ISFLAG("--")) { decode = False; continue; }
1966  if (aa->name[0] == '-' && decode) continue;
1968  compress ( aa->name );
1969  }
1970  }
1971  }
1972  else
1973 
1974  if (opMode == OM_UNZ) {
1975  unzFailsExist = False;
1976  if (srcMode == SM_I2O) {
1977  uncompress ( NULL );
1978  } else {
1979  decode = True;
1980  for (aa = argList; aa != NULL; aa = aa->link) {
1981  if (ISFLAG("--")) { decode = False; continue; }
1982  if (aa->name[0] == '-' && decode) continue;
1984  uncompress ( aa->name );
1985  }
1986  }
1987  if (unzFailsExist) {
1988  setExit(2);
1989  exit(exitValue);
1990  }
1991  }
1992 
1993  else {
1995  if (srcMode == SM_I2O) {
1996  testf ( NULL );
1997  } else {
1998  decode = True;
1999  for (aa = argList; aa != NULL; aa = aa->link) {
2000  if (ISFLAG("--")) { decode = False; continue; }
2001  if (aa->name[0] == '-' && decode) continue;
2003  testf ( aa->name );
2004  }
2005  }
2006  if (testFailsExist && noisy) {
2007  fprintf ( stderr,
2008  "\n"
2009  "You can use the `bzip2recover' program to attempt to recover\n"
2010  "data from undamaged sections of corrupted files.\n\n"
2011  );
2012  setExit(2);
2013  exit(exitValue);
2014  }
2015  }
2016 
2017  /* Free the argument list memory to mollify leak detectors
2018  (eg) Purify, Checker. Serves no other useful purpose.
2019  */
2020  aa = argList;
2021  while (aa != NULL) {
2022  Cell* aa2 = aa->link;
2023  if (aa->name != NULL) free(aa->name);
2024  free(aa);
2025  aa = aa2;
2026  }
2027 
2028  return exitValue;
2029 }
static int argc
Definition: ServiceArgs.c:12
Int32 opMode
Definition: bzip2.c:199
Bool testFailsExist
Definition: bzip2.c:185
Bool deleteOutputOnInterrupt
Definition: bzip2.c:184
static void uncompress(Char *name)
Definition: bzip2.c:1314
Char progNameReally[FILE_NAME_LEN]
Definition: bzip2.c:209
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Int32 srcMode
Definition: bzip2.c:200
#define SM_I2O
Definition: bzip2.c:190
DWORD UInt32
Definition: chm_lib.c:106
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
struct zzzz * link
Definition: bzip2.c:1697
#define free
Definition: debug_ros.c:5
#define OM_UNZ
Definition: bzip2.c:196
static void copyFileName(Char *to, Char *from)
Definition: bzip2.c:919
Int32 workFactor
Definition: bzip2.c:211
#define OM_Z
Definition: bzip2.c:195
Int32 blockSize100k
Definition: bzip2.c:186
BYTE UChar
Definition: chm_lib.c:102
#define SIGINT
Definition: signal.h:23
USHORT UInt16
Definition: chm_lib.c:104
static void usage(Char *fullProgName)
Definition: bzip2.c:1626
FILE * outputHandleJustInCase
Definition: bzip2.c:210
#define OM_TEST
Definition: bzip2.c:197
#define argv
Definition: mplay32.c:18
Bool keepInputFiles
Definition: bzip2.c:184
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
Int32 numFilesProcessed
Definition: bzip2.c:186
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void license(void)
Definition: bzip2.c:1601
#define APPEND_FILESPEC(root, name)
Definition: bzip2.c:83
static void addFlagsFromEnvVar(Cell **argList, Char *varName)
Definition: bzip2.c:1747
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char Char
Definition: bzip2.c:161
static void compress(Char *name)
Definition: bzip2.c:1133
#define PATH_SEP
Definition: bzip2.c:77
smooth NULL
Definition: ftsmooth.c:416
unsigned char Bool
Definition: bzip2.c:162
Int32 verbosity
Definition: bzip2.c:183
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
Bool unzFailsExist
Definition: bzip2.c:185
Bool smallMode
Definition: bzip2.c:184
#define SM_F2O
Definition: bzip2.c:191
#define SIGBUS
Definition: signal.h:32
Char * name
Definition: bzip2.c:1696
Definition: bzip2.c:1694
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define SM_F2F
Definition: bzip2.c:192
static void mySIGSEGVorSIGBUScatcher(IntNative n)
Definition: bzip2.c:816
Char * progName
Definition: bzip2.c:208
#define True
Definition: bzip2.c:169
int signal
Definition: xcptfil.c:12
static void redundant(Char *flag)
Definition: bzip2.c:1670
#define SIGSEGV
Definition: signal.h:33
#define SIGTERM
Definition: signal.h:39
static BYTE decode(char c)
Definition: base64_codec.c:97
Int32 exitValue
Definition: bzip2.c:187
Int32 numFileNames
Definition: bzip2.c:186
static void mySignalCatcher(IntNative n)
Definition: bzip2.c:805
SHORT Int16
Definition: chm_lib.c:103
static void testf(Char *name)
Definition: bzip2.c:1512
Char outName[FILE_NAME_LEN]
Definition: bzip2.c:206
LONG Int32
Definition: chm_lib.c:105
Int32 longestFileName
Definition: bzip2.c:204
int Int32
Definition: bzip2.c:164
FILE * stderr
#define False
Definition: bzip2.c:170
#define SIGHUP
Definition: signal.h:22
void exit(int exitcode)
Definition: _exit.c:33
Bool forceOverwrite
Definition: bzip2.c:185
#define ISFLAG(s)
Definition: bzip2.c:1774
Bool noisy
Definition: bzip2.c:185
static void setExit(Int32 v)
Definition: bzip2.c:651
static void configError(void)
Definition: bzip2.c:884

◆ mapSuffix()

static Bool mapSuffix ( Char name,
const Char oldSuffix,
const Char newSuffix 
)
static

Definition at line 1120 of file bzip2.c.

1123 {
1124  if (!hasSuffix(name,oldSuffix)) return False;
1125  name[strlen(name)-strlen(oldSuffix)] = 0;
1126  strcat ( name, newSuffix );
1127  return True;
1128 }
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static Bool hasSuffix(Char *s, const Char *suffix)
Definition: bzip2.c:1110
#define True
Definition: bzip2.c:169
Definition: name.c:36
#define False
Definition: bzip2.c:170

Referenced by uncompress().

◆ mkCell()

static Cell* mkCell ( void  )
static

Definition at line 1716 of file bzip2.c.

1717 {
1718  Cell *c;
1719 
1720  c = (Cell*) myMalloc ( sizeof ( Cell ) );
1721  c->name = NULL;
1722  c->link = NULL;
1723  return c;
1724 }
smooth NULL
Definition: ftsmooth.c:416
Definition: bzip2.c:1694
const GLubyte * c
Definition: glext.h:8905
static void * myMalloc(Int32 n)
Definition: bzip2.c:1704
#define c
Definition: ke_i.h:80

Referenced by snocString().

◆ myfeof()

static Bool myfeof ( FILE f)
static

Definition at line 318 of file bzip2.c.

319 {
320  Int32 c = fgetc ( f );
321  if (c == EOF) return True;
322  ungetc ( c, f );
323  return False;
324 }
_Check_return_opt_ _CRTIMP_ALT int __cdecl ungetc(_In_ int _Ch, _Inout_ FILE *_File)
GLfloat f
Definition: glext.h:7540
const GLubyte * c
Definition: glext.h:8905
#define True
Definition: bzip2.c:169
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
#define False
Definition: bzip2.c:170
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)

Referenced by compressStream(), testStream(), and uncompressStream().

◆ myMalloc()

static void* myMalloc ( Int32  n)
static

Definition at line 1704 of file bzip2.c.

1705 {
1706  void* p;
1707 
1708  p = malloc ( (size_t)n );
1709  if (p == NULL) outOfMemory ();
1710  return p;
1711 }
GLdouble n
Definition: glext.h:7729
smooth NULL
Definition: ftsmooth.c:416
static void outOfMemory(void)
Definition: bzip2.c:872
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by mkCell(), and snocString().

◆ mySignalCatcher()

static void mySignalCatcher ( IntNative  n)
static

Definition at line 805 of file bzip2.c.

806 {
807  fprintf ( stderr,
808  "\n%s: Control-C or similar caught, quitting.\n",
809  progName );
810  cleanUpAndFail(1);
811 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
static void cleanUpAndFail(Int32 ec)
Definition: bzip2.c:687
FILE * stderr

Referenced by main().

◆ mySIGSEGVorSIGBUScatcher()

static void mySIGSEGVorSIGBUScatcher ( IntNative  n)
static

Definition at line 816 of file bzip2.c.

817 {
818  if (opMode == OM_Z)
819  fprintf (
820  stderr,
821  "\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
822  "\n"
823  " Possible causes are (most likely first):\n"
824  " (1) This computer has unreliable memory or cache hardware\n"
825  " (a surprisingly common problem; try a different machine.)\n"
826  " (2) A bug in the compiler used to create this executable\n"
827  " (unlikely, if you didn't compile bzip2 yourself.)\n"
828  " (3) A real bug in bzip2 -- I hope this should never be the case.\n"
829  " The user's manual, Section 4.3, has more info on (1) and (2).\n"
830  " \n"
831  " If you suspect this is a bug in bzip2, or are unsure about (1)\n"
832  " or (2), feel free to report it to me at: jseward@bzip.org.\n"
833  " Section 4.3 of the user's manual describes the info a useful\n"
834  " bug report should have. If the manual is available on your\n"
835  " system, please try and read it before mailing me. If you don't\n"
836  " have the manual or can't be bothered to read it, mail me anyway.\n"
837  "\n",
838  progName );
839  else
840  fprintf (
841  stderr,
842  "\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
843  "\n"
844  " Possible causes are (most likely first):\n"
845  " (1) The compressed data is corrupted, and bzip2's usual checks\n"
846  " failed to detect this. Try bzip2 -tvv my_file.bz2.\n"
847  " (2) This computer has unreliable memory or cache hardware\n"
848  " (a surprisingly common problem; try a different machine.)\n"
849  " (3) A bug in the compiler used to create this executable\n"
850  " (unlikely, if you didn't compile bzip2 yourself.)\n"
851  " (4) A real bug in bzip2 -- I hope this should never be the case.\n"
852  " The user's manual, Section 4.3, has more info on (2) and (3).\n"
853  " \n"
854  " If you suspect this is a bug in bzip2, or are unsure about (2)\n"
855  " or (3), feel free to report it to me at: jseward@bzip.org.\n"
856  " Section 4.3 of the user's manual describes the info a useful\n"
857  " bug report should have. If the manual is available on your\n"
858  " system, please try and read it before mailing me. If you don't\n"
859  " have the manual or can't be bothered to read it, mail me anyway.\n"
860  "\n",
861  progName );
862 
863  showFileNames();
864  if (opMode == OM_Z)
865  cleanUpAndFail( 3 ); else
866  { cadvise(); cleanUpAndFail( 2 ); }
867 }
Int32 opMode
Definition: bzip2.c:199
#define OM_Z
Definition: bzip2.c:195
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
static void cadvise(void)
Definition: bzip2.c:659
static void showFileNames(void)
Definition: bzip2.c:674
static void cleanUpAndFail(Int32 ec)
Definition: bzip2.c:687
FILE * stderr

Referenced by main().

◆ notAStandardFile()

static Bool notAStandardFile ( Char name)
static

Definition at line 981 of file bzip2.c.

982 {
983  IntNative i;
984  struct MY_STAT statBuf;
985 
986  i = MY_LSTAT ( name, &statBuf );
987  if (i != 0) return True;
988  if (MY_S_ISREG(statBuf.st_mode)) return False;
989  return True;
990 }
#define MY_LSTAT
Definition: bzip2.c:78
int IntNative
Definition: bzip2.c:176
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MY_STAT
Definition: bzip2.c:79
#define MY_S_ISREG
Definition: bzip2.c:80
#define True
Definition: bzip2.c:169
Definition: name.c:36
#define False
Definition: bzip2.c:170

Referenced by compress(), and uncompress().

◆ outOfMemory()

static void outOfMemory ( void  )
static

Definition at line 872 of file bzip2.c.

873 {
874  fprintf ( stderr,
875  "\n%s: couldn't allocate enough memory\n",
876  progName );
877  showFileNames();
878  cleanUpAndFail(1);
879 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
static void showFileNames(void)
Definition: bzip2.c:674
static void cleanUpAndFail(Int32 ec)
Definition: bzip2.c:687
FILE * stderr

Referenced by compressStream(), myMalloc(), testStream(), and uncompressStream().

◆ pad()

static void pad ( Char s)
static

Definition at line 908 of file bzip2.c.

909 {
910  Int32 i;
911  if ( (Int32)strlen(s) >= longestFileName ) return;
912  for (i = 1; i <= longestFileName - (Int32)strlen(s); i++)
913  fprintf ( stderr, " " );
914 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
GLdouble s
Definition: gl.h:2039
LONG Int32
Definition: chm_lib.c:105
Int32 longestFileName
Definition: bzip2.c:204
int Int32
Definition: bzip2.c:164
FILE * stderr

Referenced by acmDriverClose(), acmDriverOpen(), acmFormatTagDetailsW(), assign_file_addresses(), compress(), CRYPT_AsnEncodeInteger(), CRYPT_AsnEncodeUnsignedInteger(), edit_with_commas(), field_format_extension_hex_with_ascii(), FT_Bitmap_Convert(), gl_fixup(), MSACM_Message(), PropertyStorage_DictionaryWriter(), PS_Conv_ASCIIHexDecode(), res_write_padding(), sec_hash_48(), sltg_write_header(), sltg_write_nametable(), sltg_write_remainder(), test_capture(), test_clock(), test_padding(), test_worst_case(), testf(), uncompress(), and VARIANT_FormatNumber().

◆ panic()

static void panic ( const Char s)
static

Definition at line 213 of file bzip2.c.

233  { UChar b[8]; }
BYTE UChar
Definition: chm_lib.c:102
GLboolean GLboolean GLboolean b
Definition: glext.h:6204

Referenced by compress(), compressStream(), testf(), testStream(), uncompress(), and uncompressStream().

◆ redundant()

static void redundant ( Char flag)
static

Definition at line 1670 of file bzip2.c.

1671 {
1672  fprintf (
1673  stderr,
1674  "%s: %s is redundant in versions 0.9.5 and above\n",
1675  progName, flag );
1676 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char * progName
Definition: bzip2.c:208
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
FILE * stderr

Referenced by main().

◆ saveInputFileMetaInfo()

static void saveInputFileMetaInfo ( Char srcName)
static

Definition at line 1038 of file bzip2.c.

1039 {
1040 # if BZ_UNIX
1041  IntNative retVal;
1042  /* Note use of stat here, not lstat. */
1043  retVal = MY_STAT( srcName, &fileMetaInfo );
1044  ERROR_IF_NOT_ZERO ( retVal );
1045 # endif
1046 }
#define ERROR_IF_NOT_ZERO(i)
Definition: bzip2.c:60
int IntNative
Definition: bzip2.c:176
#define MY_STAT
Definition: bzip2.c:79
static struct MY_STAT fileMetaInfo
Definition: bzip2.c:1034

Referenced by compress(), and uncompress().

◆ setExit()

static void setExit ( Int32  v)
static

Definition at line 651 of file bzip2.c.

652 {
653  if (v > exitValue) exitValue = v;
654 }
const GLdouble * v
Definition: gl.h:2040
Int32 exitValue
Definition: bzip2.c:187

Referenced by cleanUpAndFail(), compress(), configError(), copyFileName(), main(), testf(), and uncompress().

◆ showFileNames()

static void showFileNames ( void  )
static

Definition at line 674 of file bzip2.c.

675 {
676  if (noisy)
677  fprintf (
678  stderr,
679  "\tInput file = %s, output file = %s\n",
680  inName, outName
681  );
682 }
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Char outName[FILE_NAME_LEN]
Definition: bzip2.c:206
FILE * stderr
Bool noisy
Definition: bzip2.c:185

Referenced by compressedStreamEOF(), crcError(), ioError(), mySIGSEGVorSIGBUScatcher(), and outOfMemory().

◆ snocString()

static Cell* snocString ( Cell root,
Char name 
)
static

Definition at line 1729 of file bzip2.c.

1730 {
1731  if (root == NULL) {
1732  Cell *tmp = mkCell();
1733  tmp->name = (Char*) myMalloc ( 5 + strlen(name) );
1734  strcpy ( tmp->name, name );
1735  return tmp;
1736  } else {
1737  Cell *tmp = root;
1738  while (tmp->link != NULL) tmp = tmp->link;
1739  tmp->link = snocString ( tmp->link, name );
1740  return root;
1741  }
1742 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
struct zzzz * link
Definition: bzip2.c:1697
struct _root root
static Cell * mkCell(void)
Definition: bzip2.c:1716
char Char
Definition: bzip2.c:161
smooth NULL
Definition: ftsmooth.c:416
static Cell * snocString(Cell *root, Char *name)
Definition: bzip2.c:1729
Char * name
Definition: bzip2.c:1696
Definition: bzip2.c:1694
static void * myMalloc(Int32 n)
Definition: bzip2.c:1704
Definition: name.c:36
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388

◆ testf()

static void testf ( Char name)
static

Definition at line 1512 of file bzip2.c.

1513 {
1514  FILE *inStr;
1515  Bool allOK;
1516  struct MY_STAT statBuf;
1517 
1519 
1520  if (name == NULL && srcMode != SM_I2O)
1521  panic ( "testf: bad modes\n" );
1522 
1523  copyFileName ( outName, (Char*)"(none)" );
1524  switch (srcMode) {
1525  case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
1526  case SM_F2F: copyFileName ( inName, name ); break;
1527  case SM_F2O: copyFileName ( inName, name ); break;
1528  }
1529 
1530  if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
1531  if (noisy)
1532  fprintf ( stderr, "%s: There are no files matching `%s'.\n",
1533  progName, inName );
1534  setExit(1);
1535  return;
1536  }
1537  if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
1538  fprintf ( stderr, "%s: Can't open input %s: %s.\n",
1540  setExit(1);
1541  return;
1542  }
1543  if ( srcMode != SM_I2O ) {
1544  MY_STAT(inName, &statBuf);
1545  if ( MY_S_ISDIR(statBuf.st_mode) ) {
1546  fprintf( stderr,
1547  "%s: Input file %s is a directory.\n",
1548  progName,inName);
1549  setExit(1);
1550  return;
1551  }
1552  }
1553 
1554  switch ( srcMode ) {
1555 
1556  case SM_I2O:
1557  if ( isatty ( fileno ( stdin ) ) ) {
1558  fprintf ( stderr,
1559  "%s: I won't read compressed data from a terminal.\n",
1560  progName );
1561  fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
1562  progName, progName );
1563  setExit(1);
1564  return;
1565  };
1566  inStr = stdin;
1567  break;
1568 
1569  case SM_F2O: case SM_F2F:
1570  inStr = fopen ( inName, "rb" );
1571  if ( inStr == NULL ) {
1572  fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
1574  setExit(1);
1575  return;
1576  };
1577  break;
1578 
1579  default:
1580  panic ( "testf: bad srcMode" );
1581  break;
1582  }
1583 
1584  if (verbosity >= 1) {
1585  fprintf ( stderr, " %s: ", inName );
1586  pad ( inName );
1587  fflush ( stderr );
1588  }
1589 
1590  /*--- Now the input handle is sane. Do the Biz. ---*/
1592  allOK = testStream ( inStr );
1593 
1594  if (allOK && verbosity >= 1) fprintf ( stderr, "ok\n" );
1595  if (!allOK) testFailsExist = True;
1596 }
static Bool containsDubiousChars(Char *name)
Definition: bzip2.c:1083
Bool testFailsExist
Definition: bzip2.c:185
Bool deleteOutputOnInterrupt
Definition: bzip2.c:184
Int32 srcMode
Definition: bzip2.c:200
#define SM_I2O
Definition: bzip2.c:190
static Bool testStream(FILE *zStream)
Definition: bzip2.c:554
static void copyFileName(Char *to, Char *from)
Definition: bzip2.c:919
static Bool fileExists(Char *name)
Definition: bzip2.c:940
FILE * stdin
int errno
FILE * outputHandleJustInCase
Definition: bzip2.c:210
const char * strerror(int err)
Definition: compat_str.c:23
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char Char
Definition: bzip2.c:161
_Check_return_ _CRTIMP int __cdecl isatty(_In_ int _FileHandle)
smooth NULL
Definition: ftsmooth.c:416
#define MY_STAT
Definition: bzip2.c:79
unsigned char Bool
Definition: bzip2.c:162
Int32 verbosity
Definition: bzip2.c:183
#define SM_F2O
Definition: bzip2.c:191
static void pad(Char *s)
Definition: bzip2.c:908
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
#define SM_F2F
Definition: bzip2.c:192
Char * progName
Definition: bzip2.c:208
#define True
Definition: bzip2.c:169
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static void panic(const Char *)
Definition: bzip2.c:213
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
Char outName[FILE_NAME_LEN]
Definition: bzip2.c:206
Definition: name.c:36
#define MY_S_ISDIR
Definition: bzip2.c:81
FILE * stderr
#define False
Definition: bzip2.c:170
Bool noisy
Definition: bzip2.c:185
static void setExit(Int32 v)
Definition: bzip2.c:651

Referenced by main().

◆ testStream()

static Bool testStream ( FILE zStream)
static

Definition at line 554 of file bzip2.c.

555 {
556  BZFILE* bzf = NULL;
557  Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
558  UChar obuf[5000];
560  Int32 nUnused;
561  void* unusedTmpV;
562  UChar* unusedTmp;
563 
564  nUnused = 0;
565  streamNo = 0;
566 
567  SET_BINARY_MODE(zStream);
568  if (ferror(zStream)) goto errhandler_io;
569 
570  while (True) {
571 
572  bzf = BZ2_bzReadOpen (
573  &bzerr, zStream, verbosity,
574  (int)smallMode, unused, nUnused
575  );
576  if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
577  streamNo++;
578 
579  while (bzerr == BZ_OK) {
580  nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
581  if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
582  }
583  if (bzerr != BZ_STREAM_END) goto errhandler;
584 
585  BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
586  if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
587 
588  unusedTmp = (UChar*)unusedTmpV;
589  for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
590 
591  BZ2_bzReadClose ( &bzerr, bzf );
592  if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
593  if (nUnused == 0 && myfeof(zStream)) break;
594 
595  }
596 
597  if (ferror(zStream)) goto errhandler_io;
598  ret = fclose ( zStream );
599  if (ret == EOF) goto errhandler_io;
600 
601  if (verbosity >= 2) fprintf ( stderr, "\n " );
602  return True;
603 
604  errhandler:
605  BZ2_bzReadClose ( &bzerr_dummy, bzf );
606  if (verbosity == 0)
607  fprintf ( stderr, "%s: %s: ", progName, inName );
608  switch (bzerr) {
609  case BZ_CONFIG_ERROR:
610  configError(); break;
611  case BZ_IO_ERROR:
612  errhandler_io:
613  ioError(); break;
614  case BZ_DATA_ERROR:
615  fprintf ( stderr,
616  "data integrity (CRC) error in data\n" );
617  return False;
618  case BZ_MEM_ERROR:
619  outOfMemory();
620  case BZ_UNEXPECTED_EOF:
621  fprintf ( stderr,
622  "file ends unexpectedly\n" );
623  return False;
624  case BZ_DATA_ERROR_MAGIC:
625  if (zStream != stdin) fclose(zStream);
626  if (streamNo == 1) {
627  fprintf ( stderr,
628  "bad magic number (file not created by bzip2)\n" );
629  return False;
630  } else {
631  if (noisy)
632  fprintf ( stderr,
633  "trailing garbage after EOF ignored\n" );
634  return True;
635  }
636  default:
637  panic ( "test:unexpected error" );
638  }
639 
640  panic ( "test:end" );
641  return True; /*notreached*/
642 }
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define BZ_MEM_ERROR
Definition: bzlib.h:40
static Bool myfeof(FILE *f)
Definition: bzip2.c:318
#define BZ_DATA_ERROR_MAGIC
Definition: bzlib.h:42
#define SET_BINARY_MODE(fd)
Definition: bzip2.c:89
FILE * stdin
BYTE UChar
Definition: chm_lib.c:102
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
void BZ_API() BZ2_bzReadGetUnused(int *bzerror, BZFILE *b, void **unused, int *nUnused)
Definition: bzlib.c:1237
WORD unused[29]
Definition: crypt.c:1155
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
void BZ_API() BZ2_bzReadClose(int *bzerror, BZFILE *b)
Definition: bzlib.c:1158
smooth NULL
Definition: ftsmooth.c:416
static void ioError(void)
Definition: bzip2.c:791
#define BZ_OK
Definition: bzlib.h:33
Int32 verbosity
Definition: bzip2.c:183
Bool smallMode
Definition: bzip2.c:184
#define BZ_STREAM_END
Definition: bzlib.h:37
BZFILE *BZ_API() BZ2_bzReadOpen(int *bzerror, FILE *f, int verbosity, int small, void *unused, int nUnused)
Definition: bzlib.c:1103
int BZ_API() BZ2_bzRead(int *bzerror, BZFILE *b, void *buf, int len)
Definition: bzlib.c:1177
Char * progName
Definition: bzip2.c:208
#define True
Definition: bzip2.c:169
static void outOfMemory(void)
Definition: bzip2.c:872
#define BZ_CONFIG_ERROR
Definition: bzlib.h:46
int ret
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define BZ_DATA_ERROR
Definition: bzlib.h:41
#define BZ_UNEXPECTED_EOF
Definition: bzlib.h:44
static void panic(const Char *)
Definition: bzip2.c:213
static char obuf[100]
Definition: i386-dis.c:1266
#define BZ_MAX_UNUSED
Definition: bzlib.h:135
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
#define BZ_IO_ERROR
Definition: bzlib.h:43
FILE * stderr
#define False
Definition: bzip2.c:170
Bool noisy
Definition: bzip2.c:185
static void configError(void)
Definition: bzip2.c:884

Referenced by testf().

◆ uInt64_from_UInt32s()

static void uInt64_from_UInt32s ( UInt64 n,
UInt32  lo32,
UInt32  hi32 
)
static

Definition at line 238 of file bzip2.c.

239 {
240  n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
241  n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
242  n->b[5] = (UChar)((hi32 >> 8) & 0xFF);
243  n->b[4] = (UChar) (hi32 & 0xFF);
244  n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
245  n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
246  n->b[1] = (UChar)((lo32 >> 8) & 0xFF);
247  n->b[0] = (UChar) (lo32 & 0xFF);
248 }
unsigned char UChar
Definition: bzip2.c:163
GLdouble n
Definition: glext.h:7729

Referenced by compressStream().

◆ uInt64_isZero()

static Bool uInt64_isZero ( UInt64 n)
static

Definition at line 266 of file bzip2.c.

267 {
268  Int32 i;
269  for (i = 0; i < 8; i++)
270  if (n->b[i] != 0) return 0;
271  return 1;
272 }
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG Int32
Definition: chm_lib.c:105

Referenced by uInt64_toAscii().

◆ uInt64_qrm10()

static Int32 uInt64_qrm10 ( UInt64 n)
static

Definition at line 277 of file bzip2.c.

278 {
279  UInt32 rem, tmp;
280  Int32 i;
281  rem = 0;
282  for (i = 7; i >= 0; i--) {
283  tmp = rem * 256 + n->b[i];
284  n->b[i] = tmp / 10;
285  rem = tmp % 10;
286  }
287  return rem;
288 }
DWORD UInt32
Definition: chm_lib.c:106
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG Int32
Definition: chm_lib.c:105

Referenced by uInt64_toAscii().

◆ uInt64_to_double()

static double uInt64_to_double ( UInt64 n)
static

Definition at line 252 of file bzip2.c.

253 {
254  Int32 i;
255  double base = 1.0;
256  double sum = 0.0;
257  for (i = 0; i < 8; i++) {
258  sum += base * (double)(n->b[i]);
259  base *= 256.0;
260  }
261  return sum;
262 }
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
LONG Int32
Definition: chm_lib.c:105

Referenced by compressStream().

◆ uInt64_toAscii()

static void uInt64_toAscii ( char outbuf,
UInt64 n 
)
static

Definition at line 295 of file bzip2.c.

296 {
297  Int32 i, q;
298  UChar buf[32];
299  Int32 nBuf = 0;
300  UInt64 n_copy = *n;
301  do {
302  q = uInt64_qrm10 ( &n_copy );
303  buf[nBuf] = q + '0';
304  nBuf++;
305  } while (!uInt64_isZero(&n_copy));
306  outbuf[nBuf] = 0;
307  for (i = 0; i < nBuf; i++)
308  outbuf[i] = buf[nBuf-i-1];
309 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
ULONGLONG UInt64
Definition: chm_lib.c:108
GLdouble n
Definition: glext.h:7729
BYTE UChar
Definition: chm_lib.c:102
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static Int32 uInt64_qrm10(UInt64 *n)
Definition: bzip2.c:277
static Bool uInt64_isZero(UInt64 *n)
Definition: bzip2.c:266
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
LONG Int32
Definition: chm_lib.c:105
uchar outbuf[M_BLOCK_OUT]
Definition: unzcrash.c:41

Referenced by compressStream().

◆ uncompress()

static void uncompress ( Char name)
static

Definition at line 1314 of file bzip2.c.

1315 {
1316  FILE *inStr;
1317  FILE *outStr;
1318  Int32 n, i;
1319  Bool magicNumberOK;
1320  Bool cantGuess;
1321  struct MY_STAT statBuf;
1322 
1324 
1325  if (name == NULL && srcMode != SM_I2O)
1326  panic ( "uncompress: bad modes\n" );
1327 
1328  cantGuess = False;
1329  switch (srcMode) {
1330  case SM_I2O:
1331  copyFileName ( inName, (Char*)"(stdin)" );
1332  copyFileName ( outName, (Char*)"(stdout)" );
1333  break;
1334  case SM_F2F:
1335  copyFileName ( inName, name );
1336  copyFileName ( outName, name );
1337  for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
1339  goto zzz;
1340  cantGuess = True;
1341  strcat ( outName, ".out" );
1342  break;
1343  case SM_F2O:
1344  copyFileName ( inName, name );
1345  copyFileName ( outName, (Char*)"(stdout)" );
1346  break;
1347  }
1348 
1349  zzz:
1350  if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
1351  if (noisy)
1352  fprintf ( stderr, "%s: There are no files matching `%s'.\n",
1353  progName, inName );
1354  setExit(1);
1355  return;
1356  }
1357  if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
1358  fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
1360  setExit(1);
1361  return;
1362  }
1363  if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
1364  MY_STAT(inName, &statBuf);
1365  if ( MY_S_ISDIR(statBuf.st_mode) ) {
1366  fprintf( stderr,
1367  "%s: Input file %s is a directory.\n",
1368  progName,inName);
1369  setExit(1);
1370  return;
1371  }
1372  }
1373  if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
1374  if (noisy)
1375  fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
1376  progName, inName );
1377  setExit(1);
1378  return;
1379  }
1380  if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
1381  if (noisy)
1382  fprintf ( stderr,
1383  "%s: Can't guess original name for %s -- using %s\n",
1384  progName, inName, outName );
1385  /* just a warning, no return */
1386  }
1387  if ( srcMode == SM_F2F && fileExists ( outName ) ) {
1388  if (forceOverwrite) {
1389  remove(outName);
1390  } else {
1391  fprintf ( stderr, "%s: Output file %s already exists.\n",
1392  progName, outName );
1393  setExit(1);
1394  return;
1395  }
1396  }
1397  if ( srcMode == SM_F2F && !forceOverwrite &&
1398  (n=countHardLinks ( inName ) ) > 0) {
1399  fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
1400  progName, inName, n, n > 1 ? "s" : "" );
1401  setExit(1);
1402  return;
1403  }
1404 
1405  if ( srcMode == SM_F2F ) {
1406  /* Save the file's meta-info before we open it. Doing it later
1407  means we mess up the access times. */
1409  }
1410 
1411  switch ( srcMode ) {
1412 
1413  case SM_I2O:
1414  inStr = stdin;
1415  outStr = stdout;
1416  if ( isatty ( fileno ( stdin ) ) ) {
1417  fprintf ( stderr,
1418  "%s: I won't read compressed data from a terminal.\n",
1419  progName );
1420  fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
1421  progName, progName );
1422  setExit(1);
1423  return;
1424  };
1425  break;
1426 
1427  case SM_F2O:
1428  inStr = fopen ( inName, "rb" );
1429  outStr = stdout;
1430  if ( inStr == NULL ) {
1431  fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
1433  if ( inStr != NULL ) fclose ( inStr );
1434  setExit(1);
1435  return;
1436  };
1437  break;
1438 
1439  case SM_F2F:
1440  inStr = fopen ( inName, "rb" );
1441  outStr = fopen_output_safely ( outName, "wb" );
1442  if ( outStr == NULL) {
1443  fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
1445  if ( inStr != NULL ) fclose ( inStr );
1446  setExit(1);
1447  return;
1448  }
1449  if ( inStr == NULL ) {
1450  fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
1452  if ( outStr != NULL ) fclose ( outStr );
1453  setExit(1);
1454  return;
1455  };
1456  break;
1457 
1458  default:
1459  panic ( "uncompress: bad srcMode" );
1460  break;
1461  }
1462 
1463  if (verbosity >= 1) {
1464  fprintf ( stderr, " %s: ", inName );
1465  pad ( inName );
1466  fflush ( stderr );
1467  }
1468 
1469  /*--- Now the input and output handles are sane. Do the Biz. ---*/
1470  outputHandleJustInCase = outStr;
1472  magicNumberOK = uncompressStream ( inStr, outStr );
1474 
1475  /*--- If there was an I/O error, we won't get here. ---*/
1476  if ( magicNumberOK ) {
1477  if ( srcMode == SM_F2F ) {
1480  if ( !keepInputFiles ) {
1481  IntNative retVal = remove ( inName );
1482  ERROR_IF_NOT_ZERO ( retVal );
1483  }
1484  }
1485  } else {
1486  unzFailsExist = True;
1488  if ( srcMode == SM_F2F ) {
1489  IntNative retVal = remove ( outName );
1490  ERROR_IF_NOT_ZERO ( retVal );
1491  }
1492  }
1494 
1495  if ( magicNumberOK ) {
1496  if (verbosity >= 1)
1497  fprintf ( stderr, "done\n" );
1498  } else {
1499  setExit(2);
1500  if (verbosity >= 1)
1501  fprintf ( stderr, "not a bzip2 file.\n" ); else
1502  fprintf ( stderr,
1503  "%s: %s is not a bzip2 file.\n",
1504  progName, inName );
1505  }
1506 
1507 }
static Bool containsDubiousChars(Char *name)
Definition: bzip2.c:1083
#define ERROR_IF_NOT_ZERO(i)
Definition: bzip2.c:60
static FILE * fopen_output_safely(Char *name, const char *mode)
Definition: bzip2.c:960
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
Bool deleteOutputOnInterrupt
Definition: bzip2.c:184
Int32 srcMode
Definition: bzip2.c:200
#define SM_I2O
Definition: bzip2.c:190
int IntNative
Definition: bzip2.c:176
const Char * unzSuffix[BZ_N_SUFFIX_PAIRS]
Definition: bzip2.c:1107
GLdouble n
Definition: glext.h:7729
static void copyFileName(Char *to, Char *from)
Definition: bzip2.c:919
static Bool mapSuffix(Char *name, const Char *oldSuffix, const Char *newSuffix)
Definition: bzip2.c:1120
static Bool uncompressStream(FILE *zStream, FILE *stream)
Definition: bzip2.c:433
static Bool fileExists(Char *name)
Definition: bzip2.c:940
FILE * stdin
int errno
FILE * outputHandleJustInCase
Definition: bzip2.c:210
const char * strerror(int err)
Definition: compat_str.c:23
Bool keepInputFiles
Definition: bzip2.c:184
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
FILE * stdout
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char Char
Definition: bzip2.c:161
_Check_return_ _CRTIMP int __cdecl isatty(_In_ int _FileHandle)
smooth NULL
Definition: ftsmooth.c:416
#define MY_STAT
Definition: bzip2.c:79
static Int32 countHardLinks(Char *name)
Definition: bzip2.c:998
unsigned char Bool
Definition: bzip2.c:162
Int32 verbosity
Definition: bzip2.c:183
Bool unzFailsExist
Definition: bzip2.c:185
#define SM_F2O
Definition: bzip2.c:191
static void pad(Char *s)
Definition: bzip2.c:908
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
#define SM_F2F
Definition: bzip2.c:192
Char * progName
Definition: bzip2.c:208
#define True
Definition: bzip2.c:169
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define BZ_N_SUFFIX_PAIRS
Definition: bzip2.c:1102
static Bool notAStandardFile(Char *name)
Definition: bzip2.c:981
static void saveInputFileMetaInfo(Char *srcName)
Definition: bzip2.c:1038
static void panic(const Char *)
Definition: bzip2.c:213
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
const Char * zSuffix[BZ_N_SUFFIX_PAIRS]
Definition: bzip2.c:1105
Char outName[FILE_NAME_LEN]
Definition: bzip2.c:206
LONG Int32
Definition: chm_lib.c:105
Definition: name.c:36
#define MY_S_ISDIR
Definition: bzip2.c:81
static void applySavedTimeInfoToOutputFile(Char *dstName)
Definition: bzip2.c:1050
FILE * stderr
#define False
Definition: bzip2.c:170
int remove
Definition: msacm.c:1353
Bool forceOverwrite
Definition: bzip2.c:185
Bool noisy
Definition: bzip2.c:185
static void setExit(Int32 v)
Definition: bzip2.c:651

Referenced by main().

◆ uncompressStream()

static Bool uncompressStream ( FILE zStream,
FILE stream 
)
static

Definition at line 433 of file bzip2.c.

434 {
435  BZFILE* bzf = NULL;
436  Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
437  UChar obuf[5000];
439  Int32 nUnused;
440  void* unusedTmpV;
441  UChar* unusedTmp;
442 
443  nUnused = 0;
444  streamNo = 0;
445 
447  SET_BINARY_MODE(zStream);
448 
449  if (ferror(stream)) goto errhandler_io;
450  if (ferror(zStream)) goto errhandler_io;
451 
452  while (True) {
453 
454  bzf = BZ2_bzReadOpen (
455  &bzerr, zStream, verbosity,
456  (int)smallMode, unused, nUnused
457  );
458  if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
459  streamNo++;
460 
461  while (bzerr == BZ_OK) {
462  nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
463  if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
464  if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
465  fwrite ( obuf, sizeof(UChar), nread, stream );
466  if (ferror(stream)) goto errhandler_io;
467  }
468  if (bzerr != BZ_STREAM_END) goto errhandler;
469 
470  BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
471  if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
472 
473  unusedTmp = (UChar*)unusedTmpV;
474  for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
475 
476  BZ2_bzReadClose ( &bzerr, bzf );
477  if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
478 
479  if (nUnused == 0 && myfeof(zStream)) break;
480  }
481 
482  closeok:
483  if (ferror(zStream)) goto errhandler_io;
484  if (stream != stdout) {
485  Int32 fd = fileno ( stream );
486  if (fd < 0) goto errhandler_io;
488  }
489  ret = fclose ( zStream );
490  if (ret == EOF) goto errhandler_io;
491 
492  if (ferror(stream)) goto errhandler_io;
493  ret = fflush ( stream );
494  if (ret != 0) goto errhandler_io;
495  if (stream != stdout) {
496  ret = fclose ( stream );
498  if (ret == EOF) goto errhandler_io;
499  }
501  if (verbosity >= 2) fprintf ( stderr, "\n " );
502  return True;
503 
504  trycat:
505  if (forceOverwrite) {
506  rewind(zStream);
507  while (True) {
508  if (myfeof(zStream)) break;
509  nread = fread ( obuf, sizeof(UChar), 5000, zStream );
510  if (ferror(zStream)) goto errhandler_io;
511  if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
512  if (ferror(stream)) goto errhandler_io;
513  }
514  goto closeok;
515  }
516 
517  errhandler:
518  BZ2_bzReadClose ( &bzerr_dummy, bzf );
519  switch (bzerr) {
520  case BZ_CONFIG_ERROR:
521  configError(); break;
522  case BZ_IO_ERROR:
523  errhandler_io:
524  ioError(); break;
525  case BZ_DATA_ERROR:
526  crcError();
527  case BZ_MEM_ERROR:
528  outOfMemory();
529  case BZ_UNEXPECTED_EOF:
531  case BZ_DATA_ERROR_MAGIC:
532  if (zStream != stdin) fclose(zStream);
533  if (stream != stdout) fclose(stream);
534  if (streamNo == 1) {
535  return False;
536  } else {
537  if (noisy)
538  fprintf ( stderr,
539  "\n%s: %s: trailing garbage after EOF ignored\n",
540  progName, inName );
541  return True;
542  }
543  default:
544  panic ( "decompress:unexpected error" );
545  }
546 
547  panic ( "decompress:end" );
548  return True; /*notreached*/
549 }
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define BZ_MEM_ERROR
Definition: bzlib.h:40
static Bool myfeof(FILE *f)
Definition: bzip2.c:318
static void compressedStreamEOF(void)
Definition: bzip2.c:774
#define BZ_DATA_ERROR_MAGIC
Definition: bzlib.h:42
#define SET_BINARY_MODE(fd)
Definition: bzip2.c:89
static void applySavedFileAttrToOutputFile(IntNative fd)
Definition: bzip2.c:1065
static int fd
Definition: io.c:51
FILE * stdin
BYTE UChar
Definition: chm_lib.c:102
FILE * outputHandleJustInCase
Definition: bzip2.c:210
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
Char inName[FILE_NAME_LEN]
Definition: bzip2.c:205
FILE * stdout
void BZ_API() BZ2_bzReadGetUnused(int *bzerror, BZFILE *b, void **unused, int *nUnused)
Definition: bzlib.c:1237
WORD unused[29]
Definition: crypt.c:1155
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
void BZ_API() BZ2_bzReadClose(int *bzerror, BZFILE *b)
Definition: bzlib.c:1158
smooth NULL
Definition: ftsmooth.c:416
static void ioError(void)
Definition: bzip2.c:791
static void crcError(void)
Definition: bzip2.c:761
_CRTIMP void __cdecl rewind(_Inout_ FILE *_File)
#define BZ_OK
Definition: bzlib.h:33
Int32 verbosity
Definition: bzip2.c:183
Bool smallMode
Definition: bzip2.c:184
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
#define BZ_STREAM_END
Definition: bzlib.h:37
BZFILE *BZ_API() BZ2_bzReadOpen(int *bzerror, FILE *f, int verbosity, int small, void *unused, int nUnused)
Definition: bzlib.c:1103
int BZ_API() BZ2_bzRead(int *bzerror, BZFILE *b, void *buf, int len)
Definition: bzlib.c:1177
Char * progName
Definition: bzip2.c:208
#define True
Definition: bzip2.c:169
static void outOfMemory(void)
Definition: bzip2.c:872
#define BZ_CONFIG_ERROR
Definition: bzlib.h:46
int ret
Definition: parse.h:22
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define BZ_DATA_ERROR
Definition: bzlib.h:41
#define BZ_UNEXPECTED_EOF
Definition: bzlib.h:44
static void panic(const Char *)
Definition: bzip2.c:213
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
static char obuf[100]
Definition: i386-dis.c:1266
#define BZ_MAX_UNUSED
Definition: bzlib.h:135
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
#define BZ_IO_ERROR
Definition: bzlib.h:43
FILE * stderr
#define False
Definition: bzip2.c:170
Bool forceOverwrite
Definition: bzip2.c:185
Bool noisy
Definition: bzip2.c:185
static void configError(void)
Definition: bzip2.c:884

Referenced by uncompress().

◆ usage()

static void usage ( Char fullProgName)
static

Definition at line 1626 of file bzip2.c.

1627 {
1628  fprintf (
1629  stderr,
1630  "bzip2, a block-sorting file compressor. "
1631  "Version %s.\n"
1632  "\n usage: %s [flags and input files in any order]\n"
1633  "\n"
1634  " -h --help print this message\n"
1635  " -d --decompress force decompression\n"
1636  " -z --compress force compression\n"
1637  " -k --keep keep (don't delete) input files\n"
1638  " -f --force overwrite existing output files\n"
1639  " -t --test test compressed file integrity\n"
1640  " -c --stdout output to standard out\n"
1641  " -q --quiet suppress noncritical error messages\n"
1642  " -v --verbose be verbose (a 2nd -v gives more)\n"
1643  " -L --license display software version & license\n"
1644  " -V --version display software version & license\n"
1645  " -s --small use less memory (at most 2500k)\n"
1646  " -1 .. -9 set block size to 100k .. 900k\n"
1647  " --fast alias for -1\n"
1648  " --best alias for -9\n"
1649  "\n"
1650  " If invoked as `bzip2', default action is to compress.\n"
1651  " as `bunzip2', default action is to decompress.\n"
1652  " as `bzcat', default action is to decompress to stdout.\n"
1653  "\n"
1654  " If no file names are given, bzip2 compresses or decompresses\n"
1655  " from standard input to standard output. You can combine\n"
1656  " short flags, so `-v -4' means the same as -v4 or -4v, &c.\n"
1657 # if BZ_UNIX
1658  "\n"
1659 # endif
1660  ,
1661 
1662  BZ2_bzlibVersion(),
1663  fullProgName
1664  );
1665 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define BZ_UNIX
Definition: bzip2.c:26
const char *BZ_API() BZ2_bzlibVersion(void)
Definition: bzlib.c:1383
FILE * stderr

Referenced by main().

Variable Documentation

◆ blockSize100k

◆ deleteOutputOnInterrupt

Bool deleteOutputOnInterrupt

Definition at line 184 of file bzip2.c.

Referenced by cleanUpAndFail(), compress(), main(), testf(), and uncompress().

◆ exitValue

Int32 exitValue

Definition at line 187 of file bzip2.c.

Referenced by cleanUpAndFail(), configError(), copyFileName(), main(), and setExit().

◆ fileMetaInfo

struct MY_STAT fileMetaInfo
static

◆ forceOverwrite

Bool forceOverwrite

Definition at line 185 of file bzip2.c.

Referenced by compress(), main(), uncompress(), and uncompressStream().

◆ inName

◆ keepInputFiles

Bool keepInputFiles

Definition at line 184 of file bzip2.c.

Referenced by compress(), main(), and uncompress().

◆ longestFileName

Int32 longestFileName

Definition at line 204 of file bzip2.c.

Referenced by main(), and pad().

◆ noisy

◆ numFileNames

Int32 numFileNames

Definition at line 186 of file bzip2.c.

Referenced by cleanUpAndFail(), and main().

◆ numFilesProcessed

Int32 numFilesProcessed

Definition at line 186 of file bzip2.c.

Referenced by cleanUpAndFail(), and main().

◆ opMode

Int32 opMode

Definition at line 199 of file bzip2.c.

Referenced by cleanUpAndFail(), main(), and mySIGSEGVorSIGBUScatcher().

◆ outName

Char outName[FILE_NAME_LEN]

Definition at line 206 of file bzip2.c.

Referenced by cleanUpAndFail(), compress(), main(), showFileNames(), testf(), and uncompress().

◆ outputHandleJustInCase

FILE* outputHandleJustInCase

◆ progName

◆ progNameReally

Char progNameReally[FILE_NAME_LEN]

Definition at line 209 of file bzip2.c.

Referenced by main().

◆ smallMode

Bool smallMode

Definition at line 184 of file bzip2.c.

Referenced by bzopen_or_bzdopen(), main(), testStream(), and uncompressStream().

◆ srcMode

Int32 srcMode

Definition at line 200 of file bzip2.c.

Referenced by cleanUpAndFail(), compress(), main(), testf(), and uncompress().

◆ testFailsExist

Bool testFailsExist

Definition at line 185 of file bzip2.c.

Referenced by main(), and testf().

◆ tmpName

Char tmpName[FILE_NAME_LEN]

Definition at line 207 of file bzip2.c.

Referenced by addFlagsFromEnvVar(), processFile(), and xsltXPathVariableLookup().

◆ UInt64

Definition at line 234 of file bzip2.c.

◆ unzFailsExist

Bool unzFailsExist

Definition at line 185 of file bzip2.c.

Referenced by main(), and uncompress().

◆ unzSuffix

const Char* unzSuffix[BZ_N_SUFFIX_PAIRS] = { "", "", ".tar", ".tar" }

Definition at line 1107 of file bzip2.c.

Referenced by uncompress().

◆ verbosity

Int32 verbosity

Definition at line 183 of file bzip2.c.

Referenced by compress(), compressStream(), main(), testf(), testStream(), uncompress(), and uncompressStream().

◆ workFactor

◆ zSuffix

const Char* zSuffix[BZ_N_SUFFIX_PAIRS] = { ".bz2", ".bz", ".tbz2", ".tbz" }

Definition at line 1105 of file bzip2.c.

Referenced by compress(), and uncompress().