2022-11-14 16:32:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
2009-07-14 13:57:45 +00:00
|
|
|
*
|
2022-11-14 16:32:34 +00:00
|
|
|
* Copyright (C) 2022 William Wilgus
|
2009-07-14 13:57:45 +00:00
|
|
|
*
|
2022-11-14 16:32:34 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-07-14 13:57:45 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2022-11-14 16:32:34 +00:00
|
|
|
#include "strmemccpy.h"
|
2009-07-14 13:57:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy src to string dst of size siz. At most siz-1 characters
|
|
|
|
* will be copied. Always NUL terminates (unless siz == 0).
|
|
|
|
* Returns strlen(src); if retval >= siz, truncation occurred.
|
|
|
|
*/
|
2022-11-14 16:32:34 +00:00
|
|
|
size_t strlcpy(char *dst, const char *src, size_t siz)
|
2009-07-14 13:57:45 +00:00
|
|
|
{
|
2022-11-14 16:32:34 +00:00
|
|
|
/* Copy as many bytes as will fit */
|
|
|
|
char *d = strmemccpy(dst, src, siz);
|
|
|
|
if (d)
|
|
|
|
return (d - dst - 1); /* count does not include NUL */
|
2009-07-14 13:57:45 +00:00
|
|
|
|
2022-11-15 16:24:34 +00:00
|
|
|
/* Not enough room in dst, traverse rest of src */
|
2022-11-14 16:32:34 +00:00
|
|
|
return(siz + strlen(src+siz)); /* count does not include NUL */
|
2009-07-14 13:57:45 +00:00
|
|
|
}
|