/*
* linux/lib/string.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
*/
/*
* stupid library routines.. The optimized versions should generally be found
* as inline code in <asm-xx/string.h>
*
* These are buggy as well..
*
* * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
* - Added strsep() which will replace strtok() soon (because strsep() is
* reentrant and should be faster). Use only strsep() in new code, please.
*/
#include <types.h>
#include <ctype.h>
char * strcpy(char * dest,const char *src);
char * strncpy(char * dest,const char *src,size_t count);
char * strcat(char * dest, const char * src);
char * strncat(char *dest, const char *src, size_t count);
int strcmp(const char * cs,const char * ct);
int strncmp(const char * cs,const char * ct,size_t count);
char * strchr(const char * s, int c);
char * strrchr(const char * s, int c);
size_t strlen(const char * s);
size_t strspn(const char *s, const char *accept);
char * strpbrk(const char * cs,const char * ct);
char * strtok(char * s,const char * ct);
char * strsep(char **s, const char *ct);
char *strswab(const char *s);
char * ___strtok;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
/**
* 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;
}
int skip_atoi(const char **s)
{
int i=0;
while (is_digit(**s))
i = i*10 + *((*s)++) - '0';
return i;
}
/**
* strncat - Append a length-limited, %NUL-terminated string to another
* @dest: The string to be appended to
* @src: The string to append to it
* @count: The maximum numbers of bytes to copy
*
* Note that in contrast to strncpy, strncat ensures the result is
* terminated.
*/
char * strncat(char *dest, const char *src, size_t count)
{
char *tmp = dest;
if (count) {
while (*dest)
dest++;
while ((*dest++ = *src++)) {
if (--count == 0) {
*dest = '\0';
break;
}
}
}
return tmp;
}
/**
* 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;
}
/**
* 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 != (char) c; ++s)
if (*s == '\0')
return NULL;
return (char *) s;
}
/**
* strrchr - Find the last occurrence of a character in a string
* @s: The string to be searched
* @c: The character to search for
*/
char * strrchr(const char * s, int c)
{
const char *p = s + strlen(s);
do {
if (*p == (char)c)
return (char *)p;
} while (--p >= s);
return NULL;
}
/**
* strlen - Find the length of a string
* @s: The string to be sized
*/
size_t strlen(const char * s)
{
const char *sc;
for (sc = s; *sc != '\0'; ++sc)
/* nothing */;
return sc - s;
}
/**
* strnlen - Find the length of a length-limited string
* @s: The string to be sized
* @count: The maximum number of bytes to search
*/
size_t strnlen(const char * s, size_t count)
{
const char *sc;
for (sc = s; count-- && *sc != '\0'; ++sc)
/* nothing */;
return sc - s;
}
/**
* strspn - Calculate the length of the initial substring of @s which only
* contain letters in @accept
* @s: The string to be searched
* @accept: The string to search for
*/
size_t strspn(const char *s, const char *accept)
{
const char *p;
const char *a;
size_t count = 0;
for (p = s; *p != '\0'; ++p) {
for (a = accept; *a != '\0'; ++a) {
if (*p == *a)
break;
}
if (*a == '\0')
return count;
++count;
}
return count;
}
/**
* strpbrk - Find the first occurrence of a set of characters
* @cs: The string to be searched
* @ct: The characters to search for
*/
char * strpbrk(const char * cs,const char * ct)
{
const char *sc1,*sc2;
for( sc1 = cs; *sc1 != '\0'; ++sc1) {
for( sc2 = ct; *sc2 != '\0'; ++sc2) {
if (*sc1 == *sc2)
return (char *) sc1;
}
}
return NULL;
}
/**
* strtok - Split a string into tokens
* @s: The string to be searched
* @ct: The characters to search for
*
* WARNING: strtok is deprecated, use strsep instead.
*/
char * strtok(char * s,const char * ct)
{
char *sbegin, *send;
sbegin = s ? s : ___strtok;
if (!sbegin) {
return NULL;
}
sbegin += strspn(sbegin,ct);
if (*sbegin == '\0') {
___strtok = NULL;
return( NULL );
}
send = strpbrk( sbegin, ct);
if (send && *send != '\0')
*send++ = '\0';
___strtok = send;
return (sbegin);
}
/**
* strsep - Split a string into tokens
* @s: The string to be searched
* @ct: The characters to search for
*
* strsep() updates @s to point after the token, ready for the next call.
*
* It returns empty tokens, too, behaving exactly like the libc function
* of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
* Same semantics, slimmer shape. ;)
*/
char * strsep(char **s, const char *ct)
{
char *sbegin = *s, *end;
if (sbegin == NULL)
return NULL;
end = strpbrk(sbegin, ct);
if (end)
*end++ = '\0';
*s = end;
return sbegin;
}
/**
* strswab - swap adjacent even and odd bytes in %NUL-terminated string
* s: address of the string
*
* returns the address of the swapped string or NULL on error. If
* string length is odd, last byte is untouched.
*/
char *strswab(const char *s)
{
char *p, *q;
if ((NULL == s) || ('\0' == *s)) {
return (NULL);
}
for (p=(char *)s, q=p+1; (*p != '\0') && (*q != '\0'); p+=2, q+=2) {
char tmp;
tmp = *p;
*p = *q;
*q = tmp;
}
return (char *) s;
}
/**
* 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.
*
* Do not use memset() to access IO space, use memset_io() instead.
*/
void * memset(void * s,int c,size_t count)
{
char *xs = (char *) s;
while (count--)
*xs++ = c;
return s;
}
/**
* bcopy - Copy one area of memory to another
* @src: Where to copy from
* @dest: Where to copy to
* @count: The size of the area.
*
* Note that this is the same as memcpy(), with the arguments reversed.
* memcpy() is the standard, bcopy() is a legacy BSD function.
*
* You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead.
*/
char * bcopy(const char * src, char * dest, int count)
{
char *tmp = dest;
while (count--)
*tmp++ = *src++;
return dest;
}
/**
* memcpy - Copy one area of memory to another
* @dest: Where to copy to
* @src: Where to copy from
* @count: The size of the area.
*
没有合适的资源?快使用搜索试试~ 我知道了~
自己写的bootloader源码
共120个文件
c:25个
o:22个
h:20个
需积分: 9 11 下载量 195 浏览量
2012-04-01
19:45:50
上传
评论
收藏 266KB RAR 举报
温馨提示
自己写的bootloader源码,支持NAMD FLASH ,TFTP 下载
资源推荐
资源详情
资源评论
收起资源包目录
自己写的bootloader源码 (120个子文件)
start.S.123 8KB
config.mk.123 2KB
Makefile.12345 6KB
libdm9000.a 29KB
libcommon.a 27KB
libsmdk2410.a 19KB
libgeneric.a 18KB
libuart.a 8KB
libinterrupts.a 8KB
libnand.a 8KB
libarm.a 8KB
s3c24x0.h.bak 2KB
smdk2410.h.bak 341B
types.h.bak 263B
u-boot.bin 21KB
string.c 10KB
dm9000x.c 8KB
nand.c 8KB
dm9000x.c 8KB
main.c 6KB
vsprintf.c 6KB
board.c 5KB
udp.c 5KB
udp.c 5KB
tftp.c 5KB
uart.c 5KB
tftp.c 5KB
interrupts.c 5KB
arp.c 4KB
arp.c 4KB
port.c 4KB
boot_init.c 4KB
speed.c 4KB
speed.c 3KB
cmd_md.c 3KB
command.c 2KB
ctype.c 2KB
cmd_go.c 1006B
cmd_tftp.c 546B
tt.c 112B
.depend 1KB
.depend 866B
.depend 531B
.depend 436B
.depend 393B
.depend 306B
.depend 188B
.depend 99B
.depend 67B
2440addr.h 33KB
s3c24x0.h 18KB
net.h 6KB
net.h 5KB
s3c2410.h 4KB
u-boot.h 2KB
command.h 2KB
dm9000x.h 2KB
dm9000x.h 2KB
ctype.h 1KB
udp.h 1KB
udp.h 1KB
global_data.h 1010B
smdk2410.h 715B
stdarg.h 583B
types.h 289B
common.h 279B
config.h 74B
version_autogenerated.h 41B
version_autogenerated.h 41B
u-boot.lds 532B
abc.log 16KB
view.log 3KB
Makefile 6KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile 1KB
Makefile_123 6KB
u-boot.map 39KB
System.map 7KB
config.mk 2KB
config78898.mk 2KB
rules.mk 289B
config.mk 82B
mkconfig 866B
dm9000x.o 10KB
string.o 9KB
main.o 8KB
uart.o 8KB
nand.o 8KB
interrupts.o 8KB
port.o 7KB
vsprintf.o 7KB
board.o 7KB
共 120 条
- 1
- 2
资源评论
laoyinaiqiqi
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功