summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2011-04-15 21:20:40 +0000
committerArthur de Jong <arthur@arthurdejong.org>2011-04-15 21:20:40 +0000
commit8e5373638043870f0f068d48e4c9e69d904abdfb (patch)
tree0b5ccfb290bff17f28c7332f78dc34c4a2eb027d /compat
parentf4ef68224b38febc2e6d0fb22933be7413e0a4fa (diff)
provide replacement implementation for strndup() for systems that don't have it
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1427 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'compat')
-rw-r--r--compat/Makefile.am3
-rw-r--r--compat/strndup.c41
-rw-r--r--compat/strndup.h33
3 files changed, 76 insertions, 1 deletions
diff --git a/compat/Makefile.am b/compat/Makefile.am
index 8e8e3a7..9ff1204 100644
--- a/compat/Makefile.am
+++ b/compat/Makefile.am
@@ -1,6 +1,6 @@
# Makefile.am - use automake to generate Makefile.in
#
-# Copyright (C) 2008, 2009, 2010 Arthur de Jong
+# Copyright (C) 2008, 2009, 2010, 2011 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@ AM_CFLAGS = -fPIC
EXTRA_DIST = getopt_long.c getopt_long.h \
daemon.c daemon.h \
ether.c ether.h \
+ strndup.c strndup.h \
nss_compat.h \
ldap_compat.h pagectrl.c ldap_passwd_s.c ldap_initialize.c \
pam_compat.h pam_get_authtok.c pam_prompt.c
diff --git a/compat/strndup.c b/compat/strndup.c
new file mode 100644
index 0000000..9eb38a0
--- /dev/null
+++ b/compat/strndup.c
@@ -0,0 +1,41 @@
+/*
+ strndup.c - implementation of strndup() for systems that lack it
+
+ Copyright (C) 2011 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "strndup.h"
+
+/* this is a strndup() replacement for systems that don't have it
+ (strndup() is in POSIX 2008 now) */
+char *strndup(const char *s,size_t size)
+{
+ char *result;
+ result=(char *)malloc(size+1);
+ if (result!=NULL)
+ {
+ strncpy(result,s,size);
+ result[size]='\0';
+ }
+ return result;
+}
diff --git a/compat/strndup.h b/compat/strndup.h
new file mode 100644
index 0000000..abedd22
--- /dev/null
+++ b/compat/strndup.h
@@ -0,0 +1,33 @@
+/*
+ strndup.h - definition of strndup() for systems that lack it
+
+ Copyright (C) 2011 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA
+*/
+
+#ifndef COMPAT__STRNDUP_H
+#define COMPAT__STRNDUP_H 1
+
+#ifndef HAVE_STRNDUP
+
+/* this is a strndup() replacement for systems that don't have it
+ (strndup() is in POSIX 2008 now) */
+char *strndup(const char *s,size_t size);
+
+#endif /* not HAVE_STRNDUP */
+
+#endif /* COMPAT__STRNDUP_H */