| H. Peter Anvin | 5be8656 | 2007-07-11 12:18:41 -0700 | [diff] [blame] | 1 | /* -*- linux-c -*- ------------------------------------------------------- * | 
 | 2 |  * | 
 | 3 |  *   Copyright (C) 1991, 1992 Linus Torvalds | 
 | 4 |  *   Copyright 2007 rPath, Inc. - All Rights Reserved | 
 | 5 |  * | 
 | 6 |  *   This file is part of the Linux kernel, and is made available under | 
 | 7 |  *   the terms of the GNU General Public License version 2. | 
 | 8 |  * | 
 | 9 |  * ----------------------------------------------------------------------- */ | 
 | 10 |  | 
 | 11 | /* | 
| H. Peter Anvin | 5be8656 | 2007-07-11 12:18:41 -0700 | [diff] [blame] | 12 |  * Very basic string functions | 
 | 13 |  */ | 
 | 14 |  | 
 | 15 | #include "boot.h" | 
 | 16 |  | 
 | 17 | int strcmp(const char *str1, const char *str2) | 
 | 18 | { | 
 | 19 | 	const unsigned char *s1 = (const unsigned char *)str1; | 
 | 20 | 	const unsigned char *s2 = (const unsigned char *)str2; | 
 | 21 | 	int delta = 0; | 
 | 22 |  | 
 | 23 | 	while (*s1 || *s2) { | 
 | 24 | 		delta = *s2 - *s1; | 
 | 25 | 		if (delta) | 
 | 26 | 			return delta; | 
 | 27 | 		s1++; | 
 | 28 | 		s2++; | 
 | 29 | 	} | 
 | 30 | 	return 0; | 
 | 31 | } | 
 | 32 |  | 
 | 33 | size_t strnlen(const char *s, size_t maxlen) | 
 | 34 | { | 
 | 35 | 	const char *es = s; | 
 | 36 | 	while (*es && maxlen) { | 
 | 37 | 		es++; | 
 | 38 | 		maxlen--; | 
 | 39 | 	} | 
 | 40 |  | 
 | 41 | 	return (es - s); | 
 | 42 | } | 
 | 43 |  | 
 | 44 | unsigned int atou(const char *s) | 
 | 45 | { | 
 | 46 | 	unsigned int i = 0; | 
 | 47 | 	while (isdigit(*s)) | 
 | 48 | 		i = i * 10 + (*s++ - '0'); | 
 | 49 | 	return i; | 
 | 50 | } |