summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/chunk.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-11-01 13:32:07 +0100
committerYves-Alexis Perez <corsac@debian.org>2013-11-01 13:32:07 +0100
commit5313d2d78ca150515f7f5eb39801c100690b6b29 (patch)
treec78e420367283bb1b16f14210b12687cdfbd26eb /src/libstrongswan/utils/chunk.c
parent6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349 (diff)
downloadvyos-strongswan-5313d2d78ca150515f7f5eb39801c100690b6b29.tar.gz
vyos-strongswan-5313d2d78ca150515f7f5eb39801c100690b6b29.zip
Imported Upstream version 5.1.1
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, ":");
}