mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-20 01:46:31 +00:00
new: string.h
This commit is contained in:
53
kernel/common/string.h
Normal file
53
kernel/common/string.h
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include "glib.h"
|
||||
/**
|
||||
* @brief 拷贝整个字符串
|
||||
*
|
||||
* @param dst 目标地址
|
||||
* @param src 源地址
|
||||
* @return char* 目标字符串
|
||||
*/
|
||||
char *strcpy(char *dst, const char *src);
|
||||
|
||||
//计算字符串的长度(经过测试,该版本比采用repne/scasb汇编的运行速度快16.8%左右)
|
||||
static inline int strlen(const char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
register int __res = 0;
|
||||
while (s[__res] != '\0')
|
||||
{
|
||||
++__res;
|
||||
}
|
||||
return __res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 测量字符串的长度
|
||||
*
|
||||
* @param src 字符串
|
||||
* @param maxlen 最大长度
|
||||
* @return long
|
||||
*/
|
||||
long strnlen(const char *src, unsigned long maxlen);
|
||||
|
||||
/*
|
||||
比较字符串 FirstPart and SecondPart
|
||||
FirstPart = SecondPart => 0
|
||||
FirstPart > SecondPart => 1
|
||||
FirstPart < SecondPart => -1
|
||||
*/
|
||||
|
||||
int strcmp(char *FirstPart, char *SecondPart);
|
||||
|
||||
char *strncpy(char *dst, const char *src, long count);
|
||||
|
||||
long strncpy_from_user(char *dst, const char *src, unsigned long size);
|
||||
|
||||
/**
|
||||
* @brief 测量来自用户空间的字符串的长度,会检验地址空间是否属于用户空间
|
||||
* @param src
|
||||
* @param maxlen
|
||||
* @return long
|
||||
*/
|
||||
long strnlen_user(const char *src, unsigned long maxlen);
|
Reference in New Issue
Block a user