diff -apruNU3 bzip2-1.0.3.orig/Makefile bzip2-1.0.3/Makefile
--- bzip2-1.0.3.orig/Makefile	2005-02-17 11:28:24.000000000 +0000
+++ bzip2-1.0.3/Makefile	2005-07-04 16:48:46.000000000 +0000
@@ -8,10 +8,12 @@ RANLIB=ranlib
 LDFLAGS=
 
 BIGFILES=-D_FILE_OFFSET_BITS=64
-CFLAGS=-Wall -Winline -O -g $(BIGFILES)
+CFLAGS=-Wall -Winline -O2 -g $(BIGFILES)
+
+EXEEXT = .exe
 
 # Where you want it installed when you do 'make install'
-PREFIX=/usr
+PREFIX=/dev/env/DJDIR
 
 
 OBJS= blocksort.o  \
@@ -22,32 +24,27 @@ OBJS= blocksort.o  \
       decompress.o \
       bzlib.o
 
-all: libbz2.a bzip2 bzip2recover test
+all: libbz2.a bzip2$(EXEEXT) bzip2recover$(EXEEXT) test
 
-bzip2: libbz2.a bzip2.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
+bzip2$(EXEEXT): libbz2.a bzip2.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2$(EXEEXT) bzip2.o -L. -lbz2
 
-bzip2recover: bzip2recover.o
-	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
+bzip2recover$(EXEEXT): bzip2recover.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover$(EXEEXT) bzip2recover.o
 
 libbz2.a: $(OBJS)
 	rm -f libbz2.a
-	$(AR) cq libbz2.a $(OBJS)
-	@if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \
-		-f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \
-		echo $(RANLIB) libbz2.a ; \
-		$(RANLIB) libbz2.a ; \
-	fi
+	$(AR) cqs libbz2.a $(OBJS)
 
 check: test
-test: bzip2
+test: bzip2$(EXEEXT)
 	@cat words1
-	./bzip2 -1  < sample1.ref > sample1.rb2
-	./bzip2 -2  < sample2.ref > sample2.rb2
-	./bzip2 -3  < sample3.ref > sample3.rb2
-	./bzip2 -d  < sample1.bz2 > sample1.tst
-	./bzip2 -d  < sample2.bz2 > sample2.tst
-	./bzip2 -ds < sample3.bz2 > sample3.tst
+	./bzip2$(EXEEXT) -1  < sample1.ref > sample1.rb2
+	./bzip2$(EXEEXT) -2  < sample2.ref > sample2.rb2
+	./bzip2$(EXEEXT) -3  < sample3.ref > sample3.rb2
+	./bzip2$(EXEEXT) -d  < sample1.bz2 > sample1.tst
+	./bzip2$(EXEEXT) -d  < sample2.bz2 > sample2.tst
+	./bzip2$(EXEEXT) -ds < sample3.bz2 > sample3.tst
 	cmp sample1.bz2 sample1.rb2 
 	cmp sample2.bz2 sample2.rb2
 	cmp sample3.bz2 sample3.rb2
@@ -56,20 +53,20 @@ test: bzip2
 	cmp sample3.tst sample3.ref
 	@cat words3
 
-install: bzip2 bzip2recover
+install: bzip2$(EXEEXT) bzip2recover$(EXEEXT)
 	if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
 	if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
 	if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi
 	if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi
 	if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
-	cp -f bzip2 $(PREFIX)/bin/bzip2
-	cp -f bzip2 $(PREFIX)/bin/bunzip2
-	cp -f bzip2 $(PREFIX)/bin/bzcat
-	cp -f bzip2recover $(PREFIX)/bin/bzip2recover
-	chmod a+x $(PREFIX)/bin/bzip2
-	chmod a+x $(PREFIX)/bin/bunzip2
-	chmod a+x $(PREFIX)/bin/bzcat
-	chmod a+x $(PREFIX)/bin/bzip2recover
+	cp -f bzip2$(EXEEXT) $(PREFIX)/bin/bzip2$(EXEEXT)
+	ln -s $(PREFIX)/bin/bzip2$(EXEEXT) $(PREFIX)/bin/bunzip2$(EXEEXT)
+	ln -s $(PREFIX)/bin/bzip2$(EXEEXT) $(PREFIX)/bin/bzcat$(EXEEXT)
+	cp -f bzip2recover$(EXEEXT) $(PREFIX)/bin/bzip2recover$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzip2$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bunzip2$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzcat$(EXEEXT)
+	chmod a+x $(PREFIX)/bin/bzip2recover$(EXEEXT)
 	cp -f bzip2.1 $(PREFIX)/man/man1
 	chmod a+r $(PREFIX)/man/man1/bzip2.1
 	cp -f bzlib.h $(PREFIX)/include
