diff --git a/meshms.c b/meshms.c index f0bd8016..bcd43f5e 100644 --- a/meshms.c +++ b/meshms.c @@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "conf.h" #include "crypto.h" #include "strbuf.h" -#include "strlcpy.h" #include "keyring.h" #include "dataformats.h" #include "commandline.h" diff --git a/rhizome_store.c b/rhizome_store.c index 4808a7c6..d63a6555 100644 --- a/rhizome_store.c +++ b/rhizome_store.c @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "serval.h" #include "rhizome.h" #include "conf.h" -#include "strlcpy.h" #define RHIZOME_BUFFER_MAXIMUM_SIZE (1024*1024) diff --git a/strlcpy.c b/strlcpy.c index 0ffff34a..d3be3242 100644 --- a/strlcpy.c +++ b/strlcpy.c @@ -1,24 +1,30 @@ /* - * ANSI C version of strlcpy - * Based on the NetBSD strlcpy man page. - * - * Nathan Myers , 2003/06/03 - * Placed in the public domain. - */ + Copyright (C) 2015 Serval Project Inc. + + 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 program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + #ifndef HAVE_STRLCPY -#include /* for size_t */ -#include /* for strlen, memcpy */ +#include "str.h" -size_t -strlcpy(char *dst, const char *src, size_t size) { - const size_t len = strlen(src); - if (size != 0) { - memcpy(dst, src, (len > size - 1) ? size - 1 : len); - dst[size - 1] = 0; - } - return len; +size_t strlcpy(char *dst, const char *src, size_t size) +{ + strncpy_nul(dst, src, size); + return strlen(src); } #endif diff --git a/strlcpy.h b/strlcpy.h index 2302fd2d..bb8761e6 100644 --- a/strlcpy.h +++ b/strlcpy.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Serval Project Inc. + Copyright (C) 2012,2015 Serval Project Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,10 +20,15 @@ #ifndef __STRLCPY_H__ #define __STRLCPY_H__ +// Do not use strlcpy() in Serval DNA source code, use strncpy_nul() or +// buf_strncpy_nul() from "str.h" instead. This strlcpy() is provided only +// because it is needed by sqlite3.c. + #ifdef HAVE_STRLCPY -#include +# include #else -size_t strlcpy(char *dst, const char *src, size_t sz); +# include // for size_t +size_t strlcpy(char *dst, const char *src, size_t sz); #endif #endif