Fixes some build issues with 541289a326
as well as further allowing debugging (via the capdl interface) to
happen when printing is turned off.
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
/*
|
|
* Copyright 2014, General Dynamics C4 Systems
|
|
*
|
|
* This software may be distributed and modified according to the terms of
|
|
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
|
|
* See "LICENSE_GPLv2.txt" for details.
|
|
*
|
|
* @TAG(GD_GPL)
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_PRINTING)
|
|
|
|
word_t strnlen(const char *s, word_t maxlen)
|
|
{
|
|
word_t len;
|
|
for (len = 0; len < maxlen && s[len]; len++);
|
|
return len;
|
|
}
|
|
|
|
word_t strlcpy(char *dest, const char *src, word_t size)
|
|
{
|
|
word_t len;
|
|
for (len = 0; len + 1 < size && src[len]; len++) {
|
|
dest[len] = src[len];
|
|
}
|
|
dest[len] = '\0';
|
|
return len;
|
|
}
|
|
|
|
word_t strlcat(char *dest, const char *src, word_t size)
|
|
{
|
|
word_t len;
|
|
/* get to the end of dest */
|
|
for (len = 0; len < size && dest[len]; len++);
|
|
/* check that dest was at least 'size' length to prevent inserting
|
|
* a null byte when we shouldn't */
|
|
if (len < size) {
|
|
for (; len + 1 < size && *src; len++, src++) {
|
|
dest[len] = *src;
|
|
}
|
|
dest[len] = '\0';
|
|
}
|
|
return len;
|
|
}
|
|
|
|
#endif
|