aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2014-04-22 17:04:23 -0500
committerPeter Seebach <peter.seebach@windriver.com>2014-04-22 17:04:23 -0500
commit5392d265efd29e374080dca062ff1d1a834bfbed (patch)
treefedf5a7db8974343ae3848ada4d5da7956f8873f /pseudo_util.c
parent1c0d6d9a3cbb193a1c2f0e4f57a70781e7b69931 (diff)
downloadpseudo-5392d265efd29e374080dca062ff1d1a834bfbed.tar.gz
pseudo-5392d265efd29e374080dca062ff1d1a834bfbed.tar.bz2
pseudo-5392d265efd29e374080dca062ff1d1a834bfbed.zip
xattr support and other path stuff: reduce allocation and copying
The xattr first-pass implementation was allocating a buffer to hold the name and value for a set operation, then pseudo_client was allocating *another* buffer to hold the path and those two values. pseudo_client_op develops more nuanced argument handling, and also uses a static buffer for the extended paths it sometimes needs. So for the typical use case, only occasional operations will need to reallocate/expand the buffer, and we'll be down to copying things into that buffer once per operation, instead of having two alloc/free pairs and two copies. And of course, that wasn't two alloc/free pairs, it was one alloc/free pair and one alloc without a free. Whoops. Signed-off-by: Peter Seebach <peter.seebach@windriver.com>
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index a4a14b4..f20dbec 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1432,3 +1432,40 @@ pseudo_stat64_from32(struct stat64 *buf64, const struct stat *buf) {
buf64->st_mtime = buf->st_mtime;
buf64->st_ctime = buf->st_ctime;
}
+
+/* pretty-dump some data.
+ * expects to be called using pseudo_debug_call() so it doesn't have
+ * to do debug checks.
+ */
+void
+pseudo_dump_data(char *name, const void *v, size_t len) {
+ char hexbuf[128];
+ char asciibuf[32];
+ const unsigned char *base = v;
+ const unsigned char *data = base;
+ int remaining = len;
+ pseudo_diag("%s at %p [%d byte%s]:\n",
+ name ? name : "data", v, (int) len, len == 1 ? "" : "s");
+ while (remaining > 0) {
+ char *hexptr = hexbuf;
+ char *asciiptr = asciibuf;
+ for (int i = 0; i < 16 && i < remaining; ++i) {
+ hexptr += snprintf(hexptr, 4, "%02x ", data[i]);
+ if (isprint(data[i])) {
+ *asciiptr++ = data[i];
+ } else {
+ *asciiptr++ = '.';
+ }
+ if (i % 4 == 3) {
+ *hexptr++ = ' ';
+ }
+ }
+ *hexptr = '\0';
+ *asciiptr = '\0';
+ pseudo_diag("0x%06x %-50.50s '%.16s'\n",
+ (int) (data - base),
+ hexbuf, asciibuf);
+ remaining = remaining - 16;
+ data = data + 16;
+ }
+}