-
-
Notifications
You must be signed in to change notification settings - Fork 487
bzip2: apply patches from msys2/MINGW-packages. #8223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| diff -urN bzip2-1.0.6/bzip2.c bzip2-1.0.6/bzip2.c | ||
| --- bzip2-1.0.6/bzip2.c 2010-09-10 19:04:53.000000000 -0400 | ||
| +++ bzip2-1.0.6/bzip2.c 2011-05-20 21:22:16.853325100 -0400 | ||
| @@ -1132,8 +1132,8 @@ | ||
| static | ||
| void compress ( Char *name ) | ||
| { | ||
| - FILE *inStr; | ||
| - FILE *outStr; | ||
| + FILE *inStr = NULL; | ||
| + FILE *outStr = NULL; | ||
| Int32 n, i; | ||
| struct MY_STAT statBuf; | ||
|
|
||
| @@ -1313,8 +1313,8 @@ | ||
| static | ||
| void uncompress ( Char *name ) | ||
| { | ||
| - FILE *inStr; | ||
| - FILE *outStr; | ||
| + FILE *inStr = NULL; | ||
| + FILE *outStr = NULL; | ||
| Int32 n, i; | ||
| Bool magicNumberOK; | ||
| Bool cantGuess; | ||
| @@ -1511,7 +1511,7 @@ | ||
| static | ||
| void testf ( Char *name ) | ||
| { | ||
| - FILE *inStr; | ||
| + FILE *inStr = NULL; | ||
| Bool allOK; | ||
| struct MY_STAT statBuf; | ||
|
|
||
| diff -urN bzip2-1.0.6/bzip2recover.c bzip2-1.0.6/bzip2recover.c | ||
| --- bzip2-1.0.6/bzip2recover.c 2010-09-10 19:18:40.000000000 -0400 | ||
| +++ bzip2-1.0.6/bzip2recover.c 2011-05-20 21:21:39.518325100 -0400 | ||
| @@ -24,6 +24,8 @@ | ||
| #include <errno.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| +#include <fcntl.h> | ||
| +#include <unistd.h> | ||
|
|
||
|
|
||
| /* This program records bit locations in the file to be recovered. | ||
| @@ -269,6 +271,19 @@ | ||
| name[n-1] == '2'); | ||
| } | ||
|
|
||
| +/*---------------------------------------------*/ | ||
| +/* Open an output file safely with O_EXCL and good permissions */ | ||
| +FILE* fopen_output( Char* name, const char* mode ) | ||
| +{ | ||
| + FILE *fp; | ||
| + int fh; | ||
| + | ||
| + fh = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600); | ||
| + if (fh == -1) return NULL; | ||
| + fp = fdopen(fh, mode); | ||
| + if (fp == NULL) close(fh); | ||
| + return fp; | ||
| +} | ||
|
|
||
| /*---------------------------------------------------*/ | ||
| /*--- ---*/ | ||
| @@ -306,6 +321,7 @@ | ||
| Int32 b, wrBlock, currBlock, rbCtr; | ||
| MaybeUInt64 bitsRead; | ||
|
|
||
| + | ||
| UInt32 buffHi, buffLo, blockCRC; | ||
| Char* p; | ||
|
|
||
| @@ -486,7 +502,7 @@ | ||
| fprintf ( stderr, " writing block %d to `%s' ...\n", | ||
| wrBlock+1, outFileName ); | ||
|
|
||
| - outFile = fopen ( outFileName, "wb" ); | ||
| + outFile = fopen_output ( outFileName, "wb" ); | ||
| if (outFile == NULL) { | ||
| fprintf ( stderr, "%s: can't write `%s'\n", | ||
| progName, outFileName ); | ||
| diff -urN bzip2-1.0.6/bzlib.c bzip2-1.0.6/bzlib.c | ||
| --- bzip2-1.0.6/bzlib.c 2010-09-10 18:38:23.000000000 -0400 | ||
| +++ bzip2-1.0.6/bzlib.c 2011-05-20 21:21:39.524325100 -0400 | ||
| @@ -1372,7 +1372,7 @@ | ||
| #ifndef BZ_NO_STDIO | ||
| /*---------------------------------------------------*/ | ||
|
|
||
| -#if defined(_WIN32) || defined(OS2) || defined(MSDOS) | ||
| +#if defined(_WIN32) || defined(OS2) || defined(MSDOS) || defined(__CYGWIN__) | ||
| # include <fcntl.h> | ||
| # include <io.h> | ||
| # define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY) | ||
| diff -urN bzip2-1.0.6/bzlib.h bzip2-1.0.6/bzlib.h | ||
| --- bzip2-1.0.6/bzlib.h 2010-09-10 19:08:42.000000000 -0400 | ||
| +++ bzip2-1.0.6/bzlib.h 2011-05-20 22:38:02.807325100 -0400 | ||
| @@ -75,21 +75,39 @@ | ||
| #include <stdio.h> | ||
| #endif | ||
|
|
||
| -#ifdef _WIN32 | ||
| +#if defined(_WIN32) && !defined(__CYGWIN__) | ||
| # include <windows.h> | ||
| # ifdef small | ||
| /* windows.h define small to char */ | ||
| # undef small | ||
| # endif | ||
| -# ifdef BZ_EXPORT | ||
| -# define BZ_API(func) WINAPI func | ||
| -# define BZ_EXTERN extern | ||
| +# ifndef __GNUC__ | ||
| + /* Use these rules only for non-gcc native win32 */ | ||
| +# ifdef BZ_EXPORT | ||
| +# define BZ_API(func) WINAPI func | ||
| +# define BZ_EXTERN extern | ||
| +# else | ||
| + /* import windows dll dynamically */ | ||
| +# define BZ_API(func) (WINAPI * func) | ||
| +# define BZ_EXTERN | ||
| +# endif | ||
| # else | ||
| - /* import windows dll dynamically */ | ||
| -# define BZ_API(func) (WINAPI * func) | ||
| -# define BZ_EXTERN | ||
| + /* For gcc on native win32, use import library trampoline */ | ||
| + /* functions on DLL import. This avoids requiring clients to */ | ||
| + /* use special compilation flags depending on whether eventual */ | ||
| + /* link will be against static libbz2 or against DLL, at the */ | ||
| + /* expense of a small loss of efficiency. */ | ||
| + | ||
| + /* Because libbz2 does not export any DATA items, GNU ld's */ | ||
| + /* "auto-import" is not a factor; the MinGW-built DLL can be */ | ||
| + /* used by other compilers, provided an import library suitable */ | ||
| + /* for that compiler is (manually) constructed using the .def */ | ||
| + /* file and the appropriate tool. */ | ||
| +# define BZ_API(func) func | ||
| +# define BZ_EXTERN extern | ||
| # endif | ||
| #else | ||
| + /* non-win32 platforms, and cygwin */ | ||
| # define BZ_API(func) func | ||
| # define BZ_EXTERN extern | ||
| #endif | ||
| diff -urN bzip2-1.0.6/bzmore bzip2-1.0.6/bzmore | ||
| --- bzip2-1.0.6/bzmore 2007-01-02 21:00:55.000000000 -0500 | ||
| +++ bzip2-1.0.6/bzmore 2011-05-20 21:21:39.540325100 -0400 | ||
| @@ -24,10 +24,10 @@ | ||
| # 'stty min 1' resets eof to ^a on both SunOS and SysV! | ||
| cb='min 1 -icanon'; ncb='icanon eof ^d' | ||
| fi | ||
| -if test $? -eq 0 -a -n "$oldtty"; then | ||
| - trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15 | ||
| +if test $? -eq 0 && test -n "$oldtty"; then | ||
| + trap 'stty $oldtty 2>/dev/null; exit' 0 INT QUIT TRAP USR1 PIPE TERM | ||
| else | ||
| - trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15 | ||
| + trap 'stty $ncb echo 2>/dev/null; exit' 0 INT QUIT TRAP USR1 PIPE TERM | ||
| fi | ||
|
|
||
| if test $# = 0; then | ||
| @@ -46,7 +46,7 @@ | ||
| ANS=`dd bs=1 count=1 2>/dev/null` | ||
| stty $ncb echo 2>/dev/null | ||
| echo " " | ||
| - if test "$ANS" = 'e' -o "$ANS" = 'q'; then | ||
| + if test "$ANS" = 'e' || test "$ANS" = 'q'; then | ||
| exit | ||
| fi | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| Ripped from Mandrake | ||
|
|
||
| http://bugs.gentoo.org/82192 | ||
|
|
||
| --- bzip2-1.0.6/bzip2.1 | ||
| +++ bzip2-1.0.6/bzip2.1 | ||
| @@ -235,6 +235,10 @@ | ||
| Suppress non-essential warning messages. Messages pertaining to | ||
| I/O errors and other critical events will not be suppressed. | ||
| .TP | ||
| +.B \-p \-\-show\-progress | ||
| +Show percentage of input\-file done and while compressing show the percentage | ||
| +of the original file the new file is. | ||
| +.TP | ||
| .B \-v --verbose | ||
| Verbose mode -- show the compression ratio for each file processed. | ||
| Further \-v's increase the verbosity level, spewing out lots of | ||
| --- bzip2-1.0.6/bzip2.c | ||
| +++ bzip2-1.0.6/bzip2.c | ||
| @@ -145,6 +145,7 @@ | ||
| #include <signal.h> | ||
| #include <math.h> | ||
| #include <errno.h> | ||
| +#include <time.h> | ||
| #include <ctype.h> | ||
| #include "bzlib.h" | ||
|
|
||
| @@ -301,4 +302,5 @@ | ||
| Char progNameReally[FILE_NAME_LEN]; | ||
| FILE *outputHandleJustInCase; | ||
| Int32 workFactor; | ||
| +Char showProgress; | ||
|
|
||
| @@ -425,6 +427,12 @@ | ||
| UInt32 nbytes_in_lo32, nbytes_in_hi32; | ||
| UInt32 nbytes_out_lo32, nbytes_out_hi32; | ||
| Int32 bzerr, bzerr_dummy, ret; | ||
| + double fileSize = 0; /* initialized to make the compiler stop crying */ | ||
| + /* double because big files might otherwhise give | ||
| + * overflows. not long long since not all compilers | ||
| + * support that one | ||
| + */ | ||
| + time_t startTime, currentTime; | ||
|
|
||
| SET_BINARY_MODE(stream); | ||
| SET_BINARY_MODE(zStream); | ||
| @@ -432,12 +440,21 @@ | ||
| if (ferror(stream)) goto errhandler_io; | ||
| if (ferror(zStream)) goto errhandler_io; | ||
|
|
||
| + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) { | ||
| + (void)fseek(stream, 0, SEEK_END); | ||
| + fileSize = ftello(stream); | ||
| + rewind(stream); | ||
| + if (verbosity >= 1) | ||
| + fprintf(stderr, "Input-file size: %ld\n", (long)fileSize); | ||
| + } | ||
| + | ||
| bzf = BZ2_bzWriteOpen ( &bzerr, zStream, | ||
| blockSize100k, verbosity, workFactor ); | ||
| if (bzerr != BZ_OK) goto errhandler; | ||
|
|
||
| if (verbosity >= 2) fprintf ( stderr, "\n" ); | ||
|
|
||
| + time(&startTime); | ||
| while (True) { | ||
|
|
||
| if (myfeof(stream)) break; | ||
| @@ -446,6 +463,22 @@ | ||
| if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf ); | ||
| if (bzerr != BZ_OK) goto errhandler; | ||
|
|
||
| + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) { | ||
| + time(¤tTime); | ||
| + | ||
| + if ((currentTime - startTime) > 1) { /* show progress every 2 seconds */ | ||
| + double curInPos = ftello(stream); | ||
| + double curOutPos = ftello(zStream); | ||
| + | ||
| + startTime = currentTime; | ||
| + | ||
| + fprintf(stderr, "%.2f%% done", (curInPos * 100.0) / fileSize); | ||
| + if (srcMode == SM_F2F) | ||
| + fprintf(stderr, ", new size: %.2f%%", (curOutPos * 100.0) / curInPos); | ||
| + | ||
| + fprintf(stderr, " \r"); | ||
| + } | ||
| + } | ||
| } | ||
|
|
||
| BZ2_bzWriteClose64 ( &bzerr, bzf, 0, | ||
| @@ -520,12 +553,14 @@ | ||
| Bool uncompressStream ( FILE *zStream, FILE *stream ) | ||
| { | ||
| BZFILE* bzf = NULL; | ||
| Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i; | ||
| UChar obuf[5000]; | ||
| UChar unused[BZ_MAX_UNUSED]; | ||
| Int32 nUnused; | ||
| void* unusedTmpV; | ||
| UChar* unusedTmp; | ||
| + double fileSize = 0; /* initialized to make the compiler stop crying */ | ||
| + time_t startTime, currentTime; | ||
|
|
||
| nUnused = 0; | ||
| streamNo = 0; | ||
| @@ -533,9 +568,19 @@ | ||
| SET_BINARY_MODE(stream); | ||
| SET_BINARY_MODE(zStream); | ||
|
|
||
| + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) { | ||
| + off_t dummy = ftello(zStream); | ||
| + (void)fseeko(zStream, 0, SEEK_END); | ||
| + fileSize = ftello(zStream); | ||
| + (void)fseeko(zStream, dummy, SEEK_SET); | ||
| + if (verbosity >= 1) | ||
| + fprintf(stderr, "Input-file size: %ld\n", (long)fileSize); | ||
| + } | ||
| + | ||
| if (ferror(stream)) goto errhandler_io; | ||
| if (ferror(zStream)) goto errhandler_io; | ||
|
|
||
| + time(&startTime); | ||
| while (True) { | ||
|
|
||
| bzf = BZ2_bzReadOpen ( | ||
| @@ -551,6 +596,16 @@ | ||
| if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0) | ||
| fwrite ( obuf, sizeof(UChar), nread, stream ); | ||
| if (ferror(stream)) goto errhandler_io; | ||
| + | ||
| + if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) { | ||
| + time(¤tTime); | ||
| + if ((currentTime - startTime) >= 2) { | ||
| + double curInPos = ftello(zStream); | ||
| + startTime = currentTime; | ||
| + | ||
| + fprintf(stderr, "%.2f%% done\r", (curInPos * 100.0) / fileSize); | ||
| + } | ||
| + } | ||
| } | ||
| if (bzerr != BZ_STREAM_END) goto errhandler; | ||
|
|
||
| @@ -1872,6 +1927,7 @@ | ||
| deleteOutputOnInterrupt = False; | ||
| exitValue = 0; | ||
| i = j = 0; /* avoid bogus warning from egcs-1.1.X */ | ||
| + showProgress = False; | ||
|
|
||
| /*-- Set up signal handlers for mem access errors --*/ | ||
| signal (SIGSEGV, mySIGSEGVorSIGBUScatcher); | ||
| @@ -1949,6 +2005,7 @@ | ||
| case 'k': keepInputFiles = True; break; | ||
| case 's': smallMode = True; break; | ||
| case 'q': noisy = False; break; | ||
| + case 'p': showProgress = True; break; | ||
| case '1': blockSize100k = 1; break; | ||
| case '2': blockSize100k = 2; break; | ||
| case '3': blockSize100k = 3; break; | ||
| @@ -1985,6 +2042,7 @@ | ||
| if (ISFLAG("--keep")) keepInputFiles = True; else | ||
| if (ISFLAG("--small")) smallMode = True; else | ||
| if (ISFLAG("--quiet")) noisy = False; else | ||
| + if (ISFLAG("--show-progress")) showProgress = True; else | ||
| if (ISFLAG("--version")) license(); else | ||
| if (ISFLAG("--license")) license(); else | ||
| if (ISFLAG("--exponential")) workFactor = 1; else | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.