cygming.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. @@ -1313,8 +1313,8 @@
  15. static
  16. void uncompress ( Char *name )
  17. {
  18. - FILE *inStr;
  19. - FILE *outStr;
  20. + FILE *inStr = NULL;
  21. + FILE *outStr = NULL;
  22. Int32 n, i;
  23. Bool magicNumberOK;
  24. Bool cantGuess;
  25. @@ -1511,7 +1511,7 @@
  26. static
  27. void testf ( Char *name )
  28. {
  29. - FILE *inStr;
  30. + FILE *inStr = NULL;
  31. Bool allOK;
  32. struct MY_STAT statBuf;
  33. diff -urN bzip2-1.0.6/bzip2recover.c bzip2-1.0.6/bzip2recover.c
  34. --- bzip2-1.0.6/bzip2recover.c 2010-09-10 19:18:40.000000000 -0400
  35. +++ bzip2-1.0.6/bzip2recover.c 2011-05-20 21:21:39.518325100 -0400
  36. @@ -24,6 +24,8 @@
  37. #include <errno.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. +#include <fcntl.h>
  41. +#include <unistd.h>
  42. /* This program records bit locations in the file to be recovered.
  43. @@ -269,6 +271,19 @@
  44. name[n-1] == '2');
  45. }
  46. +/*---------------------------------------------*/
  47. +/* Open an output file safely with O_EXCL and good permissions */
  48. +FILE* fopen_output( Char* name, const char* mode )
  49. +{
  50. + FILE *fp;
  51. + int fh;
  52. +
  53. + fh = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600);
  54. + if (fh == -1) return NULL;
  55. + fp = fdopen(fh, mode);
  56. + if (fp == NULL) close(fh);
  57. + return fp;
  58. +}
  59. /*---------------------------------------------------*/
  60. /*--- ---*/
  61. @@ -306,6 +321,7 @@
  62. Int32 b, wrBlock, currBlock, rbCtr;
  63. MaybeUInt64 bitsRead;
  64. +
  65. UInt32 buffHi, buffLo, blockCRC;
  66. Char* p;
  67. @@ -486,7 +502,7 @@
  68. fprintf ( stderr, " writing block %d to `%s' ...\n",
  69. wrBlock+1, outFileName );
  70. - outFile = fopen ( outFileName, "wb" );
  71. + outFile = fopen_output ( outFileName, "wb" );
  72. if (outFile == NULL) {
  73. fprintf ( stderr, "%s: can't write `%s'\n",
  74. progName, outFileName );
  75. diff -urN bzip2-1.0.6/bzlib.c bzip2-1.0.6/bzlib.c
  76. --- bzip2-1.0.6/bzlib.c 2010-09-10 18:38:23.000000000 -0400
  77. +++ bzip2-1.0.6/bzlib.c 2011-05-20 21:21:39.524325100 -0400
  78. @@ -1372,7 +1372,7 @@
  79. #ifndef BZ_NO_STDIO
  80. /*---------------------------------------------------*/
  81. -#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
  82. +#if defined(_WIN32) || defined(OS2) || defined(MSDOS) || defined(__CYGWIN__)
  83. # include <fcntl.h>
  84. # include <io.h>
  85. # define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
  86. diff -urN bzip2-1.0.6/bzlib.h bzip2-1.0.6/bzlib.h
  87. --- bzip2-1.0.6/bzlib.h 2010-09-10 19:08:42.000000000 -0400
  88. +++ bzip2-1.0.6/bzlib.h 2011-05-20 22:38:02.807325100 -0400
  89. @@ -75,21 +75,39 @@
  90. #include <stdio.h>
  91. #endif
  92. -#ifdef _WIN32
  93. +#if defined(_WIN32) && !defined(__CYGWIN__)
  94. # include <windows.h>
  95. # ifdef small
  96. /* windows.h define small to char */
  97. # undef small
  98. # endif
  99. -# ifdef BZ_EXPORT
  100. -# define BZ_API(func) WINAPI func
  101. -# define BZ_EXTERN extern
  102. +# ifndef __GNUC__
  103. + /* Use these rules only for non-gcc native win32 */
  104. +# ifdef BZ_EXPORT
  105. +# define BZ_API(func) WINAPI func
  106. +# define BZ_EXTERN extern
  107. +# else
  108. + /* import windows dll dynamically */
  109. +# define BZ_API(func) (WINAPI * func)
  110. +# define BZ_EXTERN
  111. +# endif
  112. # else
  113. - /* import windows dll dynamically */
  114. -# define BZ_API(func) (WINAPI * func)
  115. -# define BZ_EXTERN
  116. + /* For gcc on native win32, use import library trampoline */
  117. + /* functions on DLL import. This avoids requiring clients to */
  118. + /* use special compilation flags depending on whether eventual */
  119. + /* link will be against static libbz2 or against DLL, at the */
  120. + /* expense of a small loss of efficiency. */
  121. +
  122. + /* Because libbz2 does not export any DATA items, GNU ld's */
  123. + /* "auto-import" is not a factor; the MinGW-built DLL can be */
  124. + /* used by other compilers, provided an import library suitable */
  125. + /* for that compiler is (manually) constructed using the .def */
  126. + /* file and the appropriate tool. */
  127. +# define BZ_API(func) func
  128. +# define BZ_EXTERN extern
  129. # endif
  130. #else
  131. + /* non-win32 platforms, and cygwin */
  132. # define BZ_API(func) func
  133. # define BZ_EXTERN extern
  134. #endif
  135. diff -urN bzip2-1.0.6/bzmore bzip2-1.0.6/bzmore
  136. --- bzip2-1.0.6/bzmore 2007-01-02 21:00:55.000000000 -0500
  137. +++ bzip2-1.0.6/bzmore 2011-05-20 21:21:39.540325100 -0400
  138. @@ -24,10 +24,10 @@
  139. # 'stty min 1' resets eof to ^a on both SunOS and SysV!
  140. cb='min 1 -icanon'; ncb='icanon eof ^d'
  141. fi
  142. -if test $? -eq 0 -a -n "$oldtty"; then
  143. - trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
  144. +if test $? -eq 0 && test -n "$oldtty"; then
  145. + trap 'stty $oldtty 2>/dev/null; exit' 0 INT QUIT TRAP USR1 PIPE TERM
  146. else
  147. - trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
  148. + trap 'stty $ncb echo 2>/dev/null; exit' 0 INT QUIT TRAP USR1 PIPE TERM
  149. fi
  150. if test $# = 0; then
  151. @@ -46,7 +46,7 @@
  152. ANS=`dd bs=1 count=1 2>/dev/null`
  153. stty $ncb echo 2>/dev/null
  154. echo " "
  155. - if test "$ANS" = 'e' -o "$ANS" = 'q'; then
  156. + if test "$ANS" = 'e' || test "$ANS" = 'q'; then
  157. exit
  158. fi
  159. fi