⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.c

📁 SMDK2440 boot code, base on vivi
💻 C
字号:
/* * vivi/lib/string.c: 厚厚俊辑父 荤侩窍绰 胶飘傅 包访 窃荐甸. * * Copyright (C) 2002 MIZI Research, Inc. * * Author: Janghoon Lyu <nandy@mizi.com> * Date  : $Date: 2003/08/11 02:29:46 $ * * $Revision: 1.9 $ * $Id: string.c,v 1.9 2003/08/11 02:29:46 nandy Exp $ * * */#include <config.h>#include <ctype.h>#include <types.h>#include <vstring.h>#include <serial.h>/* * Convert size from human readable size. */unsigned longsimple_hstrtoul(char *s){	unsigned long size = 0;	while (isdigit(*s)) {		size = size * 10 + *s - '0';		s++;	}	if (*s == 'M' || *s == 'm') size *= 1024*1024;	else if (*s == 'K' || *s == 'k') size *= 1024;	else if (*s) {		printk("hmm bad size %s\n", s);	}	return size;}/* * simple_strtoul - convert a stringto an unsigned long * @cp: The start of the string * @endp: A pointer to the end of the parsed string will be placed here * @base: The number base to use */unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base){	unsigned long result = 0, value;	if (!base) {		base = 10;		if (*cp == '0') {			base = 8;			cp++;			if ((*cp == 'x') && isxdigit(cp[1])) {				cp++;				base = 16;			}		}	}	while (isxdigit(*cp) &&		(value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {		result = result*base + value;		cp++;	}	if (endp)		*endp = (char *)cp;	return result;}/* * 颊毫具 凳 */static const char hex_to_ascii_table[16] = "0123456789ABCDEF";void simple_bin2hex(char *buf, long x, int nbytes){        int i;        int s = 4*(2*nbytes - 1);        for (i = 0; i < 2*nbytes; i++){                buf[i] = hex_to_ascii_table[(x >> s) & 0xf];                s -= 4;        }        buf[2*nbytes] = 0;}/* * strcmp - Compare two strings * @cs: One string * @ct: Another string */int strcmp(const char *cs, const char *ct){	register signed char __res;	while (1) {		if ((__res = *cs - *ct++) != 0 || !*cs++)			break;	}	return __res;}/* * strncmp - Compare two length-limited strings * @cs: One string * @ct: Another string * @count: The maximum number of bytes to compare */int strncmp(const char *cs, const char *ct, size_t count){	register signed char __res = 0;	while (count) {		if ((__res = *cs - *ct++) != 0 || !*cs++)			break;		count--;	}	return __res;}/* * strcpy - Copy a %NUL terminated string * @dest: Where to copy the string to * @src: Where to copy the string from */char *strcpy(char *dest, const char *src){	char *tmp = dest;	while ((*dest++ = *src++) !=  '\0')		/* nothing */;	return tmp;}/* * strncpy - Copy a length-limited, %NUL-terminated string * @dest: Where to copy the string to * @src: Where to copy the string from * @count: The maximum number of bytes to copy * * Note that unlike userspace strncpy, this does not %NUL-pad the buffer. * However, the result is not %NUL-terminated if the source exceeds * @count bytes. */char *strncpy(char *dest, const char *src, size_t count){	char *tmp = dest;	while (count-- && (*dest++ = *src++) != '\0')		/* nothing */;	return tmp;}/* * strcat - Append one %NUL-terminated string to another * @dest: The string to be appended to * @src: The string to append to it */char *strcat (char *dest, const char *src){	char *tmp = dest;	while (*dest)		dest++;	while ((*dest++ = *src++) != '\0')		;		return tmp;}/* * strlen - Find the length of a string * @s: The string to be sized */size_tstrlen(const char *s){	const char *sc;	for (sc = s; *sc != '\0'; ++sc)		/* nothing */;	return sc - s;}/* * strchr - Find the first occurrence of a character in a string * @s: The string to be searched * @c: The character to search for */char *strchr(const char *s, int c){	for (; *s != '\0'; ++s)		if (*s == (char)c)			return (char *)s;	return NULL;}/* * memset - Fill a region of memory with the given value * @s: Pointer to the start of the area * @c: The byte to fill the area with * @count: The size of the area. */void *memset(void *s, int c, size_t count){	char *xs = (char *)s;	while (count--)		*xs++ = c;	return s;}/* * memcpy - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. */void *memcpy(void *dest, const void *src, size_t count){	char *tmp = (char *)dest, *s = (char *)src;	while (count--)		*tmp++ = *s++;	return dest;}/* * memcmp - Compare two areas of memory * @cs: One area of memory * @ct: Another area of memory * @count: The size of the area */int memcmp(const void *cs, const void *ct, size_t count){	const unsigned char *su1, *su2;	int res = 0;	for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)		if ((res = *su1 - *su2) != 0)			break;	return res;}/* * memmove - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. * * Unlike memcpy(), memmove() copes with overlapping areas. */void * memmove(void * dest,const void *src,size_t count){	char *tmp, *s;	if (dest <= src) {		tmp = (char *) dest;		s = (char *) src;		while (count--)			*tmp++ = *s++;		}	else {		tmp = (char *) dest + count;		s = (char *) src + count;		while (count--)			*--tmp = *--s;		}	return dest;}

⌨️ 快捷键说明

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