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
This commit is contained in:
Stefan Reinauer
2010-03-25 22:15:19 +00:00
committed by Stefan Reinauer
parent 516a2a7bfa
commit e5d30b78b7
8 changed files with 361 additions and 16 deletions

View File

@ -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++)
@ -181,6 +183,30 @@ char *strncat(char *d, const char *s, size_t n)
return d;
}
/**
* 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.
*
@ -201,6 +227,27 @@ char *strchr(const char *s, int c)
return NULL;
}
/**
* 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.
*