| 1 | /* |
| 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
| 3 | * |
| 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * This file contains Original Code and/or Modifications of Original Code |
| 7 | * as defined in and that are subject to the Apple Public Source License |
| 8 | * Version 2.0 (the 'License'). You may not use this file except in |
| 9 | * compliance with the License. The rights granted to you under the License |
| 10 | * may not be used to create, or enable the creation or redistribution of, |
| 11 | * unlawful or unlicensed copies of an Apple operating system, or to |
| 12 | * circumvent, violate, or enable the circumvention or violation of, any |
| 13 | * terms of an Apple operating system software license agreement. |
| 14 | * |
| 15 | * Please obtain a copy of the License at |
| 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
| 17 | * |
| 18 | * The Original Code and all software distributed under the License are |
| 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 23 | * Please see the License for the specific language governing rights and |
| 24 | * limitations under the License. |
| 25 | * |
| 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
| 27 | */ |
| 28 | /* |
| 29 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce |
| 30 | * support for mandatory and extensible security protections. This notice |
| 31 | * is included in support of clause 2.2 (b) of the Apple Public License, |
| 32 | * Version 2.0. |
| 33 | */ |
| 34 | /* |
| 35 | * HISTORY |
| 36 | * @OSF_COPYRIGHT@ |
| 37 | */ |
| 38 | #ifndef _STRING_H_ |
| 39 | #define _STRING_H_ 1 |
| 40 | |
| 41 | #ifdef MACH_KERNEL_PRIVATE |
| 42 | #include <types.h> |
| 43 | #else |
| 44 | #include <sys/types.h> |
| 45 | #endif |
| 46 | |
| 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif |
| 50 | |
| 51 | #ifndef NULL |
| 52 | #if defined (__cplusplus) |
| 53 | #define NULL 0 |
| 54 | #else |
| 55 | #define NULL ((void *)0) |
| 56 | #endif |
| 57 | #endif |
| 58 | |
| 59 | extern void *memcpy(void *, const void *, size_t); |
| 60 | extern int memcmp(const void *, const void *, size_t); |
| 61 | extern void *memmove(void *, const void *, size_t); |
| 62 | extern void *memset(void *, int, size_t); |
| 63 | extern int memset_s(void *, size_t, int, size_t); |
| 64 | |
| 65 | extern size_t strlen(const char *); |
| 66 | extern size_t strnlen(const char *, size_t); |
| 67 | |
| 68 | /* strcpy() is being deprecated. Please use strlcpy() instead. */ |
| 69 | extern char *strcpy(char *, const char *) __deprecated; |
| 70 | extern char *strncpy(char *, const char *, size_t); |
| 71 | |
| 72 | extern size_t strlcat(char *, const char *, size_t); |
| 73 | extern size_t strlcpy(char *, const char *, size_t); |
| 74 | |
| 75 | /* strcat() is being deprecated. Please use strlcat() instead. */ |
| 76 | extern char *strcat(char *, const char *) __deprecated; |
| 77 | extern char *strncat(char *, const char *, size_t); |
| 78 | |
| 79 | /* strcmp() is being deprecated. Please use strncmp() instead. */ |
| 80 | extern int strcmp(const char *, const char *); |
| 81 | extern int strncmp(const char *,const char *, size_t); |
| 82 | |
| 83 | extern int strcasecmp(const char *s1, const char *s2); |
| 84 | extern int strncasecmp(const char *s1, const char *s2, size_t n); |
| 85 | extern char *strnstr(char *s, const char *find, size_t slen); |
| 86 | extern char *strchr(const char *s, int c); |
| 87 | #ifdef XNU_KERNEL_PRIVATE |
| 88 | extern char *strrchr(const char *s, int c); |
| 89 | #endif |
| 90 | extern char *STRDUP(const char *, int); |
| 91 | extern int strprefix(const char *s1, const char *s2); |
| 92 | |
| 93 | extern int bcmp(const void *, const void *, size_t); |
| 94 | extern void bcopy(const void *, void *, size_t); |
| 95 | extern void bzero(void *, size_t); |
| 96 | |
| 97 | #ifdef PRIVATE |
| 98 | #include <san/memintrinsics.h> |
| 99 | #endif |
| 100 | |
| 101 | #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_13 |
| 102 | /* older deployment target */ |
| 103 | #elif defined(KASAN) || (defined (_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 0) |
| 104 | /* FORTIFY_SOURCE disabled */ |
| 105 | #else /* _chk macros */ |
| 106 | #if __has_builtin(__builtin___memcpy_chk) |
| 107 | #define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 0)) |
| 108 | #endif |
| 109 | |
| 110 | #if __has_builtin(__builtin___memmove_chk) |
| 111 | #define memmove(dest, src, len) __builtin___memmove_chk(dest, src, len, __builtin_object_size(dest, 0)) |
| 112 | #endif |
| 113 | |
| 114 | #if __has_builtin(__builtin___strncpy_chk) |
| 115 | #define strncpy(dest, src, len) __builtin___strncpy_chk(dest, src, len, __builtin_object_size(dest, 1)) |
| 116 | #endif |
| 117 | |
| 118 | #if __has_builtin(__builtin___strncat_chk) |
| 119 | #define strncat(dest, src, len) __builtin___strncat_chk(dest, src, len, __builtin_object_size(dest, 1)) |
| 120 | #endif |
| 121 | |
| 122 | #if __has_builtin(__builtin___strlcat_chk) |
| 123 | #define strlcat(dest, src, len) __builtin___strlcat_chk(dest, src, len, __builtin_object_size(dest, 1)) |
| 124 | #endif |
| 125 | |
| 126 | #if __has_builtin(__builtin___strlcpy_chk) |
| 127 | #define strlcpy(dest, src, len) __builtin___strlcpy_chk(dest, src, len, __builtin_object_size(dest, 1)) |
| 128 | #endif |
| 129 | |
| 130 | #if __has_builtin(__builtin___strcpy_chk) |
| 131 | #define strcpy(dest, src, len) __builtin___strcpy_chk(dest, src, __builtin_object_size(dest, 1)) |
| 132 | #endif |
| 133 | |
| 134 | #if __has_builtin(__builtin___strcat_chk) |
| 135 | #define strcat(dest, src) __builtin___strcat_chk(dest, src, __builtin_object_size(dest, 1)) |
| 136 | #endif |
| 137 | |
| 138 | #if __has_builtin(__builtin___memmove_chk) |
| 139 | #define bcopy(src, dest, len) __builtin___memmove_chk(dest, src, len, __builtin_object_size(dest, 0)) |
| 140 | #endif |
| 141 | |
| 142 | #endif /* _chk macros */ |
| 143 | #ifdef __cplusplus |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | #endif /* _STRING_H_ */ |
| 148 | |