* configure.in (snprintf): New check.
* nt/config.nt (HAVE_SNPRINTF): New macro.
* src/sysdep.c (snprintf) [! HAVE_SNPRINTF]: New function.
+2011-08-31 Paul Eggert <eggert@cs.ucla.edu>
+
+ * configure.in (snprintf): New check.
+
2011-08-30 Paul Eggert <eggert@cs.ucla.edu>
* configure.in (opsys): Change pattern to *-*-linux*
AC_FUNC_FORK
+AC_CHECK_FUNCS(snprintf)
+
dnl Adapted from Haible's version.
AC_CACHE_CHECK([for nl_langinfo and CODESET], emacs_cv_langinfo_codeset,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
+2011-08-31 Paul Eggert <eggert@cs.ucla.edu>
+
+ * config.nt (HAVE_SNPRINTF): New macro.
+
2011-07-28 Paul Eggert <eggert@cs.ucla.edu>
Assume freestanding C89 headers, string.h, stdlib.h.
#define HAVE_SETSOCKOPT 1
#define HAVE_GETSOCKNAME 1
#define HAVE_GETPEERNAME 1
+#define HAVE_SNPRINTF 1
#define HAVE_LANGINFO_CODESET 1
/* Local (unix) sockets are not supported. */
#undef HAVE_SYS_UN_H
* process.c (make_process): Use printmax_t, not int, to format
process-name gensyms.
+ * sysdep.c (snprintf) [! HAVE_SNPRINTF]: New function.
+
* term.c (produce_glyphless_glyph): Make sprintf buffer a bit bigger
to avoid potential buffer overrun.
}
#endif /* not WINDOWSNT */
#endif /* ! HAVE_STRERROR */
+
+#ifndef HAVE_SNPRINTF
+/* Approximate snprintf as best we can on ancient hosts that lack it. */
+int
+snprintf (char *buf, size_t bufsize, char const *format, ...)
+{
+ ptrdiff_t size = min (bufsize, PTRDIFF_MAX);
+ ptrdiff_t nbytes = size - 1;
+ va_list ap;
+
+ if (size)
+ {
+ va_start (ap, format);
+ nbytes = doprnt (buf, size, format, 0, ap);
+ va_end (ap);
+ }
+
+ if (nbytes == size - 1)
+ {
+ /* Calculate the length of the string that would have been created
+ had the buffer been large enough. */
+ char stackbuf[4000];
+ char *b = stackbuf;
+ ptrdiff_t bsize = sizeof stackbuf;
+ va_start (ap, format);
+ nbytes = evxprintf (&b, &bsize, stackbuf, -1, format, ap);
+ va_end (ap);
+ if (b != stackbuf)
+ xfree (b);
+ }
+
+ if (INT_MAX < nbytes)
+ {
+ errno = EOVERFLOW;
+ return -1;
+ }
+ return nbytes;
+}
+#endif
\f
int
emacs_open (const char *path, int oflag, int mode)