]> git.saurik.com Git - apple/libplatform.git/blame - include/platform/compat.h
libplatform-126.1.2.tar.gz
[apple/libplatform.git] / include / platform / compat.h
CommitLineData
ada7c492
A
1/*
2 * Copyright (c) 2013 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _PLATFORM_COMPAT_H_
25#define _PLATFORM_COMPAT_H_
26
27#include <platform/string.h>
28
29__BEGIN_DECLS
30
31/* Helpers for other common non-primitive routines */
32
33__header_always_inline
34size_t
35_platform_strlen(const char *s) {
36 const char *t = _platform_memchr(s, '\0', SIZE_MAX);
37 return (uintptr_t)t - (uintptr_t)s;
38}
39
40__header_always_inline
41size_t
42_platform_strlcpy(char * restrict dst, const char * restrict src, size_t maxlen) {
43 const size_t srclen = _platform_strlen(src);
44 if (srclen < maxlen) {
45 _platform_memmove(dst, src, srclen+1);
46 } else if (maxlen != 0) {
47 _platform_memmove(dst, src, maxlen-1);
48 dst[maxlen-1] = '\0';
49 }
50 return srclen;
51}
52
53__END_DECLS
54
55/* Compat macros for primitives */
56#define bzero _platform_bzero
57#define memchr _platform_memchr
58#define memcmp _platform_memcmp
59#define memmove _platform_memmove
60#define memccpy _platform_memccpy
61#define memset _platform_memset
62#define memset_pattern4 _platform_memset_pattern4
63#define memset_pattern8 _platform_memset_pattern8
64#define memset_pattern16 _platform_memset_pattern16
65#define strchr _platform_strchr
66#define strcmp _platform_strcmp
67#define strncmp _platform_strncmp
68
69/* Compat macros for non-primitive helpers */
70#define strlcpy _platform_strlcpy
71#define strlen _platform_strlen
72
73#endif /* _PLATFORM_COMPAT_H_ */