summaryrefslogtreecommitdiff
path: root/src/support/scratch.c
diff options
context:
space:
mode:
authorDavid Hows <david.hows@mongodb.com>2016-06-24 17:05:13 +1000
committerDavid Hows <david.hows@mongodb.com>2016-06-24 17:05:13 +1000
commitd8fb874fc40989cb9675e56ca80b3b64e6fa2ee3 (patch)
tree6f03ed5cde97aedc762215c14d23ee5305998a2b /src/support/scratch.c
parentfb1663e6fc800be97c0ddc697b6f939dc610e08e (diff)
parent1f4aaa4490a82cf947afdabbb9214ee5b1850d13 (diff)
downloadmongo-ac1162a35b4f17f8352398eceeda73646d8253c4.tar.gz
Merge branch 'develop' of github.com:wiredtiger/wiredtiger into mongodb-3.4mongodb-3.3.9mongodb-3.3.10mongodb-3.0.1
Diffstat (limited to 'src/support/scratch.c')
-rw-r--r--src/support/scratch.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/support/scratch.c b/src/support/scratch.c
index 1881f8ad5a5..69987ebc852 100644
--- a/src/support/scratch.c
+++ b/src/support/scratch.c
@@ -135,6 +135,64 @@ __wt_buf_catfmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...)
}
/*
+ * __wt_buf_set_printable --
+ * Set the contents of the buffer to a printable representation of a
+ * byte string.
+ */
+const char *
+__wt_buf_set_printable(
+ WT_SESSION_IMPL *session, const void *p, size_t size, WT_ITEM *buf)
+{
+ if (__wt_raw_to_esc_hex(session, p, size, buf)) {
+ buf->data = "[Error]";
+ buf->size = strlen("[Error]");
+ }
+ return (buf->data);
+}
+
+/*
+ * __wt_buf_set_size --
+ * Set the contents of the buffer to a printable representation of a
+ * byte size.
+ */
+const char *
+__wt_buf_set_size(
+ WT_SESSION_IMPL *session, uint64_t size, bool exact, WT_ITEM *buf)
+{
+ WT_DECL_RET;
+
+ if (size >= WT_EXABYTE)
+ ret = __wt_buf_fmt(session, buf,
+ "%" PRIu64 "EB", size / WT_EXABYTE);
+ else if (size >= WT_PETABYTE)
+ ret = __wt_buf_fmt(session, buf,
+ "%" PRIu64 "PB", size / WT_PETABYTE);
+ else if (size >= WT_TERABYTE)
+ ret = __wt_buf_fmt(session, buf,
+ "%" PRIu64 "TB", size / WT_TERABYTE);
+ else if (size >= WT_GIGABYTE)
+ ret = __wt_buf_fmt(session, buf,
+ "%" PRIu64 "GB", size / WT_GIGABYTE);
+ else if (size >= WT_MEGABYTE)
+ ret = __wt_buf_fmt(session, buf,
+ "%" PRIu64 "MB", size / WT_MEGABYTE);
+ else if (size >= WT_KILOBYTE)
+ ret = __wt_buf_fmt(session, buf,
+ "%" PRIu64 "KB", size / WT_KILOBYTE);
+ else
+ ret = __wt_buf_fmt(session, buf, "%" PRIu64 "B", size);
+
+ if (ret == 0 && exact && size >= WT_KILOBYTE)
+ ret = __wt_buf_catfmt(session, buf, " (%" PRIu64 ")", size);
+
+ if (ret != 0) {
+ buf->data = "[Error]";
+ buf->size = strlen("[Error]");
+ }
+ return (buf->data);
+}
+
+/*
* __wt_scr_alloc_func --
* Scratch buffer allocation function.
*/