w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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  UInt64
 
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 ioError (void)
 
static void outOfMemory (void)
 
static void configError (void)
 
static void crcError (void)
 
static void cleanUpAndFail (Int32)
 
static void compressedStreamEOF (void)
 
static void copyFileName (Char *, Char *)
 
static voidmyMalloc (Int32)
 
static void applySavedFileAttrToOutputFile (IntNative fd)
 
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 mySignalCatcher (IntNative n)
 
static void mySIGSEGVorSIGBUScatcher (IntNative n)
 
static void pad (Char *s)
 
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 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 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 [1034]
 
Char outName [1034]
 
Char tmpName [1034]
 
CharprogName
 
Char progNameReally [1034]
 
FILEoutputHandleJustInCase
 
Int32 workFactor
 
static struct stat fileMetaInfo
 
const CharzSuffix [4] = { ".bz2", ".bz", ".tbz2", ".tbz" }
 
const CharunzSuffix [4] = { "", "", ".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

The base type for UTF-16 code units and pointers. Unsigned 16-bit integer. Starting with ICU 59, C++ API uses char16_t directly, while C API continues to use UChar.

UChar is configurable by defining the macro UCHAR_TYPE on the preprocessor or compiler command line: -DUCHAR_TYPE=uint16_t or -DUCHAR_TYPE=wchar_t (if U_SIZEOF_WCHAR_T==2) etc. (The UCHAR_TYPE can also be #defined earlier in this file, for outside the ICU library code.) This is for transitional use from application code that uses uint16_t or wchar_t for UTF-16.

The default is UChar=char16_t.

C++11 defines char16_t as bit-compatible with uint16_t, but as a distinct type.

In C, char16_t is a simple typedef of uint_least16_t. ICU requires uint_least16_t=uint16_t for data memory mapping. On macOS, char16_t is not available because the uchar.h standard header is missing.

@stable ICU 4.4

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.

References APPEND_FLAG, FILE_NAME_LEN, getenv(), i, isspace, j, k, NULL, p, tmpName, and True.

Referenced by main().

◆ applySavedFileAttrToOutputFile()

static void applySavedFileAttrToOutputFile ( IntNative  fd)
static

Definition at line 1065 of file bzip2.c.

References ERROR_IF_NOT_ZERO, fileMetaInfo, and void.

Referenced by compressStream(), and uncompressStream().

◆ applySavedTimeInfoToOutputFile()

static void applySavedTimeInfoToOutputFile ( Char dstName)
static

Definition at line 1050 of file bzip2.c.

References ERROR_IF_NOT_ZERO, fileMetaInfo, and utime.

Referenced by compress(), and uncompress().

◆ cadvise()

static void cadvise ( void  )
static

Definition at line 659 of file bzip2.c.

References fprintf, and noisy.

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

◆ cleanUpAndFail()

◆ compress()

◆ compressedStreamEOF()

static void compressedStreamEOF ( void  )
static

Definition at line 774 of file bzip2.c.

References cadvise(), cleanUpAndFail(), fprintf, noisy, perror(), progName, and showFileNames().

Referenced by uncompressStream().

◆ compressStream()

◆ configError()

static void configError ( void  )
static

Definition at line 884 of file bzip2.c.

References exit(), exitValue, fprintf, and setExit().

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

◆ containsDubiousChars()

static Bool containsDubiousChars ( Char name)
static

Definition at line 1083 of file bzip2.c.

References False, name, and True.

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

◆ copyFileName()

static void copyFileName ( Char to,
Char from 
)
static

Definition at line 919 of file bzip2.c.

References exit(), exitValue, FILE_NAME_LEN, fprintf, setExit(), strlen(), strncpy(), and to.

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

◆ countHardLinks()

static Int32 countHardLinks ( Char name)
static

Definition at line 998 of file bzip2.c.

References i, MY_LSTAT, MY_STAT, and name.

Referenced by compress(), and uncompress().

◆ crcError()

static void crcError ( void  )
static

Definition at line 761 of file bzip2.c.

References cadvise(), cleanUpAndFail(), fprintf, progName, and showFileNames().

Referenced by uncompressStream().

◆ fileExists()

static Bool fileExists ( Char name)
static

Definition at line 940 of file bzip2.c.

References fclose, FILE, fopen, name, and NULL.

Referenced by compress(), drvHPGL::drvHPGL(), drvPPTX::drvPPTX(), pstoedit(), drvHPGL::readPenColors(), 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.

References close, fdopen(), FILE, fopen, fp, mode, name, NULL, O_CREAT, O_EXCL, O_WRONLY, open, S_IRUSR, and S_IWUSR.

Referenced by compress(), and uncompress().

◆ hasSuffix()

◆ ioError()

static void ioError ( void  )
static

Definition at line 791 of file bzip2.c.

References cleanUpAndFail(), fprintf, perror(), progName, and showFileNames().

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

◆ license()

static void license ( void  )
static

Definition at line 1601 of file bzip2.c.

References BZ2_bzlibVersion(), and fprintf.

Referenced by main().

◆ main()

◆ mapSuffix()

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

Definition at line 1120 of file bzip2.c.

References False, hasSuffix(), name, strlen(), and True.

Referenced by uncompress().

◆ mkCell()

static Cell* mkCell ( void  )
static

Definition at line 1716 of file bzip2.c.

References c, myMalloc(), and NULL.

Referenced by snocString().

◆ myfeof()

static Bool myfeof ( FILE f)
static

Definition at line 318 of file bzip2.c.

References c, EOF, f, False, fgetc, True, and ungetc.

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

◆ myMalloc()

static void * myMalloc ( Int32  n)
static

Definition at line 1704 of file bzip2.c.

References malloc, n, NULL, outOfMemory(), and p.

Referenced by mkCell(), and snocString().

◆ mySignalCatcher()

static void mySignalCatcher ( IntNative  n)
static

Definition at line 805 of file bzip2.c.

References cleanUpAndFail(), fprintf, and progName.

Referenced by main().

◆ mySIGSEGVorSIGBUScatcher()

static void mySIGSEGVorSIGBUScatcher ( IntNative  n)
static

Definition at line 816 of file bzip2.c.

References cadvise(), cleanUpAndFail(), fprintf, OM_Z, opMode, progName, and showFileNames().

Referenced by main().

◆ notAStandardFile()

static Bool notAStandardFile ( Char name)
static

Definition at line 981 of file bzip2.c.

References False, i, MY_LSTAT, MY_S_ISREG, MY_STAT, name, and True.

Referenced by compress(), and uncompress().

◆ outOfMemory()

static void outOfMemory ( void  )
static

◆ pad()

static void pad ( Char s)
static

Definition at line 908 of file bzip2.c.

References fprintf, i, longestFileName, s, and strlen().

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

◆ panic()

◆ redundant()

static void redundant ( Char flag)
static

Definition at line 1670 of file bzip2.c.

References fprintf, and progName.

Referenced by main().

◆ saveInputFileMetaInfo()

static void saveInputFileMetaInfo ( Char srcName)
static

Definition at line 1038 of file bzip2.c.

References ERROR_IF_NOT_ZERO, fileMetaInfo, and MY_STAT.

Referenced by compress(), and uncompress().

◆ setExit()

static void setExit ( Int32  v)
static

Definition at line 651 of file bzip2.c.

References exitValue, and v.

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

◆ showFileNames()

static void showFileNames ( void  )
static

Definition at line 674 of file bzip2.c.

References fprintf, inName, noisy, and outName.

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

◆ snocString()

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

Definition at line 1729 of file bzip2.c.

References zzzz::link, mkCell(), myMalloc(), zzzz::name, name, NULL, root, strcpy(), and strlen().

◆ testf()

◆ testStream()

◆ uInt64_from_UInt32s()

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

Definition at line 238 of file bzip2.c.

References n.

Referenced by compressStream().

◆ uInt64_isZero()

static Bool uInt64_isZero ( UInt64 n)
static

Definition at line 266 of file bzip2.c.

References i, and n.

Referenced by uInt64_toAscii().

◆ uInt64_qrm10()

static Int32 uInt64_qrm10 ( UInt64 n)
static

Definition at line 277 of file bzip2.c.

References i, and n.

Referenced by uInt64_toAscii().

◆ uInt64_to_double()

static double uInt64_to_double ( UInt64 n)
static

Definition at line 252 of file bzip2.c.

References base, i, and n.

Referenced by compressStream().

◆ uInt64_toAscii()

static void uInt64_toAscii ( char *  outbuf,
UInt64 n 
)
static

Definition at line 295 of file bzip2.c.

References buf, i, n, outbuf, q, uInt64_isZero(), and uInt64_qrm10().

Referenced by compressStream().

◆ uncompress()

◆ uncompressStream()

◆ usage()

static void usage ( Char fullProgName)
static

Definition at line 1626 of file bzip2.c.

References BZ2_bzlibVersion(), BZ_UNIX, endif, and fprintf.

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 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[1034]

◆ outputHandleJustInCase

FILE* outputHandleJustInCase

◆ progName

◆ progNameReally

Char progNameReally[1034]

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

◆ testFailsExist

Bool testFailsExist

Definition at line 185 of file bzip2.c.

Referenced by main(), and testf().

◆ tmpName

Char tmpName[1034]

Definition at line 207 of file bzip2.c.

Referenced by addFlagsFromEnvVar().

◆ unzFailsExist

Bool unzFailsExist

Definition at line 185 of file bzip2.c.

Referenced by main(), and uncompress().

◆ unzSuffix

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

Definition at line 1106 of file bzip2.c.

Referenced by uncompress().

◆ verbosity

◆ workFactor

◆ zSuffix

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

Definition at line 1104 of file bzip2.c.

Referenced by compress(), and uncompress().