From 0244c0d86cd86e4cc90e0c112c6edeafdfb558c2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 22 Feb 2017 14:53:11 +0100 Subject: strcmp instead of memcmp --- src/util/strings.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/strings.c b/src/util/strings.c index 2b51d3e52..291255344 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2005-2013 GNUnet e.V. + Copyright (C) 2005-2017 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -17,7 +17,6 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - /** * @file util/strings.c * @brief string functions @@ -89,6 +88,37 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...) } +/** + * Convert a peer path to a human-readable string. + * + * @param pids array of PIDs to convert to a string + * @param num_pids length of the @a pids array + * @return string representing the array of @a pids + */ +char * +GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids, + unsigned int num_pids) +{ + char *buf; + size_t off; + size_t plen = num_pids * 5 + 1; + + off = 0; + buf = GNUNET_malloc (plen); + for (unsigned int i = 0; + i < num_pids; + i++) + { + off += GNUNET_snprintf (&buf[off], + plen - off, + "%s%s", + GNUNET_i2s (&pids[i]), + (i == num_pids -1) ? "" : "-"); + } + return buf; +} + + /** * Given a buffer of a given size, find "count" * 0-terminated strings in the buffer and assign -- cgit v1.2.3