-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.h
More file actions
107 lines (92 loc) · 2.23 KB
/
string.h
File metadata and controls
107 lines (92 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef ARIA_STRING_H_
#define ARIA_STRING_H_
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#define DIV_ROUNDUP(a, b) (((a) + ((b) - 1)) / (b))
#define ALIGN_UP(a, b) (DIV_ROUNDUP(a, b) * b)
#define LENGTHOF(a) (sizeof(a) / sizeof(a[0]))
#define ABS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
#define BIT_SET(a, b) ((a)[(b) / 8] |= (1 << ((b) % 8)))
#define BIT_CLEAR(a, b) ((a)[(b) / 8] &= ~(1 << ((b) % 8)))
#define BIT_TEST(a, b) (((a)[(b) / 8] >> ((b) % 8)) & 0x1)
static inline void memset8(uint8_t *src, uint8_t data, size_t n)
{
for (size_t i = 0; i < n; i++) {
*src++ = data;
}
}
static inline void memset16(uint16_t *src, uint16_t data, size_t n)
{
for (size_t i = 0; i < n; i++) {
*src++ = data;
}
}
static inline void memset32(uint32_t *src, uint32_t data, size_t n)
{
for (size_t i = 0; i < n; i++) {
*src++ = data;
}
}
static inline void memset64(uint64_t *src, uint64_t data, size_t n)
{
for (size_t i = 0; i < n; i++) {
*src++ = data;
}
}
static inline void memcpy8(uint8_t *dest, const uint8_t *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
dest[i] = src[i];
}
}
static inline void memcpy16(uint16_t *dest, const uint16_t *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
*dest++ = *src++;
}
}
static inline void memcpy32(uint32_t *dest, const uint32_t *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
*dest++ = *src++;
}
}
static inline void memcpy64(uint64_t *dest, const uint64_t *src, size_t n)
{
for (size_t i = 0; i < n; i++) {
*dest++ = *src++;
}
}
static inline size_t strlen(const char *str)
{
size_t len = 0;
while (str[len])
len++;
return len;
}
static inline size_t abs(int64_t n)
{
return (n < 0) ? -n : n;
}
static inline int pow2_roundup(int n)
{
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}
int strcmp(const char *str0, const char *str1);
int strncmp(const char *str0, const char *str1, size_t n);
int memcmp(const char *str0, const char *str, size_t n);
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
char *strchr(const char *str, char c);
void memcpy(void *dest, const void *src, size_t n);
void memset(void *src, int data, size_t n);
void sprint(char *str, ...);
#endif