mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
swab函数 (#53)
* swab函数 Signed-off-by: Yuqia <15287042733@163.com> * 修正格式 Signed-off-by: Yuqia <15287042733@163.com> Co-authored-by: fslongjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include <libc/errno.h>
|
||||
#include <libc/stdio.h>
|
||||
#include <libc/stddef.h>
|
||||
#include <libc/string.h>
|
||||
|
||||
/**
|
||||
* @brief 关闭文件接口
|
||||
@ -157,4 +158,27 @@ int execv(const char *path, char *const argv[])
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
return syscall_invoke(SYS_RMDIR, (uint64_t)path, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 交换n字节
|
||||
* @param src 源地址
|
||||
* @param dest 目的地址
|
||||
* @param nbytes 交换字节数
|
||||
*/
|
||||
void swab(void *restrict src, void *restrict dest, ssize_t nbytes)
|
||||
{
|
||||
unsigned char buf[32];
|
||||
char *_src = src;
|
||||
char *_dest = dest;
|
||||
uint32_t transfer;
|
||||
for (; nbytes > 0; nbytes -= transfer)
|
||||
{
|
||||
transfer = (nbytes > 32) ? 32 : nbytes;
|
||||
memcpy(buf, _src, transfer);
|
||||
memcpy(_src, _dest, transfer);
|
||||
memcpy(_dest, buf, transfer);
|
||||
_src += transfer;
|
||||
_dest += transfer;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user