1
0
This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
TP-Link_Archer-XR500v/EN7526G_3.18Kernel_SDK/apps/public/net-snmp-5.3.1/snmplib/strlcpy.c
2024-07-22 01:58:46 -03:00

46 lines
928 B
C
Executable File

/*
* Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms specified in the COPYING file
* distributed with the Net-SNMP package.
*/
#include <net-snmp/net-snmp-config.h>
#if !HAVE_STRLCPY
#if HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <sys/types.h>
/*
* Copies src to the dest buffer. The copy will never overflow the dest buffer
* and dest will always be null terminated, len is the size of the dest buffer.
*
* Returns the length of the src buffer.
*/
size_t
strlcpy(char *dest, const char *src, size_t len)
{
size_t src_len = strlen(src);
size_t new_len;
if (len == 0) {
return (src_len);
}
if (src_len >= len) {
new_len = len - 1;
} else {
new_len = src_len;
}
memcpy(dest, src, new_len);
dest[new_len] = '\0';
return (src_len);
}
#endif /* !HAVE_STRLCPY */