aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2011-08-31 15:18:16 -0700
committerPaul Eggert2011-08-31 15:18:16 -0700
commit55e5faa18952a5608cf653f8fd268a7645a2f876 (patch)
tree5056032a9e9270cb79639f2e1fa515d0bbde8d8b
parente91caa6011949f45790cd131883b2b3b26d6a0a2 (diff)
downloademacs-55e5faa18952a5608cf653f8fd268a7645a2f876.tar.gz
emacs-55e5faa18952a5608cf653f8fd268a7645a2f876.zip
Add a stub for snprintf, for ancient hosts lacking it.
* configure.in (snprintf): New check. * nt/config.nt (HAVE_SNPRINTF): New macro. * src/sysdep.c (snprintf) [! HAVE_SNPRINTF]: New function.
-rw-r--r--ChangeLog4
-rw-r--r--configure.in2
-rw-r--r--nt/ChangeLog4
-rw-r--r--nt/config.nt1
-rw-r--r--src/ChangeLog2
-rw-r--r--src/sysdep.c39
6 files changed, 52 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f38dbf71ca..c973a82e8a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
12011-08-31 Paul Eggert <eggert@cs.ucla.edu>
2
3 * configure.in (snprintf): New check.
4
12011-08-30 Paul Eggert <eggert@cs.ucla.edu> 52011-08-30 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 * configure.in (opsys): Change pattern to *-*-linux* 7 * configure.in (opsys): Change pattern to *-*-linux*
diff --git a/configure.in b/configure.in
index 715e8278df2..dcc2bdb99d1 100644
--- a/configure.in
+++ b/configure.in
@@ -3071,6 +3071,8 @@ fi
3071 3071
3072AC_FUNC_FORK 3072AC_FUNC_FORK
3073 3073
3074AC_CHECK_FUNCS(snprintf)
3075
3074dnl Adapted from Haible's version. 3076dnl Adapted from Haible's version.
3075AC_CACHE_CHECK([for nl_langinfo and CODESET], emacs_cv_langinfo_codeset, 3077AC_CACHE_CHECK([for nl_langinfo and CODESET], emacs_cv_langinfo_codeset,
3076 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]], 3078 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
diff --git a/nt/ChangeLog b/nt/ChangeLog
index edbd1a1c1d4..f3c57c7e0d0 100644
--- a/nt/ChangeLog
+++ b/nt/ChangeLog
@@ -1,3 +1,7 @@
12011-08-31 Paul Eggert <eggert@cs.ucla.edu>
2
3 * config.nt (HAVE_SNPRINTF): New macro.
4
12011-07-28 Paul Eggert <eggert@cs.ucla.edu> 52011-07-28 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 Assume freestanding C89 headers, string.h, stdlib.h. 7 Assume freestanding C89 headers, string.h, stdlib.h.
diff --git a/nt/config.nt b/nt/config.nt
index 3436bc989e0..ae3807538c0 100644
--- a/nt/config.nt
+++ b/nt/config.nt
@@ -240,6 +240,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
240#define HAVE_SETSOCKOPT 1 240#define HAVE_SETSOCKOPT 1
241#define HAVE_GETSOCKNAME 1 241#define HAVE_GETSOCKNAME 1
242#define HAVE_GETPEERNAME 1 242#define HAVE_GETPEERNAME 1
243#define HAVE_SNPRINTF 1
243#define HAVE_LANGINFO_CODESET 1 244#define HAVE_LANGINFO_CODESET 1
244/* Local (unix) sockets are not supported. */ 245/* Local (unix) sockets are not supported. */
245#undef HAVE_SYS_UN_H 246#undef HAVE_SYS_UN_H
diff --git a/src/ChangeLog b/src/ChangeLog
index 463f2965baa..0ba2df42186 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -90,6 +90,8 @@
90 * process.c (make_process): Use printmax_t, not int, to format 90 * process.c (make_process): Use printmax_t, not int, to format
91 process-name gensyms. 91 process-name gensyms.
92 92
93 * sysdep.c (snprintf) [! HAVE_SNPRINTF]: New function.
94
93 * term.c (produce_glyphless_glyph): Make sprintf buffer a bit bigger 95 * term.c (produce_glyphless_glyph): Make sprintf buffer a bit bigger
94 to avoid potential buffer overrun. 96 to avoid potential buffer overrun.
95 97
diff --git a/src/sysdep.c b/src/sysdep.c
index 57fff94f552..e20bd591da1 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1811,6 +1811,45 @@ strerror (int errnum)
1811} 1811}
1812#endif /* not WINDOWSNT */ 1812#endif /* not WINDOWSNT */
1813#endif /* ! HAVE_STRERROR */ 1813#endif /* ! HAVE_STRERROR */
1814
1815#ifndef HAVE_SNPRINTF
1816/* Approximate snprintf as best we can on ancient hosts that lack it. */
1817int
1818snprintf (char *buf, size_t bufsize, char const *format, ...)
1819{
1820 ptrdiff_t size = min (bufsize, PTRDIFF_MAX);
1821 ptrdiff_t nbytes = size - 1;
1822 va_list ap;
1823
1824 if (size)
1825 {
1826 va_start (ap, format);
1827 nbytes = doprnt (buf, size, format, 0, ap);
1828 va_end (ap);
1829 }
1830
1831 if (nbytes == size - 1)
1832 {
1833 /* Calculate the length of the string that would have been created
1834 had the buffer been large enough. */
1835 char stackbuf[4000];
1836 char *b = stackbuf;
1837 ptrdiff_t bsize = sizeof stackbuf;
1838 va_start (ap, format);
1839 nbytes = evxprintf (&b, &bsize, stackbuf, -1, format, ap);
1840 va_end (ap);
1841 if (b != stackbuf)
1842 xfree (b);
1843 }
1844
1845 if (INT_MAX < nbytes)
1846 {
1847 errno = EOVERFLOW;
1848 return -1;
1849 }
1850 return nbytes;
1851}
1852#endif
1814 1853
1815int 1854int
1816emacs_open (const char *path, int oflag, int mode) 1855emacs_open (const char *path, int oflag, int mode)