From 718e3744195351130f4ce7dbe0613f4b3e23df93 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 13 Dec 2002 20:15:29 +0000 Subject: Initial revision --- lib/str.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lib/str.c (limited to 'lib/str.c') diff --git a/lib/str.c b/lib/str.c new file mode 100644 index 00000000..797e9b87 --- /dev/null +++ b/lib/str.c @@ -0,0 +1,62 @@ +/* + * zebra string function + * + * these functions are just very basic wrappers around exiting ones and + * do not offer the protection that might be expected against buffer + * overruns etc + */ + +#include + +#include "str.h" + +#ifndef HAVE_SNPRINTF +/* + * snprint() is a real basic wrapper around the standard sprintf() + * without any bounds checking + */ +int +snprintf(char *str, size_t size, const char *format, ...) +{ + va_list args; + + va_start (args, format); + + return vsprintf (str, format, args); +} +#endif + +#ifndef HAVE_STRLCPY +/* + * strlcpy is a safer version of strncpy(), checking the total + * size of the buffer + */ +size_t +strlcpy(char *dst, const char *src, size_t size) +{ + strncpy(dst, src, size); + + return (strlen(dst)); +} +#endif + +#ifndef HAVE_STRLCAT +/* + * strlcat is a safer version of strncat(), checking the total + * size of the buffer + */ +size_t +strlcat(char *dst, const char *src, size_t size) +{ + /* strncpy(dst, src, size - strlen(dst)); */ + + /* I've just added below code only for workable under Linux. So + need rewrite -- Kunihiro. */ + if (strlen (dst) + strlen (src) >= size) + return -1; + + strcat (dst, src); + + return (strlen(dst)); +} +#endif -- cgit v1.2.1