2001-03-16 22:47:14 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2001-03-16 22:47:14 +00:00
|
|
|
*
|
2006-05-19 19:29:19 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2001-03-16 22:47:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2004-03-15 08:29:22 +00:00
|
|
|
/* Like strncpy but make sure the resulting string is always 0 terminated. */
|
2008-06-27 02:52:20 +00:00
|
|
|
char* FAST_FUNC safe_strncpy(char *dst, const char *src, size_t size)
|
2004-03-15 08:29:22 +00:00
|
|
|
{
|
2006-10-05 22:50:22 +00:00
|
|
|
if (!size) return dst;
|
|
|
|
dst[--size] = '\0';
|
|
|
|
return strncpy(dst, src, size);
|
2001-03-16 22:47:14 +00:00
|
|
|
}
|
2008-07-22 20:16:55 +00:00
|
|
|
|
|
|
|
/* Like strcpy but can copy overlapping strings. */
|
|
|
|
void FAST_FUNC overlapping_strcpy(char *dst, const char *src)
|
|
|
|
{
|
|
|
|
while ((*dst = *src) != '\0') {
|
|
|
|
dst++;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
}
|