2019-06-07  Juan M. Guerrero  <juan.guerrero@gmx.de>


	* srclib/getprogname.c (getprogname) [__DJGPP__]:  Implementation of
	DJGPP support.

	* srclib/progname.c [MSDOS]: Define new macro GET_LAST_SLASH to find
	the last directory separator character.  On DOS-Like systems these
	are slash, backslash or colon.  For POSIX this is simple a slash.

	* srclib/stdint.in.h [__DJGPP__]:  For DJGPP, the typedef of gl_[u]int32_t
	must be signed long int as in stdint.h.







diff -aprNU5 libiconv-1.16.orig/src/iconv.c libiconv-1.16/src/iconv.c
--- libiconv-1.16.orig/src/iconv.c	2019-04-26 18:50:12 +0000
+++ libiconv-1.16/src/iconv.c	2019-06-07 19:56:50 +0000
@@ -41,10 +41,64 @@
 #include "safe-read.h"
 #include "xalloc.h"
 #include "uniwidth.h"
 #include "uniwidth/cjk.h"
 
+#if O_BINARY
+# ifdef __DJGPP__
+/* MS-DOS and similar non-Posix systems have some peculiarities:
+    - they use both `/' and `\\' as directory separator in file names;
+    - they can have a drive letter X: prepended to a file name;
+   These are all parameterized here.  */
+
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#   define __gnuc_extension__  __extension__
+#  else
+#   define __gnuc_extension__
+#  endif
+#  include <libc/unconst.h>
+#  define IS_DIR_SEPARATOR(c)  ((c) == '/' || (c) == '\\' || (c) == ':')
+
+#  define CANONICALIZE_PATH(path)                         \
+   (__gnuc_extension__                                    \
+     ({                                                   \
+        if ((path))                                       \
+        {                                                 \
+          char *_p = unconst((path), char *);             \
+          for (; *_p; _p++)                               \
+            if (*_p == '\\')                              \
+              *_p = '/';                                  \
+        }                                                 \
+        (path);                                           \
+     })                                                   \
+   )
+
+#  define initialize_main(argv_0)                         \
+   (__gnuc_extension__                                    \
+     ({                                                   \
+        extern char __djgpp_program_invocation_name[];    \
+        char *_name = CANONICALIZE_PATH((argv_0));        \
+                                                          \
+        int i;                                            \
+        for (i = 0; _name[i] && i < FILENAME_MAX; i++)    \
+          __djgpp_program_invocation_name[i] = _name[i];  \
+        for (; i; i--)                                    \
+          if (__djgpp_program_invocation_name[i] == '.')  \
+          {                                               \
+            __djgpp_program_invocation_name[i] = '\0';    \
+            break;                                        \
+          }                                               \
+        __djgpp_program_invocation_name;                  \
+     })                                                   \
+   )
+# else  /* !__DJGPP__  */
+#  define initialize_main(argvp)
+# endif  /* !__DJGPP__  */
+#else  /* !O_BINARY  */
+# define initialize_main(argvp)
+#endif  /* !O_BINARY  */
+
 /* Ensure that iconv_no_i18n does not depend on libintl.  */
 #ifdef NO_I18N
 #include <stdarg.h>
 static void
 error (int status, int errnum, const char *message, ...)
diff -aprNU5 libiconv-1.16.orig/srclib/getprogname.c libiconv-1.16/srclib/getprogname.c
--- libiconv-1.16.orig/srclib/getprogname.c	2019-04-26 18:29:00 +0000
+++ libiconv-1.16/srclib/getprogname.c	2019-06-07 19:56:50 +0000
@@ -49,10 +49,14 @@
 # include <stdio.h>
 # include <fcntl.h>
 # include <sys/procfs.h>
 #endif
 
+#ifdef __DJGPP__
+# include <crt0.h>
+#endif
+
 #include "dirname.h"
 
 #ifndef HAVE_GETPROGNAME             /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
 char const *
 getprogname (void)
@@ -242,10 +246,12 @@ getprogname (void)
               return memcpy (namecopy, name, namelen);
             }
         }
     }
   return NULL;
