]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: stop using strndup(), which isn't portable
authorDan Fandrich <dan@coneharvesters.com>
Mon, 10 Apr 2023 17:35:04 +0000 (10:35 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Mon, 10 Apr 2023 17:51:07 +0000 (10:51 -0700)
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.

tests/libtest/stub_gssapi.c

index c6c614bc016a735a68b169c6ce178b8d63ad075a..634dddfd01ca8a20b321efcbee629b2a54bb561f 100644 (file)
@@ -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;