2016-11-05 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* contrib/gregbook/wpng.c [O_BINARY]: Define SET_BINARY macro.
	Sets file into binary mode.  If file is connected to a tty,
	SIGINT and SIGQUIT are reenabled.
	(main): Use SET_BINARY to switch stin/stdout into binary mode.

	* contrib/pngminus/png2pnm.c [O_BINARY]: Define SET_BINARY macro.
	Sets file into binary mode.  If file is connected to a tty,
	SIGINT and SIGQUIT are reenabled.
	(main): Use SET_BINARY to switch stin/stdout into binary mode.

	* contrib/pngminus/pnm2png.c [O_BINARY]: Define SET_BINARY macro.
	Sets file into binary mode.  If file is connected to a tty,
	SIGINT and SIGQUIT are reenabled.
	(main): Use SET_BINARY to switch stin/stdout into binary mode.

	* png.h: Add port info.




diff -aprNU5 libpng-1.6.26.orig/contrib/gregbook/wpng.c libpng-1.6.26/contrib/gregbook/wpng.c
--- libpng-1.6.26.orig/contrib/gregbook/wpng.c	2016-10-20 00:07:20 -0513
+++ libpng-1.6.26/contrib/gregbook/wpng.c	2016-11-05 17:20:36 -0513
@@ -91,10 +91,17 @@
 #define VERSION   "2.00 of 2 June 2007"
 #define APPNAME   "Simple PGM/PPM/PAM to PNG Converter"
 
 #if defined(__MSDOS__) || defined(__OS2__)
 #  define DOS_OS2_W32
+#  ifdef __DJGPP__
+#    if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#      define __gnuc_extension__  __extension__
+#    else
+#      define __gnuc_extension__
+#    endif
+#  endif
 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
 #  ifndef __GNUC__   /* treat Win32 native ports of gcc as Unix environments */
 #    define DOS_OS2_W32
 #  endif
 #endif
@@ -117,10 +124,32 @@
 #      include <pc.h>
 #      define getch() getkey()  /* GRR:  need getche() */
 #    else
 #      include <conio.h>        /* for getche() console input */
 #    endif
+#    ifdef __DJGPP__
+#      include <unistd.h>       /* declares isatty() */
+#      include <sys/exceptn.h>  /* declares __djgpp_set_ctrl_c() */
+
+       /* Putting stdin/stdout in binary mode if it is connected to
+          the console, would make it impossible for the user to
+          interrupt the program through Ctrl-C or Ctrl-Break.  */
+
+       /* This is DJGPP-specific.  By default, switching console
+          to binary mode disables SIGINT and SIGQUIT.  But we want
+          terminal reads to be interruptible.  */
+
+#      define set_binary_mode  setmode
+#      define SET_BINARY(fd)                                  \
+       (__gnuc_extension__                                    \
+         ({                                                   \
+            int _old_mode = set_binary_mode((fd), O_BINARY);  \
+            if (isatty(fd)) __djgpp_set_ctrl_c(1);            \
+            _old_mode;                                        \
+         })                                                   \
+       )
+#    endif /* __DJGPP__ */
 #  endif /* ?__EMX__ */
 #  define FGETS(buf,len,stream)  dos_kbd_gets(buf,len)
 #else
 #  include <unistd.h>           /* for isatty() prototype */
 #  define FGETS fgets
