Blame support/resolv_response_context_duplicate.c

Packit Service 87bc11
/* Duplicate a response context used in DNS resolver tests.
Packit Service 87bc11
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service 87bc11
   This file is part of the GNU C Library.
Packit Service 87bc11
Packit Service 87bc11
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 87bc11
   modify it under the terms of the GNU Lesser General Public
Packit Service 87bc11
   License as published by the Free Software Foundation; either
Packit Service 87bc11
   version 2.1 of the License, or (at your option) any later version.
Packit Service 87bc11
Packit Service 87bc11
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 87bc11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 87bc11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 87bc11
   Lesser General Public License for more details.
Packit Service 87bc11
Packit Service 87bc11
   You should have received a copy of the GNU Lesser General Public
Packit Service 87bc11
   License along with the GNU C Library; if not, see
Packit Service 87bc11
   <https://www.gnu.org/licenses/>.  */
Packit Service 87bc11
Packit Service 87bc11
#include <string.h>
Packit Service 87bc11
#include <support/resolv_test.h>
Packit Service 87bc11
#include <support/support.h>
Packit Service 87bc11
Packit Service 87bc11
struct resolv_response_context *
Packit Service 87bc11
resolv_response_context_duplicate (const struct resolv_response_context *ctx)
Packit Service 87bc11
{
Packit Service 87bc11
  struct resolv_response_context *result = xmalloc (sizeof (*result));
Packit Service 87bc11
  memcpy (result, ctx, sizeof (*result));
Packit Service 87bc11
  if (result->client_address != NULL)
Packit Service 87bc11
    {
Packit Service 87bc11
      result->client_address = xmalloc (result->client_address_length);
Packit Service 87bc11
      memcpy (result->client_address, ctx->client_address,
Packit Service 87bc11
              result->client_address_length);
Packit Service 87bc11
    }
Packit Service 87bc11
  result->query_buffer = xmalloc (result->query_length);
Packit Service 87bc11
  memcpy (result->query_buffer, ctx->query_buffer, result->query_length);
Packit Service 87bc11
  return result;
Packit Service 87bc11
}