blob: 37d2e2f778587349de3c6bff26ed6ea88b115670 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/*
* 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
|