From: Dan Fandrich Date: Mon, 10 Apr 2023 17:35:04 +0000 (-0700) Subject: tests: stop using strndup(), which isn't portable X-Git-Tag: curl-8_1_0~196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ed0629901ccb5b7019e3b1c0daa4550114a909f;p=thirdparty%2Fcurl.git tests: stop using strndup(), which isn't portable It's not available on Solaris 10, for example. Since this is just test code that doesn't need to use an optimized system version, replace it with the implementation copied from tool_cb_hdr.c. --- diff --git a/tests/libtest/stub_gssapi.c b/tests/libtest/stub_gssapi.c index c6c614bc01..634dddfd01 100644 --- a/tests/libtest/stub_gssapi.c +++ b/tests/libtest/stub_gssapi.c @@ -65,6 +65,17 @@ struct gss_ctx_id_t_desc_struct { char creds[MAX_CREDS_LENGTH]; }; +/* simple implementation of strndup(), which isn't portable */ +static char *my_strndup(const char *ptr, size_t len) +{ + char *copy = malloc(len + 1); + if(!copy) + return NULL; + memcpy(copy, ptr, len); + copy[len] = '\0'; + return copy; +} + OM_uint32 gss_init_sec_context(OM_uint32 *min, gss_const_cred_id_t initiator_cred_handle, gss_ctx_id_t *context_handle, @@ -280,7 +291,7 @@ OM_uint32 gss_import_name(OM_uint32 *min, return GSS_S_FAILURE; } - name = strndup(input_name_buffer->value, input_name_buffer->length); + name = my_strndup(input_name_buffer->value, input_name_buffer->length); if(!name) { *min = GSS_NO_MEMORY; return GSS_S_FAILURE;