mesa/src/util/strndup.c
Yonggang Luo bd915eeb96 util: Fixes gcc warning: declaration of 'strndup' shadows a built-in function [-Wshadow]
../../src/util/strndup.h:37:1: warning: declaration of 'strndup' shadows a built-in function [-Wshadow]
   37 | strndup(const char *str, size_t max)
      | ^~~~~~~

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37289>
2025-09-13 08:23:07 +00:00

27 lines
418 B
C

/*
* Copyright (c) 2015 Intel Corporation
* Copyright (c) 2025 Yonggang Luo
* SPDX-License-Identifier: MIT
*/
#include "strndup.h"
#if defined(_WIN32)
char *
strndup(const char *str, size_t max)
{
size_t n;
char *ptr;
if (!str)
return NULL;
n = strnlen(str, max);
ptr = (char *) calloc(n + 1, sizeof(char));
if (!ptr)
return NULL;
memcpy(ptr, str, n);
return ptr;
}
#endif