This is really a replacement for a missing platform function, so use
the same LIBOBJS mechanism to replace it.
---
configure.ac | 2 +-
lib/get_current_dir_name.h | 49 +++++++++++++++++++
.../get_current_dir_name.c | 10 ++--
.../include => lib}/test-current-dir-name.c | 2 +-
plugins/floppy/virtual-floppy.c | 4 +-
server/utils.c | 3 +-
.gitignore | 2 +-
common/include/Makefile.am | 6 ---
lib/Makefile.am | 10 ++++
plugins/floppy/Makefile.am | 1 +
10 files changed, 70 insertions(+), 19 deletions(-)
diff --git a/configure.ac b/configure.ac
index c5a23a5..8c2d9c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,12 +207,12 @@ AC_CHECK_HEADERS([\
dnl Check for functions in libc, all optional.
AC_CHECK_FUNCS([\
fdatasync \
- get_current_dir_name \
mkostemp])
dnl Replacement functions that we provide for some platforms.
AC_CONFIG_LIBOBJ_DIR([lib])
AC_REPLACE_FUNCS([\
+ get_current_dir_name \
getdelim \
getline \
openlog \
diff --git a/lib/get_current_dir_name.h b/lib/get_current_dir_name.h
new file mode 100644
index 0000000..95d4d47
--- /dev/null
+++ b/lib/get_current_dir_name.h
@@ -0,0 +1,49 @@
+/* nbdkit
+ * Copyright (C) 2018 Red Hat Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Red Hat nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef NBDKIT_GET_CURRENT_DIR_NAME_H
+#define NBDKIT_GET_CURRENT_DIR_NAME_H
+
+#include <config.h>
+
+#ifdef HAVE_GET_CURRENT_DIR_NAME
+
+#include <unistd.h>
+
+#else
+
+extern char *get_current_dir_name (void);
+
+#endif
+
+#endif /* NBDKIT_GET_CURRENT_DIR_NAME_H */
diff --git a/common/include/get-current-dir-name.h b/lib/get_current_dir_name.c
similarity index 93%
rename from common/include/get-current-dir-name.h
rename to lib/get_current_dir_name.c
index d99c1ad..5c018e2 100644
--- a/common/include/get-current-dir-name.h
+++ b/lib/get_current_dir_name.c
@@ -33,9 +33,6 @@
/* Implement get_current_dir_name(3) on platforms which don't have it. */
-#ifndef NBDKIT_GET_CURRENT_DIR_NAME_H
-#define NBDKIT_GET_CURRENT_DIR_NAME_H
-
#include <config.h>
#ifndef HAVE_GET_CURRENT_DIR_NAME
@@ -44,7 +41,9 @@
#include <unistd.h>
#include <limits.h>
-static inline char *
+#include "get_current_dir_name.h"
+
+char *
get_current_dir_name (void)
{
char *ret;
@@ -57,6 +56,5 @@ get_current_dir_name (void)
return NULL;
return realloc (ret, strlen (ret) + 1);
}
-#endif
-#endif /* NBDKIT_GET_CURRENT_DIR_NAME_H */
+#endif /* !HAVE_GET_CURRENT_DIR_NAME */
diff --git a/common/include/test-current-dir-name.c b/lib/test-current-dir-name.c
similarity index 98%
rename from common/include/test-current-dir-name.c
rename to lib/test-current-dir-name.c
index e2415dd..dfcba76 100644
--- a/common/include/test-current-dir-name.c
+++ b/lib/test-current-dir-name.c
@@ -40,7 +40,7 @@
#include <unistd.h>
#include <assert.h>
-#include "get-current-dir-name.h"
+#include "get_current_dir_name.h"
int
main (void)
diff --git a/plugins/floppy/virtual-floppy.c b/plugins/floppy/virtual-floppy.c
index 5b52e0e..9313767 100644
--- a/plugins/floppy/virtual-floppy.c
+++ b/plugins/floppy/virtual-floppy.c
@@ -48,12 +48,12 @@
#include <nbdkit-plugin.h>
-#include "get-current-dir-name.h"
-
#include "byte-swapping.h"
#include "regions.h"
#include "rounding.h"
+#include "get_current_dir_name.h"
+
#include "virtual-floppy.h"
/* This is the Windows 98 OEM name, and some sites recommend using it
diff --git a/server/utils.c b/server/utils.c
index 3799490..d67ec43 100644
--- a/server/utils.c
+++ b/server/utils.c
@@ -44,11 +44,10 @@
#include <termios.h>
#include <errno.h>
-#include "get-current-dir-name.h"
-
#include "internal.h"
#include "realpath.h"
#include "getline.h"
+#include "get_current_dir_name.h"
char *
nbdkit_absolute_path (const char *path)
diff --git a/.gitignore b/.gitignore
index 34a5657..35561e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,7 +26,6 @@ Makefile.in
/autom4te.cache
/common/bitmap/test-bitmap
/common/include/test-byte-swapping
-/common/include/test-current-dir-name
/common/include/test-isaligned
/common/include/test-ispowerof2
/common/include/test-iszero
@@ -48,6 +47,7 @@ Makefile.in
/INSTALL
/install-sh
/lib/libcompat.a
+/lib/test-current-dir-name
/lib/win32/MSG00001.bin
/lib/win32/nbdkit-cat.h
/lib/win32/nbdkit-cat.rc
diff --git a/common/include/Makefile.am b/common/include/Makefile.am
index 6bb2285..aa0ca52 100644
--- a/common/include/Makefile.am
+++ b/common/include/Makefile.am
@@ -37,7 +37,6 @@ include $(top_srcdir)/common-rules.mk
EXTRA_DIST = \
byte-swapping.h \
exit-with-parent.h \
- get-current-dir-name.h \
isaligned.h \
ispowerof2.h \
iszero.h \
@@ -50,7 +49,6 @@ EXTRA_DIST = \
TESTS = \
test-byte-swapping \
- test-current-dir-name \
test-isaligned \
test-ispowerof2 \
test-iszero \
@@ -62,10 +60,6 @@ test_byte_swapping_SOURCES = test-byte-swapping.c byte-swapping.h
test_byte_swapping_CPPFLAGS = -I$(srcdir)
test_byte_swapping_CFLAGS = $(WARNINGS_CFLAGS)
-test_current_dir_name_SOURCES = test-current-dir-name.c get-current-dir-name.h
-test_current_dir_name_CPPFLAGS = -I$(srcdir)
-test_current_dir_name_CFLAGS = $(WARNINGS_CFLAGS)
-
test_isaligned_SOURCES = test-isaligned.c isaligned.h
test_isaligned_CPPFLAGS = -I$(srcdir)
test_isaligned_CFLAGS = $(WARNINGS_CFLAGS)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 5051099..5d73ac3 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -40,6 +40,8 @@ libcompat_la_SOURCES =
libcompat_la_LIBADD = $(LTLIBOBJS)
EXTRA_DIST = \
+ get_current_dir_name.c \
+ get_current_dir_name.h \
getdelim.c \
getline.c \
getline.h \
@@ -51,3 +53,11 @@ EXTRA_DIST = \
syslog.c \
syslog.h \
vsyslog.c
+
+TESTS = \
+ test-current-dir-name
+check_PROGRAMS = $(TESTS)
+
+test_current_dir_name_SOURCES = test-current-dir-name.c get_current_dir_name.h
+test_current_dir_name_CPPFLAGS = -I$(srcdir)
+test_current_dir_name_CFLAGS = $(WARNINGS_CFLAGS)
diff --git a/plugins/floppy/Makefile.am b/plugins/floppy/Makefile.am
index 499e2e9..202cebd 100644
--- a/plugins/floppy/Makefile.am
+++ b/plugins/floppy/Makefile.am
@@ -46,6 +46,7 @@ nbdkit_floppy_plugin_la_SOURCES = \
$(top_srcdir)/include/nbdkit-plugin.h
nbdkit_floppy_plugin_la_CPPFLAGS = \
+ -I$(top_srcdir)/lib \
-I$(top_srcdir)/include \
-I$(top_srcdir)/common/include \
-I$(top_srcdir)/common/regions \
--
2.20.1