1 #pragma once
2
3 #include <sys/types.h>
4
5 #if defined(__cplusplus)
6 extern "C" {
7 #endif
8
9 void *memset(void *dst, unsigned char C, uint64_t size);
10 /**
11 * @brief 获取字符串的大小
12 *
13 * @param s 字符串
14 * @return size_t 大小
15 */
16 size_t strlen(const char *s);
17
18 /*
19 比较字符串 FirstPart and SecondPart
20 FirstPart = SecondPart => 0
21 FirstPart > SecondPart => 1
22 FirstPart < SecondPart => -1
23 */
24
25 int strcmp(const char *FirstPart, const char *SecondPart);
26
27 /**
28 * @brief 拷贝指定字节数的字符串
29 *
30 * @param dst 目标地址
31 * @param src 源字符串
32 * @param Count 字节数
33 * @return char*
34 */
35 char *strncpy(char *dst, const char *src, size_t Count);
36
37 /**
38 * @brief 拷贝整个字符串
39 *
40 * @param dst 目标地址
41 * @param src 源地址
42 * @return char* 目标字符串
43 */
44 char* strcpy(char* dst, const char* src);
45
46 /**
47 * @brief 拼接两个字符串(将src接到dest末尾)
48 *
49 * @param dest 目标串
50 * @param src 源串
51 * @return char*
52 */
53 char *strcat(char *dest, const char *src);
54
55 /**
56 * @brief 内存拷贝函数
57 *
58 * @param dst 目标数组
59 * @param src 源数组
60 * @param Num 字节数
61 * @return void*
62 */
memcpy(void * dst,const void * src,long Num)63 static void *memcpy(void *dst, const void *src, long Num)
64 {
65 int d0 = 0, d1 = 0, d2 = 0;
66 __asm__ __volatile__("cld \n\t"
67 "rep \n\t"
68 "movsq \n\t"
69 "testb $4,%b4 \n\t"
70 "je 1f \n\t"
71 "movsl \n\t"
72 "1:\ttestb $2,%b4 \n\t"
73 "je 2f \n\t"
74 "movsw \n\t"
75 "2:\ttestb $1,%b4 \n\t"
76 "je 3f \n\t"
77 "movsb \n\t"
78 "3: \n\t"
79 : "=&c"(d0), "=&D"(d1), "=&S"(d2)
80 : "0"(Num / 8), "q"(Num), "1"(dst), "2"(src)
81 : "memory");
82 return dst;
83 }
84
85 #if defined(__cplusplus)
86 } /* extern "C" */
87 #endif
88