mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-16 18:28:05 +02:00
../../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>
27 lines
418 B
C
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
|