Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame^] | 1 | #ifndef _STD_H |
| 2 | #define _STD_H |
| 3 | |
| 4 | #include <stddef.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | void *memset(void *s, int c, size_t n); |
| 8 | void *memcpy(void *dst, const void *src, size_t n); |
| 9 | void *memmove(void *dst, const void *src, size_t n); |
| 10 | int memcmp(const void *a, const void *b, size_t n); |
| 11 | |
| 12 | size_t strlen(const char *str); |
| 13 | int strcmp(const char *a, const char *b); |
| 14 | |
| 15 | static inline uint16_t ntohs(uint16_t v) |
| 16 | { |
| 17 | return v << 8 | v >> 8; |
| 18 | } |
| 19 | |
| 20 | static 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 | |
| 29 | static 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 | |
| 42 | static inline uint32_t htonl(uint32_t v) |
| 43 | { |
| 44 | return ntohl(v); |
| 45 | } |
| 46 | |
| 47 | static inline uint64_t htonll(uint64_t v) |
| 48 | { |
| 49 | return ntohll(v); |
| 50 | } |
| 51 | |
| 52 | #endif /* STD_H */ |