From bf31fc8174b6d130b90e6ee1a67c543c3c8f1615 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 28 Nov 2016 17:46:55 +0100 Subject: [PATCH] lib: pre-remove str.[ch] for merge, move strmatch() lib/str.[ch] was removed in cleaning up autoconf deadweight. best place for strmatch seems to be a #define in zebra.h Signed-off-by: David Lamparter --- lib/str.c | 143 ---------------------------------------------------- lib/str.h | 35 ------------- lib/zebra.h | 2 + 3 files changed, 2 insertions(+), 178 deletions(-) delete mode 100644 lib/str.c delete mode 100644 lib/str.h diff --git a/lib/str.c b/lib/str.c deleted file mode 100644 index cfdb6e024e..0000000000 --- a/lib/str.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * zebra string function - * - * XXX This version of snprintf does not check bounds! - */ - -/* - The implementations of strlcpy and strlcat are copied from rsync (GPL): - Copyright (C) Andrew Tridgell 1998 - Copyright (C) 2002 by Martin Pool - - Note that these are not terribly efficient, since they make more than one - pass over the argument strings. At some point, they should be optimized. - - The implementation of strndup is copied from glibc-2.3.5: - Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc. -*/ - -/* - * This file is part of Quagga. - * - * Quagga 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, or (at your option) any - * later version. - * - * Quagga is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Quagga; see the file COPYING. If not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include - -#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 -/* - * Copy string src to buffer dst of size dsize. At most dsize-1 - * chars will be copied. Always NUL terminates (unless dsize == 0). - * Returns strlen(src); if retval >= dsize, truncation occurred. - */ -size_t -strlcpy(char *dst, const char *src, size_t dsize) -{ - const char *osrc = src; - size_t nleft = dsize; - - /* Copy as many bytes as will fit. */ - if (nleft != 0) { - while (--nleft != 0) { - if ((*dst++ = *src++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL and traverse rest of src. */ - if (nleft == 0) { - if (dsize != 0) - *dst = '\0'; /* NUL-terminate dst */ - while (*src++) - ; - } - - return(src - osrc - 1); /* count does not include NUL */ -} -#endif - -#ifndef HAVE_STRLCAT -/** - * Like strncat() but does not 0 fill the buffer and always null - * terminates. - * - * @param bufsize length of the buffer, which should be one more than - * the maximum resulting string length. - **/ -size_t -strlcat(char *d, const char *s, size_t bufsize) -{ - size_t len1 = strlen(d); - size_t len2 = strlen(s); - size_t ret = len1 + len2; - - if (len1 < bufsize - 1) { - if (len2 >= bufsize - len1) - len2 = bufsize - len1 - 1; - memcpy(d+len1, s, len2); - d[len1+len2] = 0; - } - return ret; -} -#endif - -#ifndef HAVE_STRNLEN -size_t -strnlen(const char *s, size_t maxlen) -{ - const char *p; - return (p = (const char *)memchr(s, '\0', maxlen)) ? (size_t)(p-s) : maxlen; -} -#endif - -#ifndef HAVE_STRNDUP -char * -strndup (const char *s, size_t maxlen) -{ - size_t len = strnlen (s, maxlen); - char *new = (char *) malloc (len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return (char *) memcpy (new, s, len); -} -#endif - -extern int -strmatch (const char *str1, const char *str2) -{ - if (!strcmp(str1, str2)) - return 1; - return 0; -} diff --git a/lib/str.h b/lib/str.h deleted file mode 100644 index dc8e7e5d67..0000000000 --- a/lib/str.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * $Id: str.h,v 1.4 2005/09/19 09:53:21 hasso Exp $ - */ - -#ifndef _ZEBRA_STR_H -#define _ZEBRA_STR_H - -#ifndef HAVE_SNPRINTF -extern int snprintf(char *, size_t, const char *, ...); -#endif - -#ifndef HAVE_VSNPRINTF -#define vsnprintf(buf, size, format, args) vsprintf(buf, format, args) -#endif - -#ifndef HAVE_STRLCPY -extern size_t strlcpy(char *, const char *, size_t); -#endif - -#ifndef HAVE_STRLCAT -extern size_t strlcat(char *, const char *, size_t); -#endif - -#ifndef HAVE_STRNLEN -extern size_t strnlen(const char *s, size_t maxlen); -#endif - -#ifndef HAVE_STRNDUP -extern char * strndup (const char *, size_t); -#endif - -extern int strmatch (const char *, const char *); - -#endif /* _ZEBRA_STR_H */ - diff --git a/lib/zebra.h b/lib/zebra.h index 08c50c68bc..a37cdd9472 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -461,6 +461,8 @@ extern int proto_redistnum(int afi, const char *s); extern const char *zserv_command_string (unsigned int command); +#define strmatch(a,b) (!strcmp((a), (b))) + /* Error codes of zebra. */ #define ZEBRA_ERR_NOERROR 0 #define ZEBRA_ERR_RTEXIST -1 -- 2.39.5