+# elif __DJGPP__
+  return last_component (__crt0_argv ? __crt0_argv[0] : __dos_argv0);
 # else
 #  error "getprogname module not ported to this OS"
 # endif
 }
 
diff -aprNU5 libiconv-1.16.orig/srclib/progname.c libiconv-1.16/srclib/progname.c
--- libiconv-1.16.orig/srclib/progname.c	2019-01-06 08:51:40 +0000
+++ libiconv-1.16/srclib/progname.c	2019-06-07 19:56:50 +0000
@@ -25,10 +25,44 @@
 #include <errno.h> /* get program_invocation_name declaration */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+/* MS-DOS and similar non-Posix systems have some peculiarities:
+    - they use both `/' and `\\' as directory separator in file names;
+    - they can have a drive letter X: prepended to a file name;
+   These are all parameterized here.  */
+
+#ifdef MSDOS
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define __gnuc_extension__  __extension__
+# else
+#  define __gnuc_extension__
+# endif
+# include <libc/unconst.h>
+# undef  IS_SLASH
+# define IS_SLASH(c)  ((c) == '/' || (c) == '\\' || (c) == ':')
+# define GET_LAST_SLASH(filename)              \
+  (__gnuc_extension__                          \
+    ({                                         \
+      char *_slash = NULL;                     \
+      if ((filename))                          \
+      {                                        \
+        _slash = unconst((filename), char *);  \
+        while (*_slash++)                      \
+          ;                                    \
+        while ((--_slash - (filename)))        \
+          if (IS_SLASH(*_slash))               \
+            break;                             \
+      }                                        \
+      _slash;                                  \
+    })                                         \
+  )
+#else
+# define GET_LAST_SLASH(filename)  (strrchr((filename), '/'))
+#endif
+
 
 /* String containing name the program is called with.
    To be initialized by main().  */
 const char *program_name = NULL;
 
@@ -54,13 +88,21 @@ set_program_name (const char *argv0)
       fputs ("A NULL argv[0] was passed through an exec system call.\n",
              stderr);
       abort ();
     }
 
-  slash = strrchr (argv0, '/');
+  slash = GET_LAST_SLASH (argv0);
   base = (slash != NULL ? slash + 1 : argv0);
-  if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
+  if (base - argv0 >= 7 && (strncmp (base - 7, "/.libs/", 7) == 0
+#ifdef MSDOS
+     || strncmp (base - 7, "\\.libs/", 7) == 0
+     || strncmp (base - 7, "\\.libs\\", 7) == 0
+     || strncmp (base - 7, "/_libs/", 7) == 0
+     || strncmp (base - 7, "\\_libs/", 7) == 0
+     || strncmp (base - 7, "\\_libs\\", 7) == 0
+#endif
+     ))
     {
       argv0 = base;
       if (strncmp (base, "lt-", 3) == 0)
         {
           argv0 = base + 3;
diff -aprNU5 libiconv-1.16.orig/srclib/stdint.in.h libiconv-1.16/srclib/stdint.in.h
--- libiconv-1.16.orig/srclib/stdint.in.h	2019-01-06 08:51:40 +0000
+++ libiconv-1.16/srclib/stdint.in.h	2019-06-07 20:09:20 +0000
@@ -160,12 +160,17 @@ typedef unsigned short int gl_uint16_t;
 # define int16_t gl_int16_t
 # define uint16_t gl_uint16_t
 
 # undef int32_t
 # undef uint32_t
+#if __DJGPP__
+typedef long int gl_int32_t;
+typedef unsigned long int gl_uint32_t;
+#else  /* !__DJGPP__ */
 typedef int gl_int32_t;
 typedef unsigned int gl_uint32_t;
+#endif /* !__DJGPP__ */
 # define int32_t gl_int32_t
 # define uint32_t gl_uint32_t
 
 /* If the system defines INT64_MAX, assume int64_t works.  That way,
    if the underlying platform defines int64_t to be a 64-bit long long
