summaryrefslogtreecommitdiff
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
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
-rw-r--r--compat/Makefile.am3
-rw-r--r--compat/strndup.c41
-rw-r--r--compat/strndup.h33
-rw-r--r--configure.ac3
-rw-r--r--nslcd/group.c1
-rw-r--r--nslcd/passwd.c1
6 files changed, 80 insertions, 2 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 */
diff --git a/configure.ac b/configure.ac
index 0a860ce..ae45268 100644
--- a/configure.ac
+++ b/configure.ac
@@ -566,8 +566,9 @@ then
AC_CHECK_FUNCS(dlopen dlsym dlerror)
AC_CHECK_FUNCS(regcomp regexec regerror)
- # replace getopt_long() function if it is not on the system
+ # replace some functions if they are not on the system
AC_REPLACE_FUNCS(getopt_long)
+ AC_REPLACE_FUNCS(strndup)
# replace daemon() function if it is not on the system
AC_SEARCH_LIBS(daemon,bsd)
diff --git a/nslcd/group.c b/nslcd/group.c
index f320828..c2a09a5 100644
--- a/nslcd/group.c
+++ b/nslcd/group.c
@@ -37,6 +37,7 @@
#include "myldap.h"
#include "cfg.h"
#include "attmap.h"
+#include "compat/strndup.h"
/* ( nisSchema.2.2 NAME 'posixGroup' SUP top STRUCTURAL
* DESC 'Abstraction of a group of accounts'
diff --git a/nslcd/passwd.c b/nslcd/passwd.c
index 5f02486..15124fe 100644
--- a/nslcd/passwd.c
+++ b/nslcd/passwd.c
@@ -38,6 +38,7 @@
#include "cfg.h"
#include "attmap.h"
#include "common/dict.h"
+#include "compat/strndup.h"
/* ( nisSchema.2.0 NAME 'posixAccount' SUP top AUXILIARY
* DESC 'Abstraction of an account with POSIX attributes'