@@ -96,7 +93,7 @@ install: bzip2 bzip2recover
 	echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
 
 clean: 
-	rm -f *.o libbz2.a bzip2 bzip2recover \
+	rm -f *.o libbz2.a bzip2$(EXEEXT) bzip2recover$(EXEEXT) \
 	sample1.rb2 sample2.rb2 sample3.rb2 \
 	sample1.tst sample2.tst sample3.tst
 
diff -apruNU3 bzip2-1.0.3.orig/bzdiff bzip2-1.0.3/bzdiff
--- bzip2-1.0.3.orig/bzdiff	2004-10-09 11:29:42.000000000 +0000
+++ bzip2-1.0.3/bzdiff	2005-07-04 16:51:58.000000000 +0000
@@ -12,7 +12,18 @@
 # necessary) and fed to cmp or diff.  The exit status from cmp
 # or diff is preserved.
 
-PATH="/usr/bin:$PATH"; export PATH
+tmpdir=${TMPDIR-/tmp}
+if test ! -d "$tmpdir"; then
+  tmpdir=.
+fi
+
+remove=/bin/rm
+pathsep=:
+if test -n "$DJGPP$djgpp"; then
+  remove=/dev/env/DJDIR/rm
+  pathsep=";"
+fi
+PATH="/dev/env/DJDIR/bin$pathsep$PATH"; export PATH
 prog=`echo $0 | sed 's|.*/||'`
 case "$prog" in
   *cmp) comp=${CMP-cmp}   ;;
@@ -37,10 +48,7 @@ if test -z "$FILES"; then
 	echo "Usage: $prog [${comp}_options] file [file]"
 	exit 1
 fi
-tmp=`tempfile -d /tmp -p bz` || {
-      echo 'cannot create a temporary file' >&2
-      exit 1
-}
+tmp="$tmpdir/bz$$"
 set $FILES
 if test $# -eq 1; then
 	FILE=`echo "$1" | sed 's/.bz2$//'`
@@ -56,7 +64,7 @@ elif test $# -eq 2; then
                         bzip2 -cdfq "$2" > $tmp
                         bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
                         STAT="$?"
-			/bin/rm -f $tmp;;
+			$remove -f $tmp;;
 
                 *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
                         STAT="$?";;
diff -apruNU3 bzip2-1.0.3.orig/bzgrep bzip2-1.0.3/bzgrep
--- bzip2-1.0.3.orig/bzgrep	2004-10-09 11:29:32.000000000 +0000
+++ bzip2-1.0.3/bzgrep	2005-07-04 16:51:58.000000000 +0000
@@ -6,7 +6,11 @@
 ## zgrep -- a wrapper around a grep program that decompresses files as needed
 ## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
 
-PATH="/usr/bin:$PATH"; export PATH
+pathsep=:
+if test -n "$DJGPP$djgpp"; then
+  pathsep=";"
+fi
+PATH="/dev/env/DJDIR/bin$pathsep$PATH"; export PATH
 
 prog=`echo $0 | sed 's|.*/||'`
 case "$prog" in
diff -apruNU3 bzip2-1.0.3.orig/bzip2.1 bzip2-1.0.3/bzip2.1
--- bzip2-1.0.3.orig/bzip2.1	2004-10-17 17:07:20.000000000 +0000
+++ bzip2-1.0.3/bzip2.1	2005-07-04 16:51:58.000000000 +0000
@@ -10,14 +10,14 @@ bzip2recover \- recovers data from damag
 .SH SYNOPSIS
 .ll +8
 .B bzip2
