utils.c

来自「YL9200开发板的BIOS9200源码」· C语言 代码 · 共 60 行

C
60
字号
#include "utils.h"

#ifndef	SELF_BOOT
void *memcpy(void *s1, const void *s2, int n)
{
	int i;

	for (i = 0; i < n; i++)
		((char *)(s1))[i] = ((const char *)(s2))[i];
		
	return s1;	
}

void *memset(void *s, const char ch, int n)
{
	int i;

	for (i = 0; i < n; i++)
		((char *)(s))[i] = ch;
		
	return s;
}

unsigned short ntohs(unsigned short s)
{
	return (s >> 8) | (s << 8);
}

unsigned long ntohl(unsigned long l)
{
	return  ((l >> 24) & 0x000000ff) |
		((l >>  8) & 0x0000ff00) |
		((l <<  8) & 0x00ff0000) |
		((l << 24) & 0xff000000);
}

unsigned short htons(unsigned short s)
{
	return (s >> 8) | (s << 8);
}

unsigned long htonl(unsigned long l)
{
	return  ((l >> 24) & 0x000000ff) |
		((l >>  8) & 0x0000ff00) |
		((l <<  8) & 0x00ff0000) |
		((l << 24) & 0xff000000);
}

#endif

int strlen(const char *s)
{
  int i ;
  
  i = 0 ;
  while (s[i] != '\0') i++ ;
  return i ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?