2001-03-17 04:17:14 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2004-03-15 13:59:22 +05:30
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2001-03-17 04:17:14 +05:30
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2001-03-17 04:17:14 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2004-03-15 13:59:22 +05:30
|
|
|
/* Like strncpy but make sure the resulting string is always 0 terminated. */
|
2008-06-27 08:22:20 +05:30
|
|
|
char* FAST_FUNC safe_strncpy(char *dst, const char *src, size_t size)
|
2004-03-15 13:59:22 +05:30
|
|
|
{
|
2006-10-06 04:20:22 +05:30
|
|
|
if (!size) return dst;
|
|
|
|
dst[--size] = '\0';
|
|
|
|
return strncpy(dst, src, size);
|
2001-03-17 04:17:14 +05:30
|
|
|
}
|
2008-07-23 01:46:55 +05:30
|
|
|
|
|
|
|
/* Like strcpy but can copy overlapping strings. */
|
|
|
|
void FAST_FUNC overlapping_strcpy(char *dst, const char *src)
|
|
|
|
{
|
2010-10-20 02:37:49 +05:30
|
|
|
/* Cheap optimization for dst == src case -
|
|
|
|
* better to have it here than in many callers.
|
|
|
|
*/
|
|
|
|
if (dst != src) {
|
|
|
|
while ((*dst = *src) != '\0') {
|
|
|
|
dst++;
|
|
|
|
src++;
|
|
|
|
}
|
2008-07-23 01:46:55 +05:30
|
|
|
}
|
|
|
|
}
|