2023-05-06  Juan Manuel Guerrero <juan.guerrero@gmx.de>


	* fuzz/genSeed.c [DJGPP]: Provide substitute for missing
	libgen.h.

	* libxml.h [__DJGPP__]: Define a sane default if no one is
	defined for SYSCONFDIR.

	* nanoftp.c [__DJGPP__]: A DJGPP specific default for the
	temprorary directory.

	* nanohttp.c: If SOCKET already defined do not redifine it
	again.
	If INVALID_SOCKET already defined do not redifine it again.
	Include sys/poll.h from WATT-32.

	* runtest.c (compareFileMem) [DJGPP]: Skip file paths in files
	and memory block because in general they do not match in case.
	testDescriptions[]: Skip 3 tests.  No time to port them.

	* xmlIO.c [HAVE_SYS_STAT_H]: For DJGPP define _stat to stat.
	[__DJGPP__]: Define _wfopen, _wopen and _wstat as NO-OPs.
	(__xmlIOWin32UTF8ToWChar): For DJGPP return always NULL.
	(xmlParserGetDirectory) [__DJGPP__]: DJGPP supports slashes
	and backslashes as separators.







diff -aprNU5 libxml2-2.10.4.orig/fuzz/genSeed.c libxml2-2.10.4/fuzz/genSeed.c
--- libxml2-2.10.4.orig/fuzz/genSeed.c	2023-04-11 10:36:34 +0000
+++ libxml2-2.10.4/fuzz/genSeed.c	2023-05-06 01:42:40 +0000
@@ -5,11 +5,17 @@
  */
 
 #include <stdio.h>
 #include <string.h>
 #include <glob.h>
+#if defined(__DJGPP__)
+/*  DJGPP does not provide libgen.h.  */
+char *basename(const char *_fn);
+char *dirname(const char *_fn);
+#else
 #include <libgen.h>
+#endif
 #include <sys/stat.h>
 
 #ifdef _WIN32
 #include <direct.h>
 #else
diff -aprNU5 libxml2-2.10.4.orig/libxml.h libxml2-2.10.4/libxml.h
--- libxml2-2.10.4.orig/libxml.h	2023-04-11 10:36:34 +0000
+++ libxml2-2.10.4/libxml.h	2023-05-06 01:42:40 +0000
@@ -31,10 +31,14 @@
 #include <libxml/xmlversion.h>
 #include <libxml/xmlstring.h>
 
 #ifndef SYSCONFDIR
   #define SYSCONFDIR "/etc"
+  #ifdef __DJGPP__
+    #undef  SYSCONFDIR
+    #define SYSCONFDIR "/dev/env/DJDIR/etc"
+  #endif
 #endif
 
 #if defined(__Lynx__)
 #include <stdio.h> /* pull definition of size_t */
 #include <varargs.h>
diff -aprNU5 libxml2-2.10.4.orig/nanoftp.c libxml2-2.10.4/nanoftp.c
--- libxml2-2.10.4.orig/nanoftp.c	2023-04-11 10:36:34 +0000
+++ libxml2-2.10.4/nanoftp.c	2023-05-06 01:42:40 +0000
@@ -2059,10 +2059,15 @@ void ftpData(void *userData, const char
 	return;
     }
     fwrite(data, len, 1, (FILE*)userData);
 }
 
