summaryrefslogtreecommitdiff
path: root/db-4.8.30/clib/printf.c
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
committerJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
commit54df2afaa61c6a03cbb4a33c9b90fa572b6d07b8 (patch)
tree18147b92b969d25ffbe61935fb63035cac820dd0 /db-4.8.30/clib/printf.c
Berkeley DB 4.8 with rust build script for linux.
Diffstat (limited to 'db-4.8.30/clib/printf.c')
-rw-r--r--db-4.8.30/clib/printf.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/db-4.8.30/clib/printf.c b/db-4.8.30/clib/printf.c
new file mode 100644
index 0000000..37187a4
--- /dev/null
+++ b/db-4.8.30/clib/printf.c
@@ -0,0 +1,142 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2005-2009 Oracle. All rights reserved.
+ *
+ * $Id$
+ */
+
+#include "db_config.h"
+
+#include "db_int.h"
+
+/*
+ * printf --
+ *
+ * PUBLIC: #ifndef HAVE_PRINTF
+ * PUBLIC: int printf __P((const char *, ...));
+ * PUBLIC: #endif
+ */
+#ifndef HAVE_PRINTF
+int
+#ifdef STDC_HEADERS
+printf(const char *fmt, ...)
+#else
+printf(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ size_t len;
+ char buf[2048]; /* !!!: END OF THE STACK DON'T TRUST SPRINTF. */
+
+#ifdef STDC_HEADERS
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ len = (size_t)vsnprintf(buf, sizeof(buf), fmt, ap);
+#ifdef HAVE_BREW
+ /*
+ * The BREW vsnprintf function return count includes the trailing
+ * nul-termination character.
+ */
+ if (len > 0 && len <= sizeof(buf) && buf[len - 1] == '\0')
+ --len;
+#endif
+
+ va_end(ap);
+
+ /*
+ * We implement printf/fprintf with fwrite, because Berkeley DB uses
+ * fwrite in other places.
+ */
+ return (fwrite(
+ buf, sizeof(char), (size_t)len, stdout) == len ? (int)len: -1);
+}
+#endif /* HAVE_PRINTF */
+
+/*
+ * fprintf --
+ *
+ * PUBLIC: #ifndef HAVE_PRINTF
+ * PUBLIC: int fprintf __P((FILE *, const char *, ...));
+ * PUBLIC: #endif
+ */
+#ifndef HAVE_PRINTF
+int
+#ifdef STDC_HEADERS
+fprintf(FILE *fp, const char *fmt, ...)
+#else
+fprintf(fp, fmt, va_alist)
+ FILE *fp;
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ size_t len;
+ char buf[2048]; /* !!!: END OF THE STACK DON'T TRUST SPRINTF. */
+
+#ifdef STDC_HEADERS
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ len = vsnprintf(buf, sizeof(buf), fmt, ap);
+#ifdef HAVE_BREW
+ /*
+ * The BREW vsnprintf function return count includes the trailing
+ * nul-termination character.
+ */
+ if (len > 0 && len <= sizeof(buf) && buf[len - 1] == '\0')
+ --len;
+#endif
+
+ va_end(ap);
+
+ /*
+ * We implement printf/fprintf with fwrite, because Berkeley DB uses
+ * fwrite in other places.
+ */
+ return (fwrite(
+ buf, sizeof(char), (size_t)len, fp) == len ? (int)len: -1);
+}
+#endif /* HAVE_PRINTF */
+
+/*
+ * vfprintf --
+ *
+ * PUBLIC: #ifndef HAVE_PRINTF
+ * PUBLIC: int vfprintf __P((FILE *, const char *, va_list));
+ * PUBLIC: #endif
+ */
+#ifndef HAVE_PRINTF
+int
+vfprintf(fp, fmt, ap)
+ FILE *fp;
+ const char *fmt;
+ va_list ap;
+{
+ size_t len;
+ char buf[2048]; /* !!!: END OF THE STACK DON'T TRUST SPRINTF. */
+
+ len = vsnprintf(buf, sizeof(buf), fmt, ap);
+#ifdef HAVE_BREW
+ /*
+ * The BREW vsnprintf function return count includes the trailing
+ * nul-termination character.
+ */
+ if (len > 0 && len <= sizeof(buf) && buf[len - 1] == '\0')
+ --len;
+#endif
+
+ /*
+ * We implement printf/fprintf with fwrite, because Berkeley DB uses
+ * fwrite in other places.
+ */
+ return (fwrite(
+ buf, sizeof(char), (size_t)len, fp) == len ? (int)len: -1);
+}
+#endif /* HAVE_PRINTF */