Skip to content

Commit 4b448ad

Browse files
bzip2: apply patches from msys2/MINGW-packages. (#8223)
1 parent 6ef7a4a commit 4b448ad

File tree

3 files changed

+346
-0
lines changed

3 files changed

+346
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
diff -urN bzip2-1.0.6/bzip2.c bzip2-1.0.6/bzip2.c
2+
--- bzip2-1.0.6/bzip2.c 2010-09-10 19:04:53.000000000 -0400
3+
+++ bzip2-1.0.6/bzip2.c 2011-05-20 21:22:16.853325100 -0400
4+
@@ -1132,8 +1132,8 @@
5+
static
6+
void compress ( Char *name )
7+
{
8+
- FILE *inStr;
9+
- FILE *outStr;
10+
+ FILE *inStr = NULL;
11+
+ FILE *outStr = NULL;
12+
Int32 n, i;
13+
struct MY_STAT statBuf;
14+
15+
@@ -1313,8 +1313,8 @@
16+
static
17+
void uncompress ( Char *name )
18+
{
19+
- FILE *inStr;
20+
- FILE *outStr;
21+
+ FILE *inStr = NULL;
22+
+ FILE *outStr = NULL;
23+
Int32 n, i;
24+
Bool magicNumberOK;
25+
Bool cantGuess;
26+
@@ -1511,7 +1511,7 @@
27+
static
28+
void testf ( Char *name )
29+
{
30+
- FILE *inStr;
31+
+ FILE *inStr = NULL;
32+
Bool allOK;
33+
struct MY_STAT statBuf;
34+
35+
diff -urN bzip2-1.0.6/bzip2recover.c bzip2-1.0.6/bzip2recover.c
36+
--- bzip2-1.0.6/bzip2recover.c 2010-09-10 19:18:40.000000000 -0400
37+
+++ bzip2-1.0.6/bzip2recover.c 2011-05-20 21:21:39.518325100 -0400
38+
@@ -24,6 +24,8 @@
39+
#include <errno.h>
40+
#include <stdlib.h>
41+
#include <string.h>
42+
+#include <fcntl.h>
43+
+#include <unistd.h>
44+
45+
46+
/* This program records bit locations in the file to be recovered.
47+
@@ -269,6 +271,19 @@
48+
name[n-1] == '2');
49+
}
50+
51+
+/*---------------------------------------------*/
52+
+/* Open an output file safely with O_EXCL and good permissions */
53+
+FILE* fopen_output( Char* name, const char* mode )
54+
+{
55+
+ FILE *fp;
56+
+ int fh;
57+
+
58+
+ fh = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600);
59+
+ if (fh == -1) return NULL;
60+
+ fp = fdopen(fh, mode);
61+
+ if (fp == NULL) close(fh);
62+
+ return fp;
63+
+}
64+
65+
/*---------------------------------------------------*/
66+
/*--- ---*/
67+
@@ -306,6 +321,7 @@
68+
Int32 b, wrBlock, currBlock, rbCtr;
69+
MaybeUInt64 bitsRead;
70+
71+
+
72+
UInt32 buffHi, buffLo, blockCRC;
73+
Char* p;
74+
75+
@@ -486,7 +502,7 @@
76+
fprintf ( stderr, " writing block %d to `%s' ...\n",
77+
wrBlock+1, outFileName );
78+
79+
- outFile = fopen ( outFileName, "wb" );
80+
+ outFile = fopen_output ( outFileName, "wb" );
81+
if (outFile == NULL) {
82+
fprintf ( stderr, "%s: can't write `%s'\n",
83+
progName, outFileName );
84+
diff -urN bzip2-1.0.6/bzlib.c bzip2-1.0.6/bzlib.c
85+
--- bzip2-1.0.6/bzlib.c 2010-09-10 18:38:23.000000000 -0400
86+
+++ bzip2-1.0.6/bzlib.c 2011-05-20 21:21:39.524325100 -0400
87+
@@ -1372,7 +1372,7 @@
88+
#ifndef BZ_NO_STDIO
89+
/*---------------------------------------------------*/
90+
91+
-#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
92+
+#if defined(_WIN32) || defined(OS2) || defined(MSDOS) || defined(__CYGWIN__)
93+
# include <fcntl.h>
94+
# include <io.h>
95+
# define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
96+
diff -urN bzip2-1.0.6/bzlib.h bzip2-1.0.6/bzlib.h
97+
--- bzip2-1.0.6/bzlib.h 2010-09-10 19:08:42.000000000 -0400
98+
+++ bzip2-1.0.6/bzlib.h 2011-05-20 22:38:02.807325100 -0400
99+
@@ -75,21 +75,39 @@
100+
#include <stdio.h>
101+
#endif
102+
103+
-#ifdef _WIN32
104+
+#if defined(_WIN32) && !defined(__CYGWIN__)
105+
# include <windows.h>
106+
# ifdef small
107+
/* windows.h define small to char */
108+
# undef small
109+
# endif
110+
-# ifdef BZ_EXPORT
111+
-# define BZ_API(func) WINAPI func
112+
-# define BZ_EXTERN extern
113+
+# ifndef __GNUC__
114+
+ /* Use these rules only for non-gcc native win32 */
115+
+# ifdef BZ_EXPORT
116+
+# define BZ_API(func) WINAPI func
117+
+# define BZ_EXTERN extern
118+
+# else
119+
+ /* import windows dll dynamically */
120+
+# define BZ_API(func) (WINAPI * func)
121+
+# define BZ_EXTERN
122+
+# endif
123+
# else
124+
- /* import windows dll dynamically */
125+
-# define BZ_API(func) (WINAPI * func)
126+
-# define BZ_EXTERN
127+
+ /* For gcc on native win32, use import library trampoline */
128+
+ /* functions on DLL import. This avoids requiring clients to */
129+
+ /* use special compilation flags depending on whether eventual */
130+
+ /* link will be against static libbz2 or against DLL, at the */
131+
+ /* expense of a small loss of efficiency. */
132+
+
133+
+ /* Because libbz2 does not export any DATA items, GNU ld's */
134+
+ /* "auto-import" is not a factor; the MinGW-built DLL can be */
135+
+ /* used by other compilers, provided an import library suitable */
136+
+ /* for that compiler is (manually) constructed using the .def */
137+
+ /* file and the appropriate tool. */
138+
+# define BZ_API(func) func
139+
+# define BZ_EXTERN extern
140+
# endif
141+
#else
142+
+ /* non-win32 platforms, and cygwin */
143+
# define BZ_API(func) func
144+
# define BZ_EXTERN extern
145+
#endif
146+
diff -urN bzip2-1.0.6/bzmore bzip2-1.0.6/bzmore
147+
--- bzip2-1.0.6/bzmore 2007-01-02 21:00:55.000000000 -0500
148+
+++ bzip2-1.0.6/bzmore 2011-05-20 21:21:39.540325100 -0400
149+
@@ -24,10 +24,10 @@
150+
# 'stty min 1' resets eof to ^a on both SunOS and SysV!
151+
cb='min 1 -icanon'; ncb='icanon eof ^d'
152+
fi
153+
-if test $? -eq 0 -a -n "$oldtty"; then
154+
- trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
155+
+if test $? -eq 0 && test -n "$oldtty"; then
156+
+ trap 'stty $oldtty 2>/dev/null; exit' 0 INT QUIT TRAP USR1 PIPE TERM
157+
else
158+
- trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
159+
+ trap 'stty $ncb echo 2>/dev/null; exit' 0 INT QUIT TRAP USR1 PIPE TERM
160+
fi
161+
162+
if test $# = 0; then
163+
@@ -46,7 +46,7 @@
164+
ANS=`dd bs=1 count=1 2>/dev/null`
165+
stty $ncb echo 2>/dev/null
166+
echo " "
167+
- if test "$ANS" = 'e' -o "$ANS" = 'q'; then
168+
+ if test "$ANS" = 'e' || test "$ANS" = 'q'; then
169+
exit
170+
fi
171+
fi
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Ripped from Mandrake
2+
3+
http://bugs.gentoo.org/82192
4+
5+
--- bzip2-1.0.6/bzip2.1
6+
+++ bzip2-1.0.6/bzip2.1
7+
@@ -235,6 +235,10 @@
8+
Suppress non-essential warning messages. Messages pertaining to
9+
I/O errors and other critical events will not be suppressed.
10+
.TP
11+
+.B \-p \-\-show\-progress
12+
+Show percentage of input\-file done and while compressing show the percentage
13+
+of the original file the new file is.
14+
+.TP
15+
.B \-v --verbose
16+
Verbose mode -- show the compression ratio for each file processed.
17+
Further \-v's increase the verbosity level, spewing out lots of
18+
--- bzip2-1.0.6/bzip2.c
19+
+++ bzip2-1.0.6/bzip2.c
20+
@@ -145,6 +145,7 @@
21+
#include <signal.h>
22+
#include <math.h>
23+
#include <errno.h>
24+
+#include <time.h>
25+
#include <ctype.h>
26+
#include "bzlib.h"
27+
28+
@@ -301,4 +302,5 @@
29+
Char progNameReally[FILE_NAME_LEN];
30+
FILE *outputHandleJustInCase;
31+
Int32 workFactor;
32+
+Char showProgress;
33+
34+
@@ -425,6 +427,12 @@
35+
UInt32 nbytes_in_lo32, nbytes_in_hi32;
36+
UInt32 nbytes_out_lo32, nbytes_out_hi32;
37+
Int32 bzerr, bzerr_dummy, ret;
38+
+ double fileSize = 0; /* initialized to make the compiler stop crying */
39+
+ /* double because big files might otherwhise give
40+
+ * overflows. not long long since not all compilers
41+
+ * support that one
42+
+ */
43+
+ time_t startTime, currentTime;
44+
45+
SET_BINARY_MODE(stream);
46+
SET_BINARY_MODE(zStream);
47+
@@ -432,12 +440,21 @@
48+
if (ferror(stream)) goto errhandler_io;
49+
if (ferror(zStream)) goto errhandler_io;
50+
51+
+ if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
52+
+ (void)fseek(stream, 0, SEEK_END);
53+
+ fileSize = ftello(stream);
54+
+ rewind(stream);
55+
+ if (verbosity >= 1)
56+
+ fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
57+
+ }
58+
+
59+
bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
60+
blockSize100k, verbosity, workFactor );
61+
if (bzerr != BZ_OK) goto errhandler;
62+
63+
if (verbosity >= 2) fprintf ( stderr, "\n" );
64+
65+
+ time(&startTime);
66+
while (True) {
67+
68+
if (myfeof(stream)) break;
69+
@@ -446,6 +463,22 @@
70+
if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
71+
if (bzerr != BZ_OK) goto errhandler;
72+
73+
+ if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
74+
+ time(&currentTime);
75+
+
76+
+ if ((currentTime - startTime) > 1) { /* show progress every 2 seconds */
77+
+ double curInPos = ftello(stream);
78+
+ double curOutPos = ftello(zStream);
79+
+
80+
+ startTime = currentTime;
81+
+
82+
+ fprintf(stderr, "%.2f%% done", (curInPos * 100.0) / fileSize);
83+
+ if (srcMode == SM_F2F)
84+
+ fprintf(stderr, ", new size: %.2f%%", (curOutPos * 100.0) / curInPos);
85+
+
86+
+ fprintf(stderr, " \r");
87+
+ }
88+
+ }
89+
}
90+
91+
BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
92+
@@ -520,12 +553,14 @@
93+
Bool uncompressStream ( FILE *zStream, FILE *stream )
94+
{
95+
BZFILE* bzf = NULL;
96+
Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
97+
UChar obuf[5000];
98+
UChar unused[BZ_MAX_UNUSED];
99+
Int32 nUnused;
100+
void* unusedTmpV;
101+
UChar* unusedTmp;
102+
+ double fileSize = 0; /* initialized to make the compiler stop crying */
103+
+ time_t startTime, currentTime;
104+
105+
nUnused = 0;
106+
streamNo = 0;
107+
@@ -533,9 +568,19 @@
108+
SET_BINARY_MODE(stream);
109+
SET_BINARY_MODE(zStream);
110+
111+
+ if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
112+
+ off_t dummy = ftello(zStream);
113+
+ (void)fseeko(zStream, 0, SEEK_END);
114+
+ fileSize = ftello(zStream);
115+
+ (void)fseeko(zStream, dummy, SEEK_SET);
116+
+ if (verbosity >= 1)
117+
+ fprintf(stderr, "Input-file size: %ld\n", (long)fileSize);
118+
+ }
119+
+
120+
if (ferror(stream)) goto errhandler_io;
121+
if (ferror(zStream)) goto errhandler_io;
122+
123+
+ time(&startTime);
124+
while (True) {
125+
126+
bzf = BZ2_bzReadOpen (
127+
@@ -551,6 +596,16 @@
128+
if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
129+
fwrite ( obuf, sizeof(UChar), nread, stream );
130+
if (ferror(stream)) goto errhandler_io;
131+
+
132+
+ if ((srcMode == SM_F2F || srcMode == SM_F2O) && showProgress == True) {
133+
+ time(&currentTime);
134+
+ if ((currentTime - startTime) >= 2) {
135+
+ double curInPos = ftello(zStream);
136+
+ startTime = currentTime;
137+
+
138+
+ fprintf(stderr, "%.2f%% done\r", (curInPos * 100.0) / fileSize);
139+
+ }
140+
+ }
141+
}
142+
if (bzerr != BZ_STREAM_END) goto errhandler;
143+
144+
@@ -1872,6 +1927,7 @@
145+
deleteOutputOnInterrupt = False;
146+
exitValue = 0;
147+
i = j = 0; /* avoid bogus warning from egcs-1.1.X */
148+
+ showProgress = False;
149+
150+
/*-- Set up signal handlers for mem access errors --*/
151+
signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
152+
@@ -1949,6 +2005,7 @@
153+
case 'k': keepInputFiles = True; break;
154+
case 's': smallMode = True; break;
155+
case 'q': noisy = False; break;
156+
+ case 'p': showProgress = True; break;
157+
case '1': blockSize100k = 1; break;
158+
case '2': blockSize100k = 2; break;
159+
case '3': blockSize100k = 3; break;
160+
@@ -1985,6 +2042,7 @@
161+
if (ISFLAG("--keep")) keepInputFiles = True; else
162+
if (ISFLAG("--small")) smallMode = True; else
163+
if (ISFLAG("--quiet")) noisy = False; else
164+
+ if (ISFLAG("--show-progress")) showProgress = True; else
165+
if (ISFLAG("--version")) license(); else
166+
if (ISFLAG("--license")) license(); else
167+
if (ISFLAG("--exponential")) workFactor = 1; else

packages/b/bzip2/xmake.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ package("bzip2")
1414
add_extsources("brew::bzip2")
1515
end
1616

17+
on_load(function (package)
18+
-- @see https://github.com/xmake-io/xmake-repo/pull/8179#issuecomment-3327113818, patches from msys2/MINGW-packages.
19+
if package:is_plat("msys", "mingw", "cygwin") then
20+
package:add("patches", "*", "patches/cygming.patch", "7e67f77172b19f3e6c1f0875b1d3e9cb79211f8e1c752794ef9afd3704f928cf")
21+
package:add("patches", "*", "patches/show-progress.patch", "57f35bd9ef9113629c1d0ab6bcbbb7c0df0f7f4402ba0dccada32aa1cfe838f5")
22+
end
23+
end)
24+
1725
on_install(function (package)
1826
local configs = {}
1927
configs.enable_tools = not package:is_plat("wasm")

0 commit comments

Comments
 (0)