blob: d2438a2fc1cda49e45462b4e5b7e718df288ab3e [file] [log] [blame]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01001#ifndef _STD_H
2#define _STD_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7void *memset(void *s, int c, size_t n);
8void *memcpy(void *dst, const void *src, size_t n);
9void *memmove(void *dst, const void *src, size_t n);
10int memcmp(const void *a, const void *b, size_t n);
11
12size_t strlen(const char *str);
13int strcmp(const char *a, const char *b);
14
15static inline uint16_t ntohs(uint16_t v)
16{
17 return v << 8 | v >> 8;
18}
19
20static inline uint32_t ntohl(uint32_t v)
21{
22 /* TODO: no conversion needed if native is big endian. */
23 return (v << 24) |
24 (v >> 24) |
25 ((v & 0xff00) << 8) |
26 ((v & 0xff0000) >> 8);
27}
28
29static inline uint64_t ntohll(uint64_t v)
30{
31 /* TODO: no conversion needed if native is big endian. */
32 return (v << 56) |
33 (v >> 56) |
34 ((v & 0xff00) << 40) |
35 ((v & 0xff000000000000) >> 40) |
36 ((v & 0xff0000) << 24) |
37 ((v & 0xff0000000000) >> 24) |
38 ((v & 0xff000000) << 8) |
39 ((v & 0xff00000000) >> 8);
40}
41
42static inline uint32_t htonl(uint32_t v)
43{
44 return ntohl(v);
45}
46
47static inline uint64_t htonll(uint64_t v)
48{
49 return ntohll(v);
50}
51
52#endif /* STD_H */