-.RB [ " \-cdfkqstvzVL123456789 " ]
+.RB [ " \-cdfknqstvzVL123456789 " ]
 [
 .I "filenames \&..."
 ]
 .ll -8
 .br
 .B bunzip2
-.RB [ " \-fkvsVL " ]
+.RB [ " \-fknvsVL " ]
 [ 
 .I "filenames \&..."
 ]
@@ -102,6 +102,68 @@ with
 .I .out
 appended.
 
+The above applies also to the DJGPP port of
+.I bzip2
+when LFN support is avaliable.
+If LFN support is not available (plain DOS and WIN9X with LFN=n) the file name
+and the extension will not be properly preserved at the same time.
+This port offers the user the choice between two rules to create the name of the
+compressed file. The first rule (default) will preserve the file name at the cost
+of truncating the extension. The second rule will preserve the extension and truncate
+the file name. The different rules are selected by omitting or setting the
+.I \-n
+flag.
+
+Rule 1: file name preserving and extension truncating.
+This is the default rule. If the
+.I \-n
+flag is omitted then this rule will be used.
+With this rule the following types of file names will be created:
+
+When compressing:
+       filename       becomes   filename.bz2
+       filename.e     becomes   filename.ebz
+       filename.ex    becomes   filename.exb
+       filename.ext   becomes   filename.exb
+       filename.tar   becomes   filename.tbz
+
+When decompressing:
+       filename.bz2   becomes   filename
+       filename.b     becomes   filename
+       filename.ebz   becomes   filename.e
+       filename.exb   becomes   filename.ex
+       filename.tbz   becomes   filename.tar
+       anyothername   becomes   anyothername.out
+
+Rule 2: file name truncating and extension preserving.
+This rule must be explicity enabled by setting the
+.I \-n
+flag.
+With this rule backward compatibility with other MSDOS ports of
+.I bzip2
+is achieved.
+With this rule the following types of file names will be created:
+
+When compressing:
+       filename       becomes   filename.bz2
+       filename.e     becomes   filena_e.bz2
+       filename.ex    becomes   filen_ex.bz2
+       filename.ext   becomes   file_ext.bz2
+       filename.tar   becomes   filename.tbz
+
+When decompressing:
+       filename.bz2   becomes   filename
+       filena_e.bz2   becomes   filena.e
+       filen_ex.bz2   becomes   filen.ex
+       file_ext.bz2   becomes   file.ext
+       filename.tbz   becomes   filename.tar
+       anyothername   becomes   anyothername.out
+
+The same rule must be used for compression and decompression.
+The
+.I \-n
+flag is ignored on WIN9X with LFN=y.
+
 As with compression, supplying no
 filenames causes decompression from 
 standard input to standard output.
@@ -261,6 +323,25 @@ These flags are redundant in versions 0.
 some coarse control over the behaviour of the sorting algorithm in
 earlier versions, which was sometimes useful.  0.9.5 and above have an
 improved algorithm which renders these flags irrelevant.
+.TP
+.B \-n
+This flag is only available for DJGPP ports of
+.I bzip2
+on plain DOS and WIN9X with LFN=n and is ignored on WIN9X with LFN=y.
+This flag selects one of two rules to create the name of the compressed
+file. If this flag is omitted then rule 1 will be used. Rule 1 preserves
+the original file name and truncates the extension. If the extension has
+the length of one character a 
+.I bz
+will be added to the extension. If the extension has two characters a
+.I b
+character will be added to the extension else the third character of
+the extension will be overwritten with a
+.I b
+character.
+If the flag is set then rule 2 will be used. Rule 2 stores
+the extension truncating the original file name.
+The same rule must be used for compression and decompression.
 
 .SH MEMORY MANAGEMENT
 .I bzip2 
@@ -376,6 +457,14 @@ any potential data loss through media  o
 you might consider compressing with a smaller
 block size.
 
