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