libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
Loading...
Searching...
No Matches
str_win32.h
Go to the documentation of this file.
1/*
2 * str_win32.h - Windows compatibility for POSIX string functions
3 * Provides implementations for strndup, strptime, and strtok_r on Windows
4 */
5
6#ifndef STR_WIN32_H
7#define STR_WIN32_H
8
9#if defined(_WIN32) || defined(_WIN64)
10
11#include <ctype.h>
12#include <stdlib.h>
13#include <string.h>
14#include <time.h>
15
16#ifdef _MSC_VER
17#pragma warning(push)
18#pragma warning(disable : 4996) // Disable deprecation warnings
19#endif
20
21/* Check if strndup is not already defined */
22#ifndef HAVE_STRNDUP
23static char *strndup(const char *s, size_t n) {
24 size_t len;
25 char *copy;
26
27 if (s == NULL)
28 return NULL;
29
30 len = strlen(s);
31 if (n < len)
32 len = n;
33
34 copy = (char *)malloc(len + 1);
35 if (copy == NULL)
36 return NULL;
37
38 memcpy(copy, s, len);
39 copy[len] = '\0';
40 return copy;
41}
42#define HAVE_STRNDUP 1
43#endif
44
45#ifdef _MSC_VER
46#pragma warning(pop)
47#endif
48
49#endif /* _WIN32 */
50
51#endif /* STR_WIN32_H */