+For the DJGPP port of
+.I bzip2recover
+the following applies:
+If LFN support is available the output file names will be of the same form
+as above described. If LFN support is not available then "rec0001file" will
+become "r0001file", etc. If the file has no extension then an ".bz2" extension
+will be added, else the original extension will be retained.
+
 .SH PERFORMANCE NOTES
 The sorting phase of compression gathers together similar strings in the
 file.  Because of this, files containing very long runs of repeated
diff -apruNU3 bzip2-1.0.3.orig/bzip2.c bzip2-1.0.3/bzip2.c
--- bzip2-1.0.3.orig/bzip2.c	2005-02-15 16:25:34.000000000 +0000
+++ bzip2-1.0.3/bzip2.c	2005-07-04 16:51:58.000000000 +0000
@@ -118,6 +118,17 @@
 #define BZ_UNIX      1
 
 /*--
+  DJGPP supports DOS and Win32 environments.
+  The actual OS is determinated at run time.
+--*/
+#define BZ_DOS       0
+
+#if defined(__DJGPP__)
+# undef  BZ_DOS
+# define BZ_DOS 1
+#endif
+
+/*--
   Win32, as seen by Jacob Navia's excellent
   port of (Chris Fraser & David Hanson)'s excellent
   lcc compiler.  Or with MS Visual C.
@@ -166,11 +177,13 @@
 #   include <sys/stat.h>
 #   include <sys/times.h>
 
-#   define PATH_SEP    '/'
-#   define MY_LSTAT    lstat
-#   define MY_STAT     stat
-#   define MY_S_ISREG  S_ISREG
-#   define MY_S_ISDIR  S_ISDIR
+#   define HAVE_SIGBUS    1
+#   define IS_PATH_SEP(c) ((c) == '/')
+#   define MY_LSTAT       lstat
+#   define MY_STAT        stat
+#   define MY_S_ISREG     S_ISREG
+#   define MY_S_ISDIR     S_ISDIR
+#   define MY_STDOUT      stderr
 
 #   define APPEND_FILESPEC(root, name) \
       root=snocString((root), (name))
@@ -189,22 +202,40 @@
 #   ifdef __DJGPP__
 #     include <io.h>
 #     include <fcntl.h>
-#     undef MY_LSTAT
+#     undef  HAVE_SIGBUS
+#     define HAVE_SIGBUS            0
+#     undef  IS_PATH_SEP
+#     define IS_PATH_SEP(c)         ((c) == '/' || (c) == '\\' || (c) == ':')
+#     define IS_EXTENSION(name)     (strchr ((name), '.') != NULL)
+#     define IS_TAR_EXTENSION(name) (strstr ((name), ".tar") != NULL)
+#     define NO_LFN_SUPPORT(name)   (pathconf ((name), _PC_NAME_MAX) <= 12)
+#     ifndef S_ISLNK
+#       undef  MY_LSTAT
+#       define MY_LSTAT     stat
+#     endif
 #     undef MY_STAT
-#     define MY_LSTAT stat
 #     define MY_STAT stat
-#     undef SET_BINARY_MODE
-#     define SET_BINARY_MODE(fd)                        \
+#     undef MY_STDOUT
+#     define MY_STDOUT stdout
+#     if (defined(O_BINARY) != 0)
+#       undef  SET_BINARY_MODE
+#       define SET_BINARY_MODE(fd)                      \
         do {                                            \
-           int retVal = setmode ( fileno ( fd ),        \
-                                  O_BINARY );           \
-           ERROR_IF_MINUS_ONE ( retVal );               \
+           if ( !isatty ( fileno ( fd ) ) )             \
+           {                                            \
+             int retVal = setmode ( fileno ( fd ),      \
+                                   O_BINARY );          \
+             ERROR_IF_MINUS_ONE ( retVal );             \
+           }                                            \
         } while ( 0 )
+#     endif
 #   endif
 
 #   ifdef __CYGWIN__
 #     include <io.h>
 #     include <fcntl.h>
+#     undef MY_STDOUT
+#     define MY_STDOUT stdout
 #     undef SET_BINARY_MODE
 #     define SET_BINARY_MODE(fd)                        \
         do {                                            \
@@ -223,11 +254,13 @@
 #   include <sys\stat.h>
 
 #   define NORETURN       /**/
-#   define PATH_SEP       '\\'
+#   define HAVE_SIGBUS    1
+#   define IS_PATH_SEP(c) ((c) == '\\')
 #   define MY_LSTAT       _stat
 #   define MY_STAT        _stat
 #   define MY_S_ISREG(x)  ((x) & _S_IFREG)
 #   define MY_S_ISDIR(x)  ((x) & _S_IFDIR)
+#   define MY_STDOUT      stdout
 
 #   define APPEND_FLAG(root, name) \
       root=snocString((root), (name))
@@ -301,6 +334,9 @@ Char    *progName;
 Char    progNameReally[FILE_NAME_LEN];
 FILE    *outputHandleJustInCase;
 Int32   workFactor;
+#ifdef BZ_DOS
+Bool    dosFileNameRule1;
+#endif
 
 static void    panic                 ( Char* )   NORETURN;
 static void    ioError               ( void )    NORETURN;
@@ -310,6 +346,7 @@ static void    crcError              ( v
 static void    cleanUpAndFail        ( Int32 )   NORETURN;
 static void    compressedStreamEOF   ( void )    NORETURN;
 
+static void    addBZ2Suffix ( Char* );
 static void    copyFileName ( Char*, Char* );
 static void*   myMalloc     ( Int32 );
 
@@ -1020,6 +1057,70 @@ void copyFileName ( Char* to, Char* from
 
 /*---------------------------------------------*/
 static 
+void addBZ2Suffix ( Char* name )
+{
+#if BZ_DOS
+   if (NO_LFN_SUPPORT ( name ))
+   {
+     /* DJGPP detects at run time if a LFN-API (win32) is available or not (plain dos).
+        MSDOS 8.3 filename restriction.
+     */
+
+     Char* fileName = basename ( name );
+     if (IS_EXTENSION ( fileName ))
+     {
+       IntNative extStart = (IntNative)( strchr ( fileName, '.' ) - fileName );
+       if (IS_TAR_EXTENSION ( &fileName[extStart] ))
+         strcpy ( &fileName[extStart], ".tbz" );
+       else
+       {
+         /* File has extension but not tar extension. */
+
+         IntNative extLen = strlen ( &fileName[extStart] );
+         if (dosFileNameRule1 == True)
+         {
+           /*----------------------------------------------*/
+           /*---   Output file name rule 1 (default):   ---*/
+           /*---   filename.ext -> filename.exb         ---*/
+           /*----------------------------------------------*/
+           extLen--;
+           switch (extLen) {
+              case 1:
+                 strcat ( fileName, "bz" ); break;
+              case 2:
+                 strcat ( fileName, "b" );  break;
+              default:
+                 fileName[extStart + 3] = 'b'; break;
+           }
+         }
+         else
+         {
+           /*-------------------------------------------------------------*/
+           /*---   Output file name rule 2 (selected with flag: -n):   ---*/
+           /*---   filename.ext -> file_ext.bz2                        ---*/
+           /*-------------------------------------------------------------*/
+
+           IntNative fileNameLen = extStart;
+           fileName[extStart] = '_';
+           if (fileNameLen + extLen > 8)
+             strcpy ( &fileName[8 - extLen], &fileName[extStart] );
+           strcat ( fileName, ".bz2" );
+         }
+       }
+     }
+     else
+       /* no extension at all. */
+       strcat ( fileName, ".bz2" );
+   }
+   else
+     /* no filename restriction. */
+#endif  /* ! BZ_DOS */
+     strcat ( name, ".bz2" ); 
+}
+
+
+/*---------------------------------------------*/
+static 
 Bool fileExists ( Char* name )
 {
    FILE *tmp   = fopen ( name, "rb" );
@@ -1156,7 +1257,7 @@ void applySavedMetaInfoToOutputFile ( Ch
 static 
 Bool containsDubiousChars ( Char* name )
 {
-#  if BZ_UNIX
+#  if defined(BZ_UNIX) && !defined(BZ_DOS)
    /* On unix, files can contain any characters and the file expansion
     * is performed by the shell.
     */
@@ -1223,7 +1324,7 @@ void compress ( Char *name )
       case SM_F2F: 
          copyFileName ( inName, name );
          copyFileName ( outName, name );
-         strcat ( outName, ".bz2" ); 
+         addBZ2Suffix ( outName );
          break;
       case SM_F2O: 
          copyFileName ( inName, name );
@@ -1408,8 +1509,55 @@ void uncompress ( Char *name )
          copyFileName ( inName, name );
          copyFileName ( outName, name );
          for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
-            if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
-               goto zzz; 
+         {
+           if (mapSuffix ( outName,zSuffix[i], unzSuffix[i] )) /* Test for extensions: .bz2, .tbz2, .bz, .tbz */
+           {
+             if (NO_LFN_SUPPORT ( outName ))  /* MSDOS 8.3 filename restriction */
+             {
+               if (dosFileNameRule1 == False)
+               {
+                 /*-------------------------------------------------------------*/
+                 /*---   Output file name rule 2 (selected with flag: -n):   ---*/
+                 /*---   file_ext.bz2 -> file.ext                            ---*/
+                 /*-------------------------------------------------------------*/
+
+                 Char* fileName = basename ( outName );
+                 if (!IS_TAR_EXTENSION ( fileName ))
+                 {
+                   Char* dot = strrchr ( fileName, '_' );
+                   if (dot && strlen ( dot ) <= 4)
+                     *dot = '.';
+                 }
+               }
+             }
+             goto zzz;
+           }
+           else /* If and only if DOS or WIN9X(LFN=n) is used, test for extensions: .xbz, .xxb. x= any character. */
+           {
+             if (NO_LFN_SUPPORT ( outName ))  /* MSDOS 8.3 filename restriction */
+             {
+               if (dosFileNameRule1 == True)
+               {
+                 /*----------------------------------------------*/
+                 /*---   Output file name rule 1 (default):   ---*/
+                 /*---   filename.exb -> filename.ex          ---*/
+                 /*----------------------------------------------*/
+
+                 Char* fileName = basename ( outName );
+                 if (IS_EXTENSION ( fileName ))
+                 {
+                   register IntNative extEnd = strlen ( fileName );
+                   for (; extEnd; --extEnd)
+                     if (fileName[extEnd] == 'b')
+                     {
+                       fileName[extEnd] = '\0';
+                       goto zzz;
+                     }
+                 }
+               }
+             }
+           }
+         }
          cantGuess = True;
          strcat ( outName, ".out" );
          break;
@@ -1673,7 +1821,7 @@ void testf ( Char *name )
 static 
 void license ( void )
 {
-   fprintf ( stderr,
+   fprintf ( MY_STDOUT,
 
     "bzip2, a block-sorting file compressor.  "
     "Version %s.\n"
@@ -1699,7 +1847,7 @@ static 
 void usage ( Char *fullProgName )
 {
    fprintf (
-      stderr,
+      MY_STDOUT,
       "bzip2, a block-sorting file compressor.  "
       "Version %s.\n"
       "\n   usage: %s [flags and input files in any order]\n"
@@ -1714,6 +1862,14 @@ void usage ( Char *fullProgName )
       "   -q --quiet          suppress noncritical error messages\n"
       "   -v --verbose        be verbose (a 2nd -v gives more)\n"
       "   -L --license        display software version & license\n"
+#ifdef BZ_DOS
+      "   -n                  select output file name rule 2.\n"
+      "                       rule 1: filename preserved, extension truncated.\n"
+      "                       default is output file name rule 1.\n"
+      "                       rule 2: filename truncated, extension preserved.\n"
+      "                       This flag is only available on plain DOS\n"
+      "                       and WIN9X with LFN=n.\n"
+#endif
       "   -V --version        display software version & license\n"
       "   -s --small          use less memory (at most 2500k)\n"
       "   -1 .. -9            set block size to 100k .. 900k\n"
@@ -1875,12 +2031,15 @@ IntNative main ( IntNative argc, Char *a
    workFactor              = 30;
    deleteOutputOnInterrupt = False;
    exitValue               = 0;
+#ifdef BZ_DOS
+   dosFileNameRule1        = True; /* On MSDOS default to output file name rule 1. */
+#endif
    i = j = 0; /* avoid bogus warning from egcs-1.1.X */
 
    /*-- Set up signal handlers for mem access errors --*/
    signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
 #  if BZ_UNIX
-#  ifndef __DJGPP__
+#  if HAVE_SIGBUS
    signal (SIGBUS,  mySIGSEGVorSIGBUScatcher);
 #  endif
 #  endif
@@ -1891,7 +2050,7 @@ IntNative main ( IntNative argc, Char *a
    copyFileName ( progNameReally, argv[0] );
    progName = &progNameReally[0];
    for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
-      if (*tmp == PATH_SEP) progName = tmp + 1;
+      if (IS_PATH_SEP ( *tmp )) progName = tmp + 1;
 
 
    /*-- Copy flags from env var BZIP2, and 
@@ -1962,6 +2121,9 @@ IntNative main ( IntNative argc, Char *a
                case '7': blockSize100k    = 7; break;
                case '8': blockSize100k    = 8; break;
                case '9': blockSize100k    = 9; break;
+#ifdef BZ_DOS
+               case 'n': dosFileNameRule1 = False; break;
+#endif
                case 'V':
                case 'L': license();            break;
                case 'v': verbosity++; break;
diff -apruNU3 bzip2-1.0.3.orig/bzip2recover.c bzip2-1.0.3/bzip2recover.c
--- bzip2-1.0.3.orig/bzip2recover.c	2005-02-15 16:20:56.000000000 +0000
+++ bzip2-1.0.3/bzip2recover.c	2005-07-04 16:51:58.000000000 +0000
@@ -56,6 +56,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef __DJGPP__
+#  include <unistd.h>
+#endif
 
 
 /* This program records bit locations in the file to be recovered.
@@ -98,6 +101,14 @@ Char progName[BZ_MAX_FILENAME];
 MaybeUInt64 bytesOut = 0;
 MaybeUInt64 bytesIn  = 0;
 
+#define IS_DIR_SEPARATOR(c) ((c) == '/')
+#ifdef __DJGPP__
+#  undef  IS_DIR_SEPARATOR
+#  define IS_DIR_SEPARATOR(c)    ((c) == '/' || (c) == '\\' || (c) == ':')
+#  define NO_LFN_SUPPORT(name)   (pathconf ((name), _PC_NAME_MAX) <= 12)
+#  define HAS_NO_EXTENSION(name) (strrchr ((name), '.') == NULL)
+#endif
+
 
 /*---------------------------------------------------*/
 /*--- Header bytes                                ---*/
@@ -234,7 +245,9 @@ Int32 bsGetBit ( BitStream* bs )
       bs->buffLive --;
       return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
    } else {
-      Int32 retVal = getc ( bs->handle );
+      Int32 retVal;
+      errno = 0; /* to avoid program abort with ENOENT set by fopen in main. */
+      retVal = getc ( bs->handle );
       if ( retVal == EOF ) {
          if (errno != 0) readError();
          return 2;
@@ -307,11 +320,14 @@ Bool endsInBz2 ( Char* name )
 /*---------------------------------------------------*/
 
 /* This logic isn't really right when it comes to Cygwin. */
+/* This logic isn't right at all when it comes to DJGPP. */
+#ifndef __DJGPP__
 #ifdef _WIN32
 #  define  BZ_SPLIT_SYM  '\\'  /* path splitter on Windows platform */
 #else
 #  define  BZ_SPLIT_SYM  '/'   /* path splitter on Unix platform */
 #endif
+#endif
 
 #define BLOCK_HEADER_HI  0x00003141UL
 #define BLOCK_HEADER_LO  0x59265359UL
@@ -341,6 +357,9 @@ Int32 main ( Int32 argc, Char** argv )
    UInt32      buffHi, buffLo, blockCRC;
    Char*       p;
 
+   Int32       pathLen;    /* Path length in inFileName including last slash. */
+   Char*       fileName;   /* Pointer to file name (basename) in inFileName. */
+
    strcpy ( progName, argv[0] );
    inFileName[0] = outFileName[0] = 0;
 
@@ -380,6 +399,20 @@ Int32 main ( Int32 argc, Char** argv )
 
    strcpy ( inFileName, argv[1] );
 
+   /*--
+     Make a pointer to the file name in inFileName
+     and compute the length of the path string without
+     the file name part but including the last slash.
+   --*/
+   fileName = inFileName;
+   for (fileName += strlen ( inFileName ); fileName > inFileName; --fileName)
+     if (IS_DIR_SEPARATOR ( *fileName ))
+     {
+       fileName++;
+       break;
+     }
+   pathLen = fileName - inFileName;
+
    inFile = fopen ( inFileName, "rb" );
    if (inFile == NULL) {
       fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
@@ -494,6 +527,7 @@ Int32 main ( Int32 argc, Char** argv )
          wrBlock++;
       } else
       if (bitsRead == rbStart[wrBlock]) {
+#ifdef BZ_SPLIT_SYM
          /* Create the output file name, correctly handling leading paths. 
             (31.10.2001 by Sergey E. Kusikov) */
          Char* split;
@@ -509,11 +543,26 @@ Int32 main ( Int32 argc, Char** argv )
 	 }
 	 /* Now split points to the start of the basename. */
          ofs  = split - outFileName;
-         sprintf (split, "rec%5d", wrBlock+1);
-         for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
-         strcat (outFileName, inFileName + ofs);
-
-         if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
+#endif
+         if (pathLen > 0) /* Account for a possible path in inFileName. */
+           strncpy ( outFileName, inFileName, pathLen );
+         else
+           outFileName[0] = 0;
+
+         if (NO_LFN_SUPPORT ( inFileName )) /* There are only 8 characters available. */
+           sprintf ( &outFileName[pathLen], "r%4d", wrBlock+1 );
+         else
+           sprintf ( &outFileName[pathLen], "rec%4d", wrBlock+1 );
+
+         for (p = outFileName; *p != 0; p++) if (*p == ' ') *p = '0';
+         strcat (outFileName, fileName);
+
+         /* MSDOS 8.3 file name restriction. */
+         if (NO_LFN_SUPPORT ( outFileName ) && HAS_NO_EXTENSION ( fileName ))
+           strcat ( outFileName, ".bz2" );
+         else
+           /* Only if LFN support is available, append an extra extension. */
+           if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
 
          fprintf ( stderr, "   writing block %d to `%s' ...\n",
                            wrBlock+1, outFileName );
diff -apruNU3 bzip2-1.0.3.orig/bzmore bzip2-1.0.3/bzmore
--- bzip2-1.0.3.orig/bzmore	2004-10-09 11:29:36.000000000 +0000
+++ bzip2-1.0.3/bzmore	2005-07-04 16:51:58.000000000 +0000
@@ -3,7 +3,11 @@
 # Bzmore wrapped for bzip2, 
 # adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
 
-PATH="/usr/bin:$PATH"; export PATH
+pathsep=:
+if test -n "$DJGPP$djgpp"; then
+  pathsep=";"
+fi
+PATH="/dev/env/DJDIR/bin$pathsep$PATH"; export PATH
 
 prog=`echo $0 | sed 's|.*/||'`
 case "$prog" in
diff -apruNU3 bzip2-1.0.3.orig/words3 bzip2-1.0.3/words3
--- bzip2-1.0.3.orig/words3	2004-10-09 11:29:32.000000000 +0000
+++ bzip2-1.0.3/words3	2005-07-04 16:51:58.000000000 +0000
@@ -2,8 +2,8 @@
 If you got this far and the "cmp"s didn't complain, it looks
 like you're in business.  
 
-To install in /usr/bin, /usr/lib, /usr/man and /usr/include, type
-   make install
+To install in /dev/env/DJDIR/bin, /dev/env/DJDIR/lib, /dev/env/DJDIR/man and
+   /dev/env/DJDIR/include, type make install
 To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 
    make install PREFIX=/xxx/yyy
 If you are (justifiably) paranoid and want to see what 'make install'
