diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-06 08:54:36 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-06 08:54:36 +0100 |
commit | 7ebc5824153f6ba8ac7385f6965bedd1b984cf5d (patch) | |
tree | 7349f0eb454987a54453a8ed03aac26ec0042d23 /src | |
parent | 724cc3119f24596fca4cd8a66e9733c48142172c (diff) | |
download | fastd-7ebc5824153f6ba8ac7385f6965bedd1b984cf5d.tar fastd-7ebc5824153f6ba8ac7385f6965bedd1b984cf5d.zip |
handshake: get rid of stpcpy
stpcpy was added in POSIX.1-2008 and is not present on some systems like
Android.
Diffstat (limited to 'src')
-rw-r--r-- | src/handshake.c | 20 |
1 files changed, 14 insertions, 6 deletions
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; } |