Browse Source

Use AC_REPLACE_FUNC to provide compat/strlcpy when needed, closes #16

Julien 'Lta' BALLET 10 years ago
parent
commit
1541cc01e2
5 changed files with 42 additions and 10 deletions
  1. 5 5
      Makefile.am
  2. 8 0
      compat/compat.c
  3. 23 0
      compat/compat.h
  4. 2 4
      configure.ac
  5. 4 1
      src/smb_ntlm.c

+ 5 - 5
Makefile.am

@@ -6,7 +6,7 @@ EXTRA_DIST = \
 	contrib/spnego/spnego.asn1
 	contrib/spnego/spnego_asn1.c
 
-CFLAGS = -I$(top_srcdir)/contrib -I$(top_srcdir)/include @TASN1_CFLAGS@ @CFLAGS@
+CFLAGS = -I$(top_srcdir)/contrib -I$(top_srcdir)/include -I$(top_srcdir)/compat @TASN1_CFLAGS@ @CFLAGS@
 
 if DEBUG
 AM_CFLAGS = -O0 -g3 -Wall -Wextra #-Werror
@@ -73,16 +73,16 @@ libdsm_la_SOURCES = \
     src/smb_transport.c     \
     src/smb_utils.c
 
-if COMPAT_STRLCPY
-libdsm_la_SOURCES += compat/strlcpy.c
-endif
+noinst_LTLIBRARIES = libcompat.la
+libcompat_la_SOURCES = compat/compat.c
+libcompat_la_LIBADD = $(LTLIBOBJS)
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libdsm.pc
 
+libdsm_la_LIBADD = libcompat.la
 libdsm_la_LDFLAGS = -version-info @BDSM_LIBTOOL_VERSION@ @LTLIBICONV@ @TASN1_LIBS@
 
-
 bin_PROGRAMS =
 
 if PROGRAMS

+ 8 - 0
compat/compat.c

@@ -0,0 +1,8 @@
+/* This file is just a placeholder so the library isn't empty */
+
+/* This function does strictly nothing. It's just here to avoid
+   libcompat.a to be empty, which is illegal */
+int not_empty()
+{
+    return (42);
+}

+ 23 - 0
compat/compat.h

@@ -0,0 +1,23 @@
+//---------------------------------------------------------------------------
+//  __________________    _________  _____            _____  .__         ._.
+//  \______   \______ \  /   _____/ /     \          /  _  \ |__| ____   | |
+//   |    |  _/|    |  \ \_____  \ /  \ /  \        /  /_\  \|  _/ __ \  | |
+//   |    |   \|    `   \/        /    Y    \      /    |    |  \  ___/   \|
+//   |______  /_______  /_______  \____|__  / /\   \____|__  |__|\___ |   __
+//          \/        \/        \/        \/  )/           \/        \/   \/
+//
+// This file is part of libdsm. Copyright © 2014 Author(s)
+//
+// Author: Julien 'Lta' BALLET <contact@lta.io>
+//
+// This program is free software. It comes without any warranty, to the extent
+// permitted by applicable law. You can redistribute it and/or modify it under
+// the terms of the Do What The Fuck You Want To Public License, Version 2, as
+// published by Sam Hocevar. See the COPYING file for more details.
+//----------------------------------------------------------------------------
+
+#include "config.h"
+
+#if !defined HAVE_strlcpy && !defined HAVE_LIBBSD
+size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif

+ 2 - 4
configure.ac

@@ -4,6 +4,7 @@ AC_INIT([libdsm], [m4_esyscmd([./package_version.sh])],
   [], [libdsm], [])
 AC_CONFIG_HEADER(config.h)
 AC_CONFIG_SRCDIR([include/bdsm.h])
+AC_CONFIG_LIBOBJ_DIR([compat])
 AM_INIT_AUTOMAKE([1.6 foreign subdir-objects tar-ustar dist-zip])
 m4_ifdef([AM_SILENT_RULES], [
   AM_SILENT_RULES([yes])
@@ -79,11 +80,8 @@ AS_IF([test x"$HAVE_TASN1_3PLUS" = x"yes"], [
 
 AC_SEARCH_LIBS([strlcpy], [bsd], [
   AC_DEFINE([HAVE_LIBBSD], [1], [Does this system have libbsd strl*** functions implementation])
-], [
-  compat_strlcpy=yes
-  AC_MSG_WARN([unable to find the strlcpy() function (missing libbsd?)])
 ])
-AM_CONDITIONAL(COMPAT_STRLCPY, [test x$compat_strlcpy = xyes])
+AC_REPLACE_FUNCS([strlcpy])
 
 AC_CHECK_HEADERS([bsd/string.h])
 AC_CHECK_HEADERS([langinfo.h])

+ 4 - 1
src/smb_ntlm.c

@@ -24,11 +24,14 @@
 #include <sys/time.h>
 #include <unistd.h>
 #include <fcntl.h>
+
+#include "config.h"
 #ifdef HAVE_BSD_STRING_H
 #include <bsd/string.h>
+#else
+#include "compat.h"
 #endif
 
-#include "config.h"
 #include "mdx/md4.h"
 #include "rc4/rc4.h"
 #include "bdsm/debug.h"