blob: c872fd472cff44932fac9ea4fe9c2005e63997d5 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scullfbc938a2018-08-20 14:09:28 +010017#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010018
19#include <stddef.h>
20#include <stdint.h>
21
22void *memset(void *s, int c, size_t n);
23void *memcpy(void *dst, const void *src, size_t n);
24void *memmove(void *dst, const void *src, size_t n);
25int memcmp(const void *a, const void *b, size_t n);
26
27size_t strlen(const char *str);
28int strcmp(const char *a, const char *b);
29
Andrew Walbran318f5732018-11-20 16:23:42 +000030#define ctz(x) __builtin_ctz(x)
31
Andrew Scullf12b35d2018-07-16 12:12:59 +010032#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010033
Andrew Scullf12b35d2018-07-16 12:12:59 +010034#define be16toh(v) __builtin_bswap16(v)
35#define be32toh(v) __builtin_bswap32(v)
36#define be64toh(v) __builtin_bswap64(v)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010037
Andrew Scullf12b35d2018-07-16 12:12:59 +010038#define htobe16(v) __builtin_bswap16(v)
39#define htobe32(v) __builtin_bswap32(v)
40#define htobe64(v) __builtin_bswap64(v)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010041
Andrew Scullf12b35d2018-07-16 12:12:59 +010042#define le16toh(v) (v)
43#define le32toh(v) (v)
44#define le64toh(v) (v)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010045
Andrew Scullf12b35d2018-07-16 12:12:59 +010046#define htole16(v) (v)
47#define htole32(v) (v)
48#define htole64(v) (v)
49
50#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
51
52#define be16toh(v) (v)
53#define be32toh(v) (v)
54#define be64toh(v) (v)
55
56#define htobe16(v) (v)
57#define htobe32(v) (v)
58#define htobe64(v) (v)
59
60#define le16toh(v) __builtin_bswap16(v)
61#define le32toh(v) __builtin_bswap32(v)
62#define le64toh(v) __builtin_bswap64(v)
63
64#define htole16(v) __builtin_bswap16(v)
65#define htole32(v) __builtin_bswap32(v)
66#define htole64(v) __builtin_bswap64(v)
67
Andrew Scullcbefbdb2019-01-11 16:36:26 +000068#else
69
70/*
71 * __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ &&
72 * __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
73 */
Andrew Scullf12b35d2018-07-16 12:12:59 +010074
75#error "Unsupported byte order"
76
77#endif