summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-01-06 08:54:36 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-01-06 08:54:36 +0100
commit7ebc5824153f6ba8ac7385f6965bedd1b984cf5d (patch)
tree7349f0eb454987a54453a8ed03aac26ec0042d23 /src
parent724cc3119f24596fca4cd8a66e9733c48142172c (diff)
downloadfastd-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.c20
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;
}