diff --git a/Makefile.in b/Makefile.in index bce9ea94..75ddc4bd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -56,6 +56,7 @@ SRCS= \ str.c \ strbuf.c \ strbuf_helpers.c \ + strlcpy.c \ vomp.c \ xprintf.c diff --git a/configure.in b/configure.in index f67d70db..f95d34e7 100644 --- a/configure.in +++ b/configure.in @@ -132,6 +132,9 @@ AC_SEARCH_LIBS([expf], [m], AC_DEFINE([HAVE_EXPF], [1], [Define to 1 if you have AC_SEARCH_LIBS([logf], [m], AC_DEFINE([HAVE_LOGF], [1], [Define to 1 if you have the logf() function.])) AC_SEARCH_LIBS([log10f], [m], AC_DEFINE([HAVE_LOG10F], [1], [Define to 1 if you have the log10f() function.])) +dnl Check for strlcpy (eg Ubuntu) +AC_SEARCH_LIBS([strlcpy], [], AC_DEFINE([HAVE_STRLCPY], [1], [Define to 1 if you have the strlcpy() function.])) + AC_OUTPUT([ Makefile testconfig.sh diff --git a/strlcpy.c b/strlcpy.c new file mode 100644 index 00000000..0226a971 --- /dev/null +++ b/strlcpy.c @@ -0,0 +1,23 @@ +/* + * ANSI C version of strlcpy + * Based on the NetBSD strlcpy man page. + * + * Nathan Myers , 2003/06/03 + * Placed in the public domain. + */ + +#ifndef HAVE_STRLCPY + +#include /* for size_t */ + +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; +} + +#endif diff --git a/strlcpy.h b/strlcpy.h new file mode 100644 index 00000000..ae16b7f7 --- /dev/null +++ b/strlcpy.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2012 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 __STRLCPY_H__ +#define __STRLCPY_H__ + +#ifndef HAVE_STRLCPY +size_t strlcpy(char *dst, const char *src, size_t sz); +#endif + +#endif diff --git a/vomp.c b/vomp.c index abc5fba5..e746c35e 100644 --- a/vomp.c +++ b/vomp.c @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "serval.h" #include "strbuf.h" - +#include "strlcpy.h" /* Typical call state lifecycle between 2 parties.