@@ -303,12 +332,17 @@ int main(int argc, char **argv)
               ":  must give input filename or provide image data via stdin\n");
             ++error;
         } else {
 #ifdef DOS_OS2_W32
             /* some buggy C libraries require BOTH setmode() and fdopen(bin) */
+#  ifdef SET_BINARY
+            SET_BINARY(fileno(stdin));
+            SET_BINARY(fileno(stdout));
+#  else
             setmode(fileno(stdin), O_BINARY);
             setmode(fileno(stdout), O_BINARY);
+#  endif
 #endif
             if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) {
                 fprintf(stderr, PROGNAME
                   ":  unable to reopen stdin in binary mode\n");
                 ++error;
diff -aprNU5 libpng-1.6.26.orig/contrib/pngminus/png2pnm.c libpng-1.6.26/contrib/pngminus/png2pnm.c
--- libpng-1.6.26.orig/contrib/pngminus/png2pnm.c	2016-10-20 00:07:20 -0513
+++ libpng-1.6.26/contrib/pngminus/png2pnm.c	2016-11-05 17:20:36 -0513
@@ -18,10 +18,43 @@
 #include <mem.h>
 #include <fcntl.h>
 #endif
 #include <zlib.h>
 
+#ifdef O_BINARY
+# ifdef __DJGPP__
+#  include <io.h>           /* declares setmode() */
+#  define set_binary_mode  setmode
+
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#   define __gnuc_extension__  __extension__
+#  else
+#   define __gnuc_extension__
+#  endif
+
+#  include <unistd.h>       /* declares isatty() */
+#  include <sys/exceptn.h>  /* declares __djgpp_set_ctrl_c() */
+
+   /* Putting stdin/stdout in binary mode if it is connected to
+      the console, would make it impossible for the user to
+      interrupt the program through Ctrl-C or Ctrl-Break.  */
+
+   /* This is DJGPP-specific.  By default, switching console
+      to binary mode disables SIGINT and SIGQUIT.  But we want
+      terminal reads to be interruptible.  */
+
+#  define SET_BINARY(fd)                                  \
+   (__gnuc_extension__                                    \
+     ({                                                   \
+        int _old_mode = set_binary_mode((fd), O_BINARY);  \
+        if (isatty(fd)) __djgpp_set_ctrl_c(1);            \
+        _old_mode;                                        \
+     })                                                   \
+   )
+# endif /* __DJGPP__ */
+#endif /* O_BINARY */
+
 #ifndef BOOL
 #define BOOL unsigned char
 #endif
 #ifndef TRUE
 #define TRUE (BOOL) 1
@@ -140,10 +173,16 @@ int main(int argc, char *argv[])
   if ((raw) && (fp_wr == stdout))
   {
     setmode (STDOUT, O_BINARY);
   }
 #endif
+#ifdef SET_BINARY
+  if (fp_rd == stdin)
+    SET_BINARY(stdin);
+  if ((raw) && (fp_wr == stdout))
+    SET_BINARY(stdout);
+#endif
 
   /* call the conversion program itself */
   if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
   {
     fprintf (stderr, "PNG2PNM\n");
diff -aprNU5 libpng-1.6.26.orig/contrib/pngminus/pnm2png.c libpng-1.6.26/contrib/pngminus/pnm2png.c
--- libpng-1.6.26.orig/contrib/pngminus/pnm2png.c	2016-10-20 00:07:20 -0513
+++ libpng-1.6.26/contrib/pngminus/pnm2png.c	2016-11-05 17:20:36 -0513
@@ -19,10 +19,43 @@
 #include <mem.h>
 #include <fcntl.h>
 #endif
 #include <zlib.h>
 
+#ifdef O_BINARY
+# ifdef __DJGPP__
+#  include <io.h>           /* declares setmode() */
+#  define set_binary_mode  setmode
+
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#   define __gnuc_extension__  __extension__
+#  else
+#   define __gnuc_extension__
+#  endif
+
+#  include <unistd.h>       /* declares isatty() */
+#  include <sys/exceptn.h>  /* declares __djgpp_set_ctrl_c() */
+
+   /* Putting stdin/stdout in binary mode if it is connected to
+      the console, would make it impossible for the user to
+      interrupt the program through Ctrl-C or Ctrl-Break.  */
+
+   /* This is DJGPP-specific.  By default, switching console
+      to binary mode disables SIGINT and SIGQUIT.  But we want
+      terminal reads to be interruptible.  */
+
+#  define SET_BINARY(fd)                                  \
+   (__gnuc_extension__                                    \
+     ({                                                   \
+        int _old_mode = set_binary_mode((fd), O_BINARY);  \
+        if (isatty(fd)) __djgpp_set_ctrl_c(1);            \
+        _old_mode;                                        \
+     })                                                   \
+   )
+# endif /* __DJGPP__ */
+#endif /* O_BINARY */
+
 #ifndef BOOL
 #define BOOL unsigned char
 #endif
 #ifndef TRUE
 #define TRUE (BOOL) 1
@@ -139,10 +172,16 @@ int main(int argc, char *argv[])
   if (fp_wr == stdout)
   {
     setmode (STDOUT, O_BINARY);
   }
 #endif
+#ifdef SET_BINARY
+  if (fp_rd == stdin)
+    SET_BINARY(stdin);
+  if ((raw) && (fp_wr == stdout))
+    SET_BINARY(stdout);
+#endif
 
   /* call the conversion program itself */
   if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)
   {
     fprintf (stderr, "PNM2PNG\n");
diff -aprNU5 libpng-1.6.26.orig/png.h libpng-1.6.26/png.h
--- libpng-1.6.26.orig/png.h	2016-10-20 00:07:20 -0513
+++ libpng-1.6.26/png.h	2016-11-05 17:20:18 -0513
@@ -313,11 +313,11 @@
  * skip to the end of this file and read the section entitled 'simplified API'.
  */
 
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.6.26"
-#define PNG_HEADER_VERSION_STRING " libpng version 1.6.26 - October 20, 2016\n"
+#define PNG_HEADER_VERSION_STRING " libpng version 1.6.26 - October 20, 2016  (DJGPP port (r1))\n"
 
 #define PNG_LIBPNG_VER_SONUM   16
 #define PNG_LIBPNG_VER_DLLNUM  16
 
 /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
