summaryrefslogtreecommitdiff
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-09-04 16:58:01 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-09-04 16:58:01 -0700
commit1c262cae409ec55a234c89b3b74a13a77c7f595a (patch)
tree2780610d6227a3b1f64aa9398f21501ce3de774e /src/sysdep.c
parent7f59d9c856de33b97bc3f2708dcc8dadf24ee040 (diff)
parent052bd38a56ad14a7f311677051e778de6c4bdc1c (diff)
downloademacs-1c262cae409ec55a234c89b3b74a13a77c7f595a.tar.gz
emacs-1c262cae409ec55a234c89b3b74a13a77c7f595a.tar.bz2
emacs-1c262cae409ec55a234c89b3b74a13a77c7f595a.zip
Merge from trunk.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c39
1 files changed, 39 insertions, 0 deletions
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)
}
#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)