2007-08-30  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* src/html.c [DJGPP]: Add declaration of snprintf() if compiled
	with DJGPP 2.03.

	* src/snprintf.c: Added from DJGPP cvs tree.

	* src/vsnprntf.c: Added from DJGPP cvs tree.





diff -aprNU5 unrtf_0.20.4.orig/configure unrtf_0.20.4/configure
--- unrtf_0.20.4.orig/configure	2007-06-29 01:52:18 +0000
+++ unrtf_0.20.4/configure	2007-08-30 23:13:58 +0000
@@ -267,12 +267,12 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 : ${ac_max_here_lines=38}
 
 # Identity of this package.
 PACKAGE_NAME='unrtf'
 PACKAGE_TARNAME='unrtf'
-PACKAGE_VERSION='0.20.3'
-PACKAGE_STRING='unrtf 0.20.3'
+PACKAGE_VERSION='0.20.4'
+PACKAGE_STRING='unrtf 0.20.4'
 PACKAGE_BUGREPORT='bug-unrtf@gnu.org'
 
 ac_unique_file="src/attr.c"
 # Factoring default headers for most tests.
 ac_includes_default="\
diff -aprNU5 unrtf_0.20.4.orig/src/html.c unrtf_0.20.4/src/html.c
--- unrtf_0.20.4.orig/src/html.c	2007-08-28 22:34:38 +0000
+++ unrtf_0.20.4/src/html.c	2007-08-30 22:45:44 +0000
@@ -1008,10 +1008,19 @@ static char *Greek[] = /* Times New Roma
 #endif
 
 
 
 
+#if __DJGPP__ == 2 && __DJGPP_MINOR__ <= 3
+/*
+ *  DJGPP 2.03 requires the declaration of snprintf
+ *  because that function is not provided by the library.
+ */
+
+int
+snprintf(char *str, size_t n, const char *fmt, ...);
+#endif
 
 /*========================================================================
  * Name:	html_unisymbol_print
  * Purpose:	Outputs arbitrary unicode symbol
  * Args:	Unsigned Short.
diff -aprNU5 unrtf_0.20.4.orig/src/snprintf.c unrtf_0.20.4/src/snprintf.c
--- unrtf_0.20.4.orig/src/snprintf.c	1970-01-01 00:00:00 +0000
+++ unrtf_0.20.4/src/snprintf.c	2007-08-30 22:45:44 +0000
@@ -0,0 +1,16 @@
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+#include <stdarg.h>
+#include <stdio.h>
+
+int
+snprintf(char *str, size_t n, const char *fmt, ...)
+{
+  va_list ap;
+  int len;
+
+  va_start(ap, fmt);
+  len = vsnprintf(str, n, fmt, ap);
+  va_end(ap);
+
+  return len;
+}
diff -aprNU5 unrtf_0.20.4.orig/src/vsnprntf.c unrtf_0.20.4/src/vsnprntf.c
--- unrtf_0.20.4.orig/src/vsnprntf.c	1970-01-01 00:00:00 +0000
+++ unrtf_0.20.4/src/vsnprntf.c	2007-08-30 22:45:44 +0000
@@ -0,0 +1,66 @@
+/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <errno.h>
+#include <libc/file.h>
+
+static __inline__ void __stropenw(FILE *p, char *str, int len)
+{
+  p->_flag = _IOWRT | _IOSTRG | _IONTERM;
+  p->_ptr = str;
+  p->_cnt = len;
+}
+
+static __inline__ void __strclosew(FILE *p)
+{
+  *p->_ptr = '\0';
+}
+
+static __inline__ void __stropenr(FILE *p, const char *str)
+{
+  union {
+    char *s;
+    const char *cs;
+  } u;
+
+  u.cs = str;
+  p->_flag = _IOREAD | _IOSTRG | _IONTERM;
+  p->_ptr = p->_base = u.s;
+  p->_cnt = 0;
+  while (*str++)
+    p->_cnt++;
+  p->_bufsiz = p->_cnt;
+}
+
+int
+vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
+{
+  FILE _strbuf;
+  int len;
+
+  /* _cnt is an int in the FILE structure. To prevent wrap-around, we limit
+   * n to between 0 and INT_MAX inclusively. */
+  if (n > INT_MAX)
+  {
+    errno = EFBIG;
+    return -1;
+  }
+
+  memset(&_strbuf, 0, sizeof(_strbuf));
+
+  /* If n == 0, just querying how much space is needed. */
+  if (n > 0)
+    __stropenw(&_strbuf, str, n - 1);
+  else
+    __stropenw(&_strbuf, NULL, 0);
+
+  len = _doprnt(fmt, ap, &_strbuf);
+
+  /* Ensure nul termination */
+  if (n > 0)
+    __strclosew(&_strbuf);
+
+  return len;
+}
