c语言bzero函数_hikaricp源码分析

看《网络编程》,对bzero等函数的实现颇有兴趣,于是便翻看了其源代码的实现。bzero、bcopy、bcmp等函数源码如下:

bzero源码:

void
bzeros1, n)
	void *s1;
	unsigned n;
{
	register char *t = s1;

	while n != 0) {
		*t++ = 0;
		n--;
	}
}

bcopy源码如下:

void
bcopys1, s2, n)
	const void *s1;
	void *s2;
	unsigned n;
{
	register const char *f = s1;
	register char *t = s2;

	while n != 0) {
		*t++ = *f++;
		n--;
	}
}

bcmp源码如下:

int
bcmpb1, b2, length)
	const void *b1, *b2;
	register size_t length;
{
	register char *p1, *p2;

	if length == 0)
		return0);
	p1 = char *)b1;
	p2 = char *)b2;
	do
		if *p1++ != *p2++)
			break;
	while --length);
	returnlength);
}

参考网址:
http://unix.superglobalmegacorp.com/BSD4.4/newsrc/stand/

                   http://ftp.cc.uoc.gr/mirrors/OpenBSD/src/sys/lib/libkern/bcmp.c

                   https://www.delphij.net/fbdoxy/subsys/libkern/html/df/de2/bcmp_8c_source.html

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注