mirror of
https://git.codelinaro.org/clo/qsdk/oss/boot/u-boot-2016.git
synced 2026-03-08 10:17:13 +01:00
Merge "lib: string: compile strlcat() and memscpy()"
This commit is contained in:
commit
94e7179ffe
2 changed files with 58 additions and 0 deletions
|
|
@ -39,6 +39,9 @@ extern char * strcat(char *, const char *);
|
|||
#ifndef __HAVE_ARCH_STRNCAT
|
||||
extern char * strncat(char *, const char *, __kernel_size_t);
|
||||
#endif
|
||||
#ifndef __HAVE_ARCH_STRLCAT
|
||||
extern size_t strlcat(char *, const char *, __kernel_size_t);
|
||||
#endif
|
||||
#ifndef __HAVE_ARCH_STRCMP
|
||||
extern int strcmp(const char *,const char *);
|
||||
#endif
|
||||
|
|
@ -80,6 +83,9 @@ extern void * memset(void *,int,__kernel_size_t);
|
|||
#ifndef __HAVE_ARCH_MEMCPY
|
||||
extern void * memcpy(void *,const void *,__kernel_size_t);
|
||||
#endif
|
||||
#ifndef __HAVE_ARCH_MEMSCPY
|
||||
extern size_t memscpy(void *dest, size_t dst_size, const void *src, size_t copy_size);
|
||||
#endif
|
||||
#ifndef __HAVE_ARCH_MEMMOVE
|
||||
extern void * memmove(void *,const void *,__kernel_size_t);
|
||||
#endif
|
||||
|
|
|
|||
52
lib/string.c
52
lib/string.c
|
|
@ -175,6 +175,33 @@ char * strncat(char *dest, const char *src, size_t count)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef __HAVE_ARCH_STRLCAT
|
||||
/**
|
||||
* strlcat - 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 size of the destination buffer.
|
||||
*
|
||||
*/
|
||||
size_t strlcat(char *dest, const char *src, size_t count)
|
||||
{
|
||||
size_t dsize = strlen(dest);
|
||||
size_t len = strlen(src);
|
||||
size_t res = dsize + len;
|
||||
|
||||
/* This would be a bug */
|
||||
BUG_ON(dsize >= count);
|
||||
|
||||
dest += dsize;
|
||||
count -= dsize;
|
||||
if (len >= count)
|
||||
len = count-1;
|
||||
memcpy(dest, src, len);
|
||||
dest[len] = 0;
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __HAVE_ARCH_STRCMP
|
||||
/**
|
||||
* strcmp - Compare two strings
|
||||
|
|
@ -520,6 +547,31 @@ void * memcpy(void *dest, const void *src, size_t count)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef __HAVE_ARCH_MEMSCPY
|
||||
/**
|
||||
* memscpy - Copy one area of memory to another
|
||||
* @dest: Where to copy to
|
||||
* @src: Where to copy from
|
||||
* @dst_size: The size of destination buffer area
|
||||
* @copy_size: The size of source buffer area
|
||||
*
|
||||
* You should not use this function where memcpy
|
||||
* was used to copy null terminated buffer, the
|
||||
* replacement function is strlcpy() and strlcat()
|
||||
* depending on situation.
|
||||
*
|
||||
* The aim of memscpy() is to prevent buffer overflow
|
||||
* by taking both destination buffer size and source
|
||||
* buffer size.
|
||||
*/
|
||||
size_t memscpy(void *dest, size_t dst_size, const void *src, size_t copy_size)
|
||||
{
|
||||
size_t min_size = dst_size < copy_size ? dst_size : copy_size;
|
||||
memcpy(dest, src, min_size);
|
||||
return min_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __HAVE_ARCH_MEMMOVE
|
||||
/**
|
||||
* memmove - Copy one area of memory to another
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue