]>
Commit | Line | Data |
---|---|---|
37be9888 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
37be9888 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
605f2c3e AJ |
9 | #ifndef SQUID_COMPAT_XSTRING_H |
10 | #define SQUID_COMPAT_XSTRING_H | |
25f98340 AJ |
11 | |
12 | #if HAVE_STRING_H | |
13 | #include <string.h> | |
14 | #endif | |
15 | ||
16 | #ifdef __cplusplus | |
17 | extern "C" { | |
18 | #endif | |
19 | ||
f53969cc SM |
20 | /** |
21 | * xstrdup() - same as strdup(3). Used for portability. | |
22 | * Never returns NULL; fatal on error. | |
23 | * | |
24 | * Sets errno to EINVAL if a NULL pointer is passed. | |
25 | * | |
26 | * Define failure_notify to receive error message. | |
27 | * otherwise perror() is used to display it. | |
28 | */ | |
29 | char *xstrdup(const char *s); | |
25f98340 AJ |
30 | |
31 | #ifdef strdup | |
32 | #undef strdup | |
33 | #endif | |
34 | #define strdup(X) xstrdup((X)) | |
35 | ||
f53969cc SM |
36 | /* |
37 | * xstrncpy() - similar to strncpy(3) but terminates string | |
38 | * always with '\0' if (n != 0 and dst != NULL), | |
39 | * and doesn't do padding | |
40 | */ | |
41 | char *xstrncpy(char *dst, const char *src, size_t n); | |
8236d34f | 42 | |
f53969cc SM |
43 | /** |
44 | * xstrndup() - same as strndup(3). Used for portability. | |
45 | * Never returns NULL; fatal on error. | |
46 | * | |
47 | * Sets errno to EINVAL if a NULL pointer or negative | |
48 | * length is passed. | |
49 | * | |
50 | * Define failure_notify to receive error message. | |
51 | * otherwise perror() is used to display it. | |
52 | */ | |
53 | char *xstrndup(const char *s, size_t n); | |
25f98340 AJ |
54 | |
55 | #ifdef strndup | |
56 | #undef strndup | |
57 | #endif | |
58 | #define strndup(X) xstrndup((X)) | |
59 | ||
25f98340 AJ |
60 | #ifdef __cplusplus |
61 | } | |
62 | #endif | |
63 | ||
605f2c3e | 64 | #endif /* SQUID_COMPAT_XSTRING_H */ |
f53969cc | 65 |