# Where you want pbzip2 installed when you do 'make install'
PREFIX = /usr
+DESTDIR =
all: pbzip2
# Install the binary pbzip2 program and man page
install: pbzip2
- if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
- if ( test ! -d $(PREFIX)/share ) ; then mkdir -p $(PREFIX)/share ; fi
- if ( test ! -d $(PREFIX)/share/man ) ; then mkdir -p $(PREFIX)/share/man ; fi
- if ( test ! -d $(PREFIX)/share/man/man1 ) ; then mkdir -p $(PREFIX)/share/man/man1 ; fi
- cp -f pbzip2 $(PREFIX)/bin/pbzip2
- chmod a+x $(PREFIX)/bin/pbzip2
- ln -s -f pbzip2 $(PREFIX)/bin/pbunzip2
- ln -s -f pbzip2 $(PREFIX)/bin/pbzcat
- cp -f pbzip2.1 $(PREFIX)/share/man/man1
- chmod a+r $(PREFIX)/share/man/man1/pbzip2.1
+ if ( test ! -d $(DESTDIR)$(PREFIX)/bin ) ; then mkdir -p $(DESTDIR)$(PREFIX)/bin ; fi
+ if ( test ! -d $(DESTDIR)$(PREFIX)/share ) ; then mkdir -p $(DESTDIR)$(PREFIX)/share ; fi
+ if ( test ! -d $(DESTDIR)$(PREFIX)/share/man ) ; then mkdir -p $(DESTDIR)$(PREFIX)/share/man ; fi
+ if ( test ! -d $(DESTDIR)$(PREFIX)/share/man/man1 ) ; then mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1 ; fi
+ cp -f pbzip2 $(DESTDIR)$(PREFIX)/bin/pbzip2
+ chmod a+x $(DESTDIR)$(PREFIX)/bin/pbzip2
+ ln -s -f pbzip2 $(DESTDIR)$(PREFIX)/bin/pbunzip2
+ ln -s -f pbzip2 $(DESTDIR)$(PREFIX)/bin/pbzcat
+ cp -f pbzip2.1 $(DESTDIR)$(PREFIX)/share/man/man1
+ chmod a+r $(DESTDIR)$(PREFIX)/share/man/man1/pbzip2.1
clean:
rm -f *.o pbzip2
static int unfinishedWorkCleaned = 0;
static int numCPU = 2;
static int IgnoreTrailingGarbageFlag = 0; // ingnore trailing garbage on decompress flag
-static int QUEUESIZE = 2;
static int SIG_HANDLER_QUIT_SIGNAL = SIGUSR1; // signal used to stop SignalHandlerThread
#ifdef USE_STACKSIZE_CUSTOMIZATION
static int ChildThreadStackSize = 0; // -1 - don't modify stacksize; 0 - use minimum; > 0 - use specified
static unsigned char Bz2HeaderZero[] = {
0x42, 0x5A, 0x68, 0x39, 0x17, 0x72, 0x45, 0x38, 0x50, 0x90, 0x00, 0x00, 0x00, 0x00 };
static OFF_T InFileSize;
-static OFF_T InBytesProduced = 0;
static int NumBlocks = 0;
static int NumBlocksEstimated = 0;
static int NumBufferedBlocks = 0;
int producer_decompress(int hInfile, OFF_T fileSize, queue *fifo)
{
safe_mutex_lock(&ProgressIndicatorsMutex);
- InBytesProduced = 0;
NumBlocks = 0;
safe_mutex_unlock(&ProgressIndicatorsMutex);
safe_cond_signal (fifo->notEmpty);
safe_mutex_lock(&ProgressIndicatorsMutex);
- InBytesProduced += fileData->bufSize;
NumBlocks = fileData->blockNumber + 1;
safe_mutex_unlock(&ProgressIndicatorsMutex);
return 0;
}
+void close_streams(FILE *out, FILE *in)
+{
+ if (out != NULL) {
+ fflush(out);
+ }
+
+ if (in != NULL && in != stdin) {
+ fclose(in);
+ }
+
+ if (out != NULL && out != stdout) {
+ fclose(out);
+ }
+}
+
/*
*********************************************************
*/
// check file stream for errors
if (ferror(zStream))
{
- if (zStream != stdin)
- fclose(zStream);
-
+ close_streams(stream, zStream);
handle_error(EF_EXIT, -1,
"pbzip2: *ERROR: Problem with input stream of file [%s]! Aborting...\n", InFilename);
return -1;
// check file stream for errors
if (ferror(stream))
{
- if (stream != stdout)
- fclose(stream);
-
+ close_streams(stream, zStream);
handle_error(EF_EXIT, -1,
"pbzip2: *ERROR: Problem with output stream of file [%s]! Aborting...\n", InFilename);
return -1;
if (syncGetTerminateFlag() != 0)
{
fprintf (stderr, "directdecompress: terminating1 - terminateFlag set\n");
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
+ close_streams(stream, zStream);
return -1;
}
if (bzf == NULL || bzerr != BZ_OK)
{
ret = testBZ2ErrorHandling(bzerr, bzf, streamNo);
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
-
+ close_streams(stream, zStream);
+
if (ret != 0)
{
syncSetTerminateFlag(1);
if (syncGetTerminateFlag() != 0)
{
fprintf (stderr, "directdecompress: terminating2 - terminateFlag set\n");
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
+ close_streams(stream, zStream);
return -1;
}
if (ferror(zStream))
{
ret = testBZ2ErrorHandling(bzerr, bzf, streamNo);
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
-
+ close_streams(stream, zStream);
+
if (ret != 0)
{
syncSetTerminateFlag(1);
if (ferror(stream))
{
ret = testBZ2ErrorHandling(bzerr, bzf, streamNo);
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
-
+ close_streams(stream, zStream);
+
if (ret != 0)
{
syncSetTerminateFlag(1);
if (ferror(stream))
{
ret = testBZ2ErrorHandling(bzerr, bzf, streamNo);
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
-
+ close_streams(stream, zStream);
+
if (ret != 0)
{
syncSetTerminateFlag(1);
if (bzerr != BZ_STREAM_END)
{
ret = testBZ2ErrorHandling(bzerr, bzf, streamNo);
- if (zStream != stdin)
- fclose(zStream);
- if (stream != stdout)
- fclose(stream);
-
+ close_streams(stream, zStream);
+
if (ret != 0)
{
syncSetTerminateFlag(1);
safe_mutex_lock(&ProgressIndicatorsMutex);
NumBlocks = 0;
- InBytesProduced = 0;
safe_mutex_unlock(&ProgressIndicatorsMutex);
// keep going until all the file is processed
safe_mutex_lock(&ProgressIndicatorsMutex);
++NumBlocks;
- InBytesProduced += inSize;
safe_mutex_unlock(&ProgressIndicatorsMutex);
safe_mutex_unlock(fifo->mut);
queue *queueInit(int queueSize)
{
queue *q;
- QUEUESIZE = queueSize;
q = new(std::nothrow) queue;
if (q == NULL)
*/
void banner()
{
- fprintf(stderr, "Parallel BZIP2 v1.1.12 [Dec 21, 2014]\n");
+ fprintf(stderr, "Parallel BZIP2 v1.1.13 [Dec 18, 2015]\n");
fprintf(stderr, "By: Jeff Gilchrist [http://compression.ca]\n");
fprintf(stderr, "Major contributions: Yavor Nikolov [http://javornikolov.wordpress.com]\n");
fprintf(stderr, "Uses libbzip2 by Julian Seward\n");
pthread_t output;
char **FileList = NULL;
char *InFilename = NULL;
+ bool hasInFile = false;
char *progName = NULL;
char *progNamePos = NULL;
char bz2Header[] = {"BZh91AY&SY"}; // using 900k block size
// set input filename
InFilename = FileList[fileLoop];
+ hasInFile = (strcmp(InFilename, "-") != 0);
// test file for errors if requested
if (testFile != 0)
if (QuietMode != 1)
{
fprintf(stderr, " File #: %d of %d\n", fileLoop+1, FileListCount);
- if (strcmp(InFilename, "-") != 0)
+ if (hasInFile)
fprintf(stderr, " Testing: %s\n", InFilename);
else
fprintf(stderr, " Testing: <stdin>\n");
// set ouput filename
outFilename = std::string(FileList[fileLoop]);
- if ((decompress == 1) && (strcmp(InFilename, "-") != 0))
+ if ((decompress == 1) && hasInFile)
{
// check if input file is a valid .bz2 compressed file
hInfile = open(InFilename, O_RDONLY | O_BINARY);
sigOutFilename = outFilename.c_str();
safe_mutex_unlock(&ErrorHandlerMutex);
- if (strcmp(InFilename, "-") != 0)
+ if (hasInFile)
{
struct stat statbuf;
// read file for compression
if (decompress == 1)
fprintf(stderr, " BWT Block Size: %c00k\n", BWTblockSizeChar);
- if (strcmp(InFilename, "-") != 0)
+ if (hasInFile)
fprintf(stderr, " Input Size: %"PRIuMAX" bytes\n", (uintmax_t)InFileSize);
}
noThreads = 0;
// Enable threads method for uncompressing from stdin
- if ((numCPU > 1) && (strcmp(InFilename, "-") == 0))
+ if ((numCPU > 1) && !hasInFile)
noThreads = 0;
} // if (decompress == 1)
else