mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 01:42:18 +00:00
Add strlcpy as it appears some systems (Ubuntu and probably Debian) don't have it.
This is a public domain version from http://cantrip.org/strlcpy.c
This commit is contained in:
parent
dcb2da45fa
commit
d77e5b7c62
@ -56,6 +56,7 @@ SRCS= \
|
||||
str.c \
|
||||
strbuf.c \
|
||||
strbuf_helpers.c \
|
||||
strlcpy.c \
|
||||
vomp.c \
|
||||
xprintf.c
|
||||
|
||||
|
@ -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
|
||||
|
23
strlcpy.c
Normal file
23
strlcpy.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* ANSI C version of strlcpy
|
||||
* Based on the NetBSD strlcpy man page.
|
||||
*
|
||||
* Nathan Myers <ncm-nospam@cantrip.org>, 2003/06/03
|
||||
* Placed in the public domain.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
|
||||
#include <stdlib.h> /* 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
|
27
strlcpy.h
Normal file
27
strlcpy.h
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user