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.
This commit is contained in:
parent
e91caa6011
commit
55e5faa189
6 changed files with 52 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
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*
|
||||
|
|
|
@ -3071,6 +3071,8 @@ fi
|
|||
|
||||
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>]],
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
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.
|
||||
|
|
|
@ -240,6 +240,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
|
|||
#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
|
||||
|
|
|
@ -90,6 +90,8 @@
|
|||
* 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.
|
||||
|
||||
|
|
39
src/sysdep.c
39
src/sysdep.c
|
@ -1811,6 +1811,45 @@ strerror (int errnum)
|
|||
}
|
||||
#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
|
||||
|
||||
int
|
||||
emacs_open (const char *path, int oflag, int mode)
|
||||
|
|
Loading…
Add table
Reference in a new issue