2013-05-15 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.

	* pngpriv.h: Use [v]snprintf() from DJGPP's repository to support
	djdev203 builds.




diff -aprNU5 libpng-1.6.2.orig/contrib/gregbook/wpng.c libpng-1.6.2/contrib/gregbook/wpng.c
--- libpng-1.6.2.orig/contrib/gregbook/wpng.c	2013-04-25 12:24:44 +0000
+++ libpng-1.6.2/contrib/gregbook/wpng.c	2013-05-15 00:11:56 +0000
@@ -117,10 +117,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)                                  \
+       (__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 +325,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.2.orig/contrib/pngminus/png2pnm.c libpng-1.6.2/contrib/pngminus/png2pnm.c
--- libpng-1.6.2.orig/contrib/pngminus/png2pnm.c	2013-04-25 12:24:44 +0000
+++ libpng-1.6.2/contrib/pngminus/png2pnm.c	2013-05-15 00:11:56 +0000
@@ -18,10 +18,37 @@
 #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
+
+#  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)                                  \
+   (__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
@@ -138,10 +165,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.2.orig/contrib/pngminus/pnm2png.c libpng-1.6.2/contrib/pngminus/pnm2png.c
--- libpng-1.6.2.orig/contrib/pngminus/pnm2png.c	2013-04-25 12:24:44 +0000
+++ libpng-1.6.2/contrib/pngminus/pnm2png.c	2013-05-15 00:11:54 +0000
@@ -18,10 +18,37 @@
 #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
+
+#  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)                                  \
+   (__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
@@ -137,10 +164,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.2.orig/png.h libpng-1.6.2/png.h
--- libpng-1.6.2.orig/png.h	2013-04-25 12:24:44 +0000
+++ libpng-1.6.2/png.h	2013-05-15 23:41:22 +0000
@@ -384,11 +384,11 @@
  */
 
 /* Version information for png.h - this should match the version in png.c */
 #define PNG_LIBPNG_VER_STRING "1.6.2"
 #define PNG_HEADER_VERSION_STRING \
-     " libpng version 1.6.2 - April 25, 2013\n"
+     " libpng version 1.6.2 - April 25, 2013  (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: */
diff -aprNU5 libpng-1.6.2.orig/pngpriv.h libpng-1.6.2/pngpriv.h
--- libpng-1.6.2.orig/pngpriv.h	2013-04-25 12:24:44 +0000
+++ libpng-1.6.2/pngpriv.h	2013-05-15 23:49:20 +0000
@@ -373,10 +373,14 @@
     defined(_WIN32) || defined(__WIN32__)
 #  include <windows.h>  /* defines _WINDOWS_ macro */
 #endif
 #endif /* PNG_VERSION_INFO_ONLY */
 
+#ifdef __DJGPP__
+#  include "djgpp/snprintf.h"
+#endif
+
 /* Moved here around 1.5.0beta36 from pngconf.h */
 /* Users may want to use these so they are not private.  Any library
  * functions that are passed far data must be model-independent.
  */
 
