diff options
author | Stefan Reinauer <stepan@coresystems.de> | 2010-03-25 22:15:19 +0000 |
---|---|---|
committer | Stefan Reinauer <stepan@openbios.org> | 2010-03-25 22:15:19 +0000 |
commit | e5d30b78b7720ba3e511819b7fc51c11d642153b (patch) | |
tree | 16e7be335542de064aef267c7c6095f5c8cd3496 /payloads/libpayload/libc/string.c | |
parent | 516a2a7bfaee5d4aa4d1e7e5ff52d3038513c82f (diff) |
libpayload update
* rework Config.in
* add string_to_args function to actually make getopt usable.
* add strchr
* add strlcat
* some malloc fixes (exposed by the USB stack)
* add malloc debugging (thanks to Matthias Krause from Secunet!)
* make LAR support optional, it's not really used anymore
* (define htoX macros for ppc)
Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Joseph Smith <joe@settoplinux.org>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5298 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload/libc/string.c')
-rw-r--r-- | payloads/libpayload/libc/string.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index 81cce26a61..b69fab6815 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -171,7 +171,9 @@ char *strcpy(char *d, const char *s) char *strncat(char *d, const char *s, size_t n) { char *p = d + strlen(d); - int max = n > strlen(s) ? strlen(s) : n; + int sl = strlen(s); + int max = n > sl ? sl : n; + // int max = n > strlen(s) ? strlen(s) : n; int i; for (i = 0; i < max; i++) @@ -182,6 +184,30 @@ char *strncat(char *d, const char *s, size_t n) } /** + * Concatenates two strings with a maximum length. + * + * @param d The destination string. + * @param s The source string. + * @param n Not more than n characters from s will be appended to d. + * @return A pointer to the destination string. + */ +size_t strlcat(char *d, const char *s, size_t n) +{ + int sl = strlen(s); + int dl = strlen(d); + + char *p = d + dl; + int max = n > (sl + dl) ? sl : (n - dl - 1); + int i; + + for (i = 0; i < max; i++) + p[i] = s[i]; + + p[i] = '\0'; + return max; +} + +/** * Find a character in a string. * * @param s The string. @@ -202,6 +228,27 @@ char *strchr(const char *s, int c) } /** + * Find a character in a string. + * + * @param s The string. + * @param c The character. + * @return A pointer to the last occurence of the character in the + * string, or NULL if the character was not encountered within the string. + */ + +char *strrchr(const char *s, int c) +{ + char *p = (char *)s + strlen(s); + + for (; p >= s; p--) { + if (*p == c) + return p; + } + + return NULL; +} + +/** * Duplicate a string. * * @param s The string to duplicate. |