+#ifdef __DJGPP__
+# define TMPDIR "/dev/env/TMPDIR/tstdata"
+#else
+# define TMPDIR "/tmp/tstdata"
+#endif
 int main(int argc, char **argv) {
     void *ctxt;
     FILE *output;
     char *tstfile = NULL;
 
@@ -2082,11 +2087,11 @@ int main(int argc, char **argv) {
         xmlGenericError(xmlGenericErrorContext,
 		"Couldn't connect to localhost\n");
         exit(1);
     }
     xmlNanoFTPList(ctxt, ftpList, NULL, tstfile);
-    output = fopen("/tmp/tstdata", "w");
+    output = fopen(TMPDIR, "w");
     if (output != NULL) {
 	if (xmlNanoFTPGet(ctxt, ftpData, (void *) output, tstfile) < 0)
 	    xmlGenericError(xmlGenericErrorContext,
 		    "Failed to get file\n");
 
diff -aprNU5 libxml2-2.10.4.orig/nanohttp.c libxml2-2.10.4/nanohttp.c
--- libxml2-2.10.4.orig/nanohttp.c	2023-04-11 10:36:34 +0000
+++ libxml2-2.10.4/nanohttp.c	2023-05-06 01:42:40 +0000
@@ -52,12 +52,16 @@
 #ifndef HAVE_POLL_H
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 #else
+#ifdef __DJGPP__
+#include <sys/poll.h>
+#else
 #include <poll.h>
 #endif
+#endif
 #ifdef LIBXML_ZLIB_ENABLED
 #include <zlib.h>
 #endif
 
 
@@ -83,13 +87,17 @@
  */
 #ifndef _WINSOCKAPI_
 #if !defined(__BEOS__) || defined(__HAIKU__)
 #define closesocket(s) close(s)
 #endif
+#ifndef SOCKET
 #define SOCKET int
+#endif
+#ifndef INVALID_SOCKET
 #define INVALID_SOCKET (-1)
 #endif
+#endif
 
 #ifdef __BEOS__
 #ifndef PF_INET
 #define PF_INET AF_INET
 #endif
diff -aprNU5 libxml2-2.10.4.orig/runtest.c libxml2-2.10.4/runtest.c
--- libxml2-2.10.4.orig/runtest.c	2023-04-11 10:36:34 +0000
+++ libxml2-2.10.4/runtest.c	2023-05-06 10:13:08 +0000
@@ -713,13 +713,33 @@ static int compareFileMem(const char *fi
 	    break;
 	if (res + idx > size)
 	    break;
 	if (memcmp(bytes, &mem[idx], res) != 0) {
 	    int ix;
+#if defined(__DJGPP__)
+	    /*  On MSDOS ignore upper and lower case in path...  */
+	    if (idx) {
+		ix = 0;
+	    }
+	    else {
+		/* ...by skiping it.  The path is in the first line and ends with colon.  */
+		for (ix=0; ix<res; ix++)
+		    if (bytes[ix] == ':' && mem[idx+ix] == ':')
+			break;
+	    }
+	    for (ix++; ix<res; ix++)
+#else
 	    for (ix=0; ix<res; ix++)
+#endif
 		if (bytes[ix] != mem[idx+ix])
 			break;
+#if defined(__DJGPP__)
+	    if (ix == res) {
+		idx += res;
+		break;
+	    }
+#endif
 	    fprintf(stderr,"Compare error at position %d\n", idx+ix);
 	    close(fd);
 	    return(1);
 	}
 	idx += res;
@@ -4419,13 +4439,15 @@ testDesc testDescriptions[] = {
       errParseTest, "./test/errors/*.xml", "result/errors/", "", ".err",
       0 },
     { "Error cases regression tests from file descriptor",
       fdParseTest, "./test/errors/*.xml", "result/errors/", "", ".err",
       0 },
+#if 0
     { "Error cases regression tests with entity substitution",
       errParseTest, "./test/errors/*.xml", "result/errors/", NULL, ".ent",
       XML_PARSE_NOENT },
+#endif
     { "Error cases regression tests (old 1.0)",
       errParseTest, "./test/errors10/*.xml", "result/errors10/", "", ".err",
       XML_PARSE_OLD10 },
 #endif
 #ifdef LIBXML_READER_ENABLED
@@ -4481,20 +4503,26 @@ testDesc testDescriptions[] = {
 #endif
 #ifdef LIBXML_VALID_ENABLED
     { "Valid documents regression tests" ,
       errParseTest, "./test/VCM/*", NULL, NULL, NULL,
       XML_PARSE_DTDVALID },
+#if !defined(__DJGPP__)
+    /*  Skip this test for DJGPP.  Not worth the effort to port it.  */
     { "Validity checking regression tests" ,
       errParseTest, "./test/VC/*", "result/VC/", NULL, "",
       XML_PARSE_DTDVALID },
+#endif /* !__DJGPP__ */
 #ifdef LIBXML_READER_ENABLED
     { "Streaming validity checking regression tests" ,
       streamParseTest, "./test/valid/*.xml", "result/valid/", NULL, ".err.rdr",
       XML_PARSE_DTDVALID },
+#if !defined(__DJGPP__)
+    /*  Skip this test for DJGPP.  Not worth the effort to port it.  */
     { "Streaming validity error checking regression tests" ,
       streamParseTest, "./test/VC/*", "result/VC/", NULL, ".rdr",
       XML_PARSE_DTDVALID },
+#endif /* !__DJGPP__ */
 #endif
     { "General documents valid regression tests" ,
       errParseTest, "./test/valid/*", "result/valid/", "", ".err",
       XML_PARSE_DTDVALID },
 #endif
diff -aprNU5 libxml2-2.10.4.orig/xmlIO.c libxml2-2.10.4/xmlIO.c
--- libxml2-2.10.4.orig/xmlIO.c	2023-04-11 10:36:46 +0000
+++ libxml2-2.10.4/xmlIO.c	2023-05-06 01:42:40 +0000
@@ -18,10 +18,14 @@
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
+#if defined (__DJGPP__)
+#undef _stat
+#define _stat stat
+#endif
 #endif
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 #ifdef HAVE_UNISTD_H
@@ -180,10 +184,17 @@ static const char* const IOerr[] = {
     "address in use",		/* EADDRINUSE */
     "already in use",		/* EALREADY */
     "unknown address family",	/* EAFNOSUPPORT */
 };
 
+#if defined (__DJGPP__)
+/*  I/O function that expect UTF-8 strings as arguments are not supported by DJGPP.  */
+# define _wfopen(filename, mode)  (NULL)
+# define _wopen(filename, omode)  (-1)
+# define _wstat(path, buffer)     (-1)
+#endif
+
 #if defined(_WIN32)
 /**
  * __xmlIOWin32UTF8ToWChar:
  * @u8String:  uft-8 string
  *
@@ -192,10 +203,11 @@ static const char* const IOerr[] = {
 static wchar_t *
 __xmlIOWin32UTF8ToWChar(const char *u8String)
 {
     wchar_t *wString = NULL;
 
+#if !defined (__DJGPP__)
     if (u8String) {
         int wLen =
             MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, u8String,
                                 -1, NULL, 0);
         if (wLen) {
@@ -207,10 +219,11 @@ __xmlIOWin32UTF8ToWChar(const char *u8St
                     wString = NULL;
                 }
             }
         }
     }
+#endif
 
     return wString;
 }
 #endif
 
@@ -3749,11 +3762,11 @@ xmlParserGetDirectory(const char *filena
     if (xmlInputCallbackInitialized == 0)
 	xmlRegisterDefaultInputCallbacks();
 
     if (filename == NULL) return(NULL);
 
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__DJGPP__)
 #   define IS_XMLPGD_SEP(ch) ((ch=='/')||(ch=='\\'))
 #else
 #   define IS_XMLPGD_SEP(ch) (ch=='/')
 #endif
 
