From 7ebc5824153f6ba8ac7385f6965bedd1b984cf5d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 6 Jan 2015 08:54:36 +0100 Subject: handshake: get rid of stpcpy stpcpy was added in POSIX.1-2008 and is not present on some systems like Android. --- src/handshake.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/handshake.c') diff --git a/src/handshake.c b/src/handshake.c index 0a47987..a55844f 100644 --- a/src/handshake.c +++ b/src/handshake.c @@ -103,19 +103,27 @@ static inline uint32_t as_uint(const fastd_handshake_record_t *record) { /** Generates a zero-separated list of supported methods */ static uint8_t * create_method_list(size_t *len) { + size_t n, i; + for (n = 0; conf.methods[n].name; n++) { + } + *len = 0; + size_t lens[n]; - size_t i; - for (i = 0; conf.methods[i].name; i++) - *len += strlen(conf.methods[i].name) + 1; + for (i = 0; i < n; i++) { + lens[i] = strlen(conf.methods[i].name) + 1; + *len += lens[i]; + } uint8_t *ret = fastd_alloc(*len); (*len)--; - char *ptr = (char *)ret; + uint8_t *ptr = ret; - for (i = 0; conf.methods[i].name; i++) - ptr = stpcpy(ptr, conf.methods[i].name) + 1; + for (i = 0; i < n; i++) { + memcpy(ptr, conf.methods[i].name, lens[i]); + ptr += lens[i]; + } return ret; } -- cgit v1.2.3