summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/chunk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/utils/chunk.c')
-rw-r--r--src/libstrongswan/utils/chunk.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/libstrongswan/utils/chunk.c b/src/libstrongswan/utils/chunk.c
index 04f3eea7d..644b8060f 100644
--- a/src/libstrongswan/utils/chunk.c
+++ b/src/libstrongswan/utils/chunk.c
@@ -243,6 +243,38 @@ bool chunk_write(chunk_t chunk, char *path, char *label, mode_t mask, bool force
return good;
}
+/**
+ * Described in header.
+ */
+chunk_t chunk_from_fd(int fd)
+{
+ char buf[8096];
+ char *pos = buf;
+ ssize_t len, total = 0;
+
+ while (TRUE)
+ {
+ len = read(fd, pos, buf + sizeof(buf) - pos);
+ if (len < 0)
+ {
+ DBG1(DBG_LIB, "reading from file descriptor failed: %s",
+ strerror(errno));
+ return chunk_empty;
+ }
+ if (len == 0)
+ {
+ break;
+ }
+ total += len;
+ if (total == sizeof(buf))
+ {
+ DBG1(DBG_LIB, "buffer too small to read from file descriptor");
+ return chunk_empty;
+ }
+ }
+ return chunk_clone(chunk_create(buf, total));
+}
+
/** hex conversion digits */
static char hexdig_upper[] = "0123456789ABCDEF";
@@ -797,7 +829,7 @@ int chunk_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
chunk_t copy = *chunk;
int written = 0;
- if (!spec->hash)
+ if (!spec->hash && !spec->plus)
{
u_int chunk_len = chunk->len;
const void *new_args[] = {&chunk->ptr, &chunk_len};
@@ -810,7 +842,7 @@ int chunk_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
{
first = FALSE;
}
- else
+ else if (!spec->plus)
{
written += print_in_hook(data, ":");
}