2021-01-24 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	DJGPP support added.

	* configure: DJGPP specific prefix added.
	DJGPP specific EXEEXT added.
	DJGPP specific CFLAGS added.

	* makefile.in: EXEEXT added.
	lzip will be created as link of clzip.
	doc will be created when installing.

	*testsuite/check.sh: Extension added to program names.

	* main.c: New macro NUMERIC_PATTERN replaces "00001".
	[DJGPP]: S_ISSOCK defined to 0 if not defined.  Ditto for S_ISVTX.
	io.h included to porovide setmode prototype.
	[O_BINARY, DJGPP]: unistd.h included to porovide pathconf prototype.
	Macro HAVE_LFN_SUPPORT defined according the OS used.
	(main): Added DJGPP to the systems that need to call setmode.
	(set_c_outname, set_d_outname, next_filename): SFN specific multi-file
	and extension support implemented.
	(close_and_set_permissions) [MSDOS]: Do not set permissions, it does
	not really make sense on DOS/Windows inhibiting that the file can be
	deleted.






diff -aprNU5 lzlib-1.12.orig/configure lzlib-1.12/configure
--- lzlib-1.12.orig/configure	2021-01-01 23:35:38 +0000
+++ lzlib-1.12/configure	2021-01-24 19:47:18 +0000
@@ -7,35 +7,43 @@
 
 pkgname=lzlib
 pkgversion=1.12
 soversion=1
 progname=minilzip
-progname_static=${progname}
+progname_static=${progname}'$(EXEEXT)'
 progname_shared=
-progname_lzip=${progname}
+progname_lzip=${progname}'$(EXEEXT)'
 disable_ldconfig=
 libname=lz
 srctrigger=doc/${pkgname}.texi
 
 # clear some things potentially inherited from environment.
 LC_ALL=C
 export LC_ALL
 srcdir=
-prefix=/usr/local
+prefix='/dev/env/DJDIR'
 exec_prefix='$(prefix)'
 bindir='$(exec_prefix)/bin'
 datarootdir='$(prefix)/share'
 includedir='$(prefix)/include'
 infodir='$(datarootdir)/info'
 libdir='$(exec_prefix)/lib'
 mandir='$(datarootdir)/man'
 CC=gcc
 CPPFLAGS=
-CFLAGS='-Wall -W -O2'
 LDFLAGS=
+EXEEXT=.exe
 
 # checking whether we are using GNU C.
+/bin/sh -c "${CC} --version" > /dev/null 2>&1 && { 
+	# Ensure that always old GNU extern inline semantics is used
+	# (aka -fgnu89-inline) even if ISO C99 semantics has been specified.
+	case $(${CC} --version 2>/dev/null | sed "/^.* \([1-9]\+\.[0-9]\+[.0-9]*\).*$/!d;s/^.* \([1-9]\+\.[0-9]\+[.0-9]*\).*$/\1/") in
+	[1-3].*|4.[0-1][.0-9]* )  CFLAGS=${CFLAGS='-g2 -O2 -march=i386 -mtune=i586 -Wall -pedantic -save-temps'};;
+	* )                       CFLAGS=${CFLAGS='-g2 -O2 -fgnu89-inline -march=i386 -mtune=i586 -Wall -pedantic -save-temps'};;
+	esac
+}
 /bin/sh -c "${CC} --version" > /dev/null 2>&1 || { CC=cc ; CFLAGS=-O2 ; }
 
 # Loop over all args
 args=
 no_create=
@@ -190,10 +198,11 @@ echo "libdir = ${libdir}"
 echo "mandir = ${mandir}"
 echo "CC = ${CC}"
 echo "CPPFLAGS = ${CPPFLAGS}"
 echo "CFLAGS = ${CFLAGS}"
 echo "LDFLAGS = ${LDFLAGS}"
+echo "EXEEXT = ${EXEEXT}"
 rm -f Makefile
 cat > Makefile << EOF
 # Makefile for Lzlib - Compression library for the lzip format
 # Copyright (C) 2009-2021 Antonio Diaz Diaz.
 # This file was generated automatically by configure. Don't edit.
@@ -221,9 +230,10 @@ libdir = ${libdir}
 mandir = ${mandir}
 CC = ${CC}
 CPPFLAGS = ${CPPFLAGS}
 CFLAGS = ${CFLAGS}
 LDFLAGS = ${LDFLAGS}
+EXEEXT = ${EXEEXT}
 EOF
 cat "${srcdir}/Makefile.in" >> Makefile
 
 echo "OK. Now you can run make."
diff -aprNU5 lzlib-1.12.orig/main.c lzlib-1.12/main.c
--- lzlib-1.12.orig/main.c	2021-01-01 23:35:38 +0000
+++ lzlib-1.12/main.c	2021-01-24 21:10:42 +0000
@@ -20,10 +20,11 @@
    corrupt or invalid input file, 3 for an internal consistency error
    (eg, bug) which caused minilzip to panic.
 */
 
 #define _FILE_OFFSET_BITS 64
+#define NUMERIC_PATTERN "00001"
 
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <signal.h>
@@ -52,17 +53,31 @@
 #endif
 #if defined(__DJGPP__)
 #define S_ISSOCK(x) 0
 #define S_ISVTX 0
 #endif
+#ifndef S_ISVTX
+#define S_ISVTX 0
+#endif
 #endif
 
 #include "carg_parser.h"
 #include "lzlib.h"
 
 #ifndef O_BINARY
 #define O_BINARY 0
+#define HAVE_LFN_SUPPORT(name) (1)
+#else
+#ifdef __DJGPP__
+#include <unistd.h>
+#define HAVE_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
+#define IS_TAR(name)           (((name)[0] == 't' || (name)[0] == 'T') && \
+                                ((name)[1] == 'a' || (name)[1] == 'A') && \
+                                ((name)[2] == 'r' || (name)[2] == 'R'))
+#else
+#define HAVE_LFN_SUPPORT(name) (0)
+#endif
 #endif
 
 #if CHAR_BIT != 8
 #error "Environments where CHAR_BIT != 8 are not supported."
 #endif
@@ -402,16 +417,109 @@ static int extension_index( const char *
 
 
 static void set_c_outname( const char * const name, const bool force_ext,
                            const bool multifile )
   {
-  output_filename = resize_buffer( output_filename, strlen( name ) + 5 +
-                                   strlen( known_extensions[0].from ) + 1 );
-  strcpy( output_filename, name );
-  if( multifile ) strcat( output_filename, "00001" );
-  if( force_ext || multifile )
-    strcat( output_filename, known_extensions[0].from );
+  if( HAVE_LFN_SUPPORT(name) )
+    {
+    output_filename = resize_buffer( output_filename, strlen( name ) + 5 +
+                                     strlen( known_extensions[0].from ) + 1 );
+    strcpy( output_filename, name );
+    if( multifile ) strcat( output_filename, NUMERIC_PATTERN );
+    if( force_ext || multifile )
+      strcat( output_filename, known_extensions[0].from );
+    }
+  else
+    {
+    // For plain DOS there are filename length limitations (8.3).
+    //
+    // uncompressed name     compressed name
+    //   filename.ext    -->   filename.exl
+    //   filename.ex     -->   filename.exl
+    //   filename.e      -->   filename.elz
+
+    size_t name_ext_len, name_len, str_len = strlen( name );
+    for( name_len = str_len; name_len && name[name_len] != '.'; name_len-- )
+      ;
+
+    {
+    const bool is_tar = IS_TAR( &(name[name_len + 1]) ) ? true : false;
+    const char* const suffix = is_tar ? known_extensions[1].from : known_extensions[0].from;
+    size_t ext_len = str_len - name_len;
+    if( ext_len == 1 || name_len == 0)
+      {
+      // File name has no extension so simply append the whole extension.
+      const size_t suffix_len = strlen(suffix);
+      name_len = ext_len == 1 && str_len > 1 ? --str_len : str_len;
+      name_ext_len = name_len + suffix_len;
+
+      str_len = multifile ? name_ext_len + sizeof NUMERIC_PATTERN - 1 : name_ext_len;
+      output_filename = resize_buffer( output_filename, str_len + 1);
+
+      memcpy( output_filename, name, name_len );
+      memcpy( output_filename + name_len, suffix, suffix_len);
+      output_filename[name_ext_len] = '\0';
+      }
+    else
+      {
+      // File name has an extension so only a part of the extension can be appended.
+      if( ext_len > 2 )
+        {
+        // Only one character left for extension.
+        name_ext_len = name_len + 1 + 2;                                 // Dot plus 2 extension chars
+
+        str_len = multifile ? name_ext_len + 1 + sizeof NUMERIC_PATTERN - 1 : name_ext_len + 1;
+        output_filename = resize_buffer( output_filename, str_len + 1);  // and 1 extension char.
+
+        if( is_tar )
+          {
+          memcpy( output_filename, name, name_len );
+          memcpy( output_filename + name_len, suffix, strlen( suffix ));
+          }
+        else
+          {
+          memcpy( output_filename, name, name_ext_len );
+          output_filename[name_ext_len] = suffix[1];
+          }
+        output_filename[++name_ext_len] = '\0';
+        }
+      else
+        {
+        // Two characters left for extension.
+        name_ext_len = name_len + 1 + 1;                                 // Dot plus 1 extension char
+
+        str_len = multifile ? name_ext_len + 2 + sizeof NUMERIC_PATTERN - 1: name_ext_len + 2;
+        output_filename = resize_buffer( output_filename, str_len + 1);  // and 2 extension chars.
+
+        memcpy( output_filename, name, name_ext_len);
+        output_filename[name_ext_len] = suffix[1];
+        output_filename[++name_ext_len] = suffix[2];
+        output_filename[++name_ext_len] = '\0';
+        }
+      }
+    }
+
+    if( multifile )
+      {
+      size_t i, k;
+
+      /*  Move extension.  */
+      size_t minor_index = 8 + name_ext_len - name_len;
+      size_t major_index = name_len < 4 ? str_len > 12 ? minor_index : str_len : minor_index;
+
+      if( major_index != name_ext_len )
+        for( name_len--, k = major_index, i = name_ext_len; i > name_len; i--, k-- )
+          output_filename[k] = output_filename[i];
+      else
+        k = --name_len;
+
+      /*  Insert numeric pattern.  */
+      minor_index = name_len < 3 ? i : 2;
+      for( output_filename[k--] = '1'; k > minor_index; k-- )
+        output_filename[k] = '0';
+      }
+    }
   }
 
 
 static void set_d_outname( const char * const name, const int eindex )
   {
@@ -429,11 +537,26 @@ static void set_d_outname( const char *
       return;
       }
     }
   output_filename = resize_buffer( output_filename, name_len + 4 + 1 );
   strcpy( output_filename, name );
-  strcat( output_filename, ".out" );
+  if( HAVE_LFN_SUPPORT(name) )
+    strcat( output_filename, ".out" );
+  else
+    {
+    if( name_len == 0 )
+      strcpy( output_filename, "_out" );  /* No leading dot allowed.  */
+    else
+      {
+      int n;
+      for( n = name_len - 1; n > -1 && output_filename[n] != '.'; n-- )
+        ;
+      if( n > 0 )
+        output_filename[n] = '\0';
+      strcat( output_filename, ".out" );
+      }
+    }
   if( verbosity >= 1 )
     fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'\n",
              program_name, name, output_filename );
   }
 
@@ -567,11 +690,15 @@ static void close_and_set_permissions( c
   if( in_statsp )
     {
     const mode_t mode = in_statsp->st_mode;
     /* fchown will in many cases return with EPERM, which can be safely ignored. */
     if( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) == 0 )
+#ifdef MSDOS
+      warning = false;
+#else
       { if( fchmod( outfd, mode ) != 0 ) warning = true; }
+#endif
     else
       if( errno != EPERM ||
           fchmod( outfd, mode & ~( S_ISUID | S_ISGID | S_ISVTX ) ) != 0 )
         warning = true;
     }
@@ -631,19 +758,37 @@ static int writeblock( const int fd, con
   }
 
 
 static bool next_filename( void )
   {
-  const unsigned name_len = strlen( output_filename );
-  const unsigned ext_len = strlen( known_extensions[0].from );
-  int i, j;
-  if( name_len >= ext_len + 5 )				/* "*00001.lz" */
-    for( i = name_len - ext_len - 1, j = 0; j < 5; --i, ++j )
+  if( HAVE_LFN_SUPPORT(output_filename) )
+    {
+    const unsigned name_len = strlen( output_filename );
+    const unsigned ext_len = strlen( known_extensions[0].from );
+    int i, j;
+    if( name_len >= ext_len + 5 )				/* "*00001.lz" */
+      for( i = name_len - ext_len - 1, j = 0; j < 5; --i, ++j )
+        {
+        if( output_filename[i] < '9' ) { ++output_filename[i]; return true; }
+        else output_filename[i] = '0';
+        }
+    }
+  else
+    {
+    size_t name_len = strlen( output_filename );
+    for( ; name_len && output_filename[name_len] != '.'; name_len-- )
+      ;
+    if( --name_len > 3 )				/* "*00001" */
       {
-      if( output_filename[i] < '9' ) { ++output_filename[i]; return true; }
-      else output_filename[i] = '0';
+      int i;
+      for( i = name_len; name_len - i < 5; i-- )
+        {
+        if( output_filename[i] < '9' ) { ++output_filename[i]; return true; }
+        else output_filename[i] = '0';
+        }
       }
+    }
   return false;
   }
 
 
 static int do_compress( struct LZ_Encoder * const encoder,
diff -aprNU5 lzlib-1.12.orig/Makefile.in lzlib-1.12/Makefile.in
--- lzlib-1.12.orig/Makefile.in	2020-05-24 22:38:14 +0000
+++ lzlib-1.12/Makefile.in	2021-01-24 21:23:30 +0000
@@ -27,23 +27,23 @@ lib$(libname).a : lzlib.o
 	$(AR) -rcs $@ $<
 
 lib$(libname).so.$(pkgversion) : lzlib_sh.o
 	$(CC) $(LDFLAGS) $(CFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $<
 
-$(progname) : $(objs) lib$(libname).a
+$(progname)$(EXEEXT) : $(objs) lib$(libname).a
 	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs) lib$(libname).a
 
 $(progname)_shared : $(objs) lib$(libname).so.$(pkgversion)
 	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs) lib$(libname).so.$(pkgversion)
 
-bbexample : bbexample.o lib$(libname).a
+bbexample$(EXEEXT) : bbexample.o lib$(libname).a
 	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ bbexample.o lib$(libname).a
 
-ffexample : ffexample.o lib$(libname).a
+ffexample$(EXEEXT) : ffexample.o lib$(libname).a
 	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ ffexample.o lib$(libname).a
 
-lzcheck : lzcheck.o lib$(libname).a
+lzcheck$(EXEEXT) : lzcheck.o lib$(libname).a
 	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ lzcheck.o lib$(libname).a
 
 main.o : main.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
 
@@ -73,17 +73,17 @@ info : $(VPATH)/doc/$(pkgname).info
 $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
 	cd $(VPATH)/doc && makeinfo $(pkgname).texi
 
 man : $(VPATH)/doc/$(progname).1
 
-$(VPATH)/doc/$(progname).1 : $(progname)
-	help2man -n 'reduces the size of files' -o $@ --no-info ./$(progname)
+$(VPATH)/doc/$(progname).1 : $(progname)$(EXEEXT)
+	help2man -n 'reduces the size of files' -o $@ --no-info ./$(progname)$(EXEEXT)
 
 Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
 	./config.status
 
-check : $(progname) bbexample ffexample lzcheck
+check : $(progname)$(EXEEXT) bbexample$(EXEEXT) ffexample$(EXEEXT) lzcheck$(EXEEXT)
 	@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
 
 install : install-lib install-info
 install-strip : install-lib-strip install-info
 install-compress : install-lib install-info-compress
@@ -91,11 +91,11 @@ install-strip-compress : install-lib-str
 install-bin-compress : install-bin install-man-compress
 install-bin-strip-compress : install-bin-strip install-man-compress
 
 install-bin : all
 	if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
-	$(INSTALL_PROGRAM) ./$(progname_lzip) "$(DESTDIR)$(bindir)/$(progname)"
+	$(INSTALL_PROGRAM) ./$(progname_lzip)$(EXEEXT) "$(DESTDIR)$(bindir)/$(progname)$(EXEEXT)"
 
 install-bin-strip : all
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
 
 install-lib : all
@@ -120,37 +120,37 @@ install-lib : all
 	fi
 
 install-lib-strip : all
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-lib
 
-install-info :
+install-info : info
 	if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
 	-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*
 	$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(pkgname).info"
 	-if $(CAN_RUN_INSTALLINFO) ; then \
 	  install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info" ; \
 	fi
 
 install-info-compress : install-info
 	lzip -v -9 "$(DESTDIR)$(infodir)/$(pkgname).info"
 
-install-man :
+install-man : man
 	if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
 	-rm -f "$(DESTDIR)$(mandir)/man1/$(progname).1"*
 	$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(DESTDIR)$(mandir)/man1/$(progname).1"
 
 install-man-compress : install-man
 	lzip -v -9 "$(DESTDIR)$(mandir)/man1/$(progname).1"
 
 install-as-lzip : install-bin
-	-rm -f "$(DESTDIR)$(bindir)/lzip"
-	cd "$(DESTDIR)$(bindir)" && ln -s $(progname) lzip
+	-rm -f "$(DESTDIR)$(bindir)/lzip$(EXEEXT)"
+	cd "$(DESTDIR)$(bindir)" && stubify -g lzip.exe | stubedit lzip.exe runfile=$(progname)$(EXEEXT)
 
 uninstall : uninstall-info uninstall-lib
 
 uninstall-bin :
-	-rm -f "$(DESTDIR)$(bindir)/$(progname)"
+	-rm -f "$(DESTDIR)$(bindir)/$(progname)$(EXEEXT)"
 
 uninstall-lib :
 	-rm -f "$(DESTDIR)$(includedir)/$(libname)lib.h"
 	-rm -f "$(DESTDIR)$(libdir)/lib$(libname).a"
 	-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so"
@@ -193,11 +193,11 @@ dist : doc
 	  $(DISTNAME)/testsuite/test_em.txt.lz
 	rm -f $(DISTNAME)
 	lzip -v -9 $(DISTNAME).tar
 
 clean :
-	-rm -f $(progname) $(objs) lzlib.o lib$(libname).a
+	-rm -f $(progname)$(EXEEXT) $(objs) lzlib.o lib$(libname).a
 	-rm -f $(progname)_shared lzlib_sh.o lib$(libname).so*
-	-rm -f bbexample bbexample.o ffexample ffexample.o lzcheck lzcheck.o
+	-rm -f bbexample$(EXEEXT) bbexample.o ffexample$(EXEEXT) ffexample.o lzcheck$(EXEEXT) lzcheck.o
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -aprNU5 lzlib-1.12.orig/testsuite/check.sh lzlib-1.12/testsuite/check.sh
--- lzlib-1.12.orig/testsuite/check.sh	2021-01-01 23:35:38 +0000
+++ lzlib-1.12/testsuite/check.sh	2021-01-24 18:48:38 +0000
@@ -7,14 +7,14 @@
 
 LC_ALL=C
 export LC_ALL
 objdir=`pwd`
 testdir=`cd "$1" ; pwd`
-LZIP="${objdir}"/minilzip
-BBEXAMPLE="${objdir}"/bbexample
-FFEXAMPLE="${objdir}"/ffexample
-LZCHECK="${objdir}"/lzcheck
+LZIP="${objdir}"/minilzip.exe
+BBEXAMPLE="${objdir}"/bbexample.exe
+FFEXAMPLE="${objdir}"/ffexample.exe
+LZCHECK="${objdir}"/lzcheck.exe
 framework_failure() { echo "failure in testing framework" ; exit 1 ; }
 
 if [ ! -f "${LZIP}" ] || [ ! -x "${LZIP}" ] ; then
 	echo "${LZIP}: cannot execute"
 	exit 1
