[BACK]Return to string.c CVS log [TXT][DIR] Up to [local] / funnyos / libkern

File: [local] / funnyos / libkern / string.c (download)

Revision 1.1, Tue Oct 16 08:41:04 2007 UTC (16 years, 6 months ago) by init
Branch point for: MAIN

Initial revision

/*
 * $Id: string.c,v 1.1 2007/10/16 08:41:04 init Exp $
 */
#include <sys/types.h>
#include <libkern/string.h>

int
strncmp(const char *s1, const char *s2, const uint32_t len)
{
	/*
	 * Compare len characters of string s1 with len characters of s2.
	 * Return first difference's position or 0 if no differencies.
	 */
	uint32_t 	i;

	/* TODO ugly algorhitm; rewrite */

	for(i = 0; i < len; i++) {
		if(s1[i] != s2[i])
			return(i + 1);

		if(s1[i] == '\0')
			/* \0 encountered, but strings are identical */
			return(0);
	}

	return(-1);	
}