shall libreplace become a public library (Was: Re: [SCM] Samba Shared Repository - branch master updated)

Christian Ambach ambi at samba.org
Fri Nov 29 14:56:07 MST 2013


Hi Andrew,

Am 26.11.13 23:57, schrieb Andrew Bartlett:

>> There is no real platform-specific include involved here, and I chose to
>> directly use sys/stat.h here as it is part of the Open Group standards
>> (and so it should be available virtually everywhere) and it is also
>> included directly at other places in the Samba source tree.
>
> We shouldn't be doing that.  We should always go via our system headers.

Ok.. this is also what the majority of the code does.

>> lib/replace/system/filesys.h also unconditionally includes <sys/stat.h>,
>> so I did not see the need to use the replace header.
> Yes, we should avoid those, but we should also always use the libreplace
> headers.

Unfortunately, it is not possible to do this in all spots.
In the attached patchset, I have changed a lot of files to eliminate
inconsistencies.

However, I failed for the file that the thread was started for.
In order to remove the include in lib/util/samba_util.h, which is part
of the public library samba-util, I would have to add a dependency of
this library to replace, which is not a public library yet.
Or is there another way to make this work (that I missed)?

So what shall we do? Is it worth the efforts (and do we really want to
expose replace as a public library) to fix this inconsistency?
Or shall we leave the affected two header files of two of our public
libraries (see list below) in their current state?

After applying the patchset, the following will still remain:

# some example code, probably not worth fixing
examples/libsmbclient/teststat2.c:#include <sys/stat.h>
examples/libsmbclient/teststat3.c:#include <sys/stat.h>
examples/perfcounter/perf.h:#include <sys/stat.h>

#test code
lib/ccan/failtest/failtest.c:#include <sys/stat.h>
lib/ccan/failtest/failtest_override.h:#include <sys/stat.h>

# the one that sparked of the discussion
lib/util/samba_util.h:#include <sys/stat.h>

# not used in Samba
lib/zlib/contrib/minizip/minizip.c:# include <sys/stat.h>
lib/zlib/contrib/puff/puff.c:#include <sys/stat.h>
lib/zlib/examples/gun.c:#include <sys/stat.h>
lib/zlib/minigzip.c:# include <sys/stat.h>

# another header of a public library
source3/include/libsmbclient.h:#include <sys/stat.h>

#unused code
source3/script/tests/dlopen.sh:#include <sys/stat.h>

# heimdal
source4/heimdal/lib/asn1/asn1_gen.c:#include <sys/stat.h>
source4/heimdal/lib/asn1/der.c:#include <sys/stat.h>
source4/heimdal/lib/roken/roken.h.in:#include <sys/stat.h>

#configure tests, no replace around at at that time
tests/ftruncate.c:#include <sys/stat.h>
tests/readlink.c:#include <sys/stat.h>
tests/shared_mmap.c:#include <sys/stat.h>

# orphaned code
testsuite/nsswitch/getgrent_r.c:#include <sys/stat.h>
testsuite/nsswitch/getpwent_r.c:#include <sys/stat.h>

Cheers,
Christian

-------------- next part --------------
From f6195d2cc4318a08a7ac74e7acc41a7f7c1f5b8f Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:09:08 +0100
Subject: [PATCH 01/10] s3:utils remove orphaned code

this does not even compile at all.. looks like a real orphan
---
 source3/utils/smbw_sample.c | 96 ---------------------------------------------
 1 file changed, 96 deletions(-)
 delete mode 100644 source3/utils/smbw_sample.c

diff --git a/source3/utils/smbw_sample.c b/source3/utils/smbw_sample.c
deleted file mode 100644
index 2c4a20f..0000000
--- a/source3/utils/smbw_sample.c
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-static void usage(void)
-{
-	printf("
-smbw_sample - a sample program that uses smbw
-
-smbw_sample <options> path
-
-  options:
-     -W workgroup
-     -l logfile
-     -P prefix
-     -d debuglevel
-     -U username%%password
-     -R resolve order
-
-note that path must start with /smb/
-");
-}
-
-int main(int argc, char *argv[])
-{
-	DIR *dir;
-	struct dirent *dent;
-	int opt;
-	char *p;
-	extern char *optarg;
-	extern int optind;
-	char *path;
-	TALLOC_CTX *frame = talloc_stackframe();
-
-	lp_load_global(get_dyn_CONFIGFILE());
-	smbw_setup_shared();
-
-	while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) {
-		switch (opt) {
-		case 'W':
-			smbw_setshared("WORKGROUP", optarg);
-			break;
-		case 'l':
-			smbw_setshared("LOGFILE", optarg);
-			break;
-		case 'P':
-			smbw_setshared("PREFIX", optarg);
-			break;
-		case 'd':
-			smbw_setshared("DEBUG", optarg);
-			break;
-		case 'U':
-			p = strchr_m(optarg,'%');
-			if (p) {
-				*p=0;
-				smbw_setshared("PASSWORD",p+1);
-			}
-			smbw_setshared("USER", optarg);
-			break;
-		case 'R':
-			smbw_setshared("RESOLVE_ORDER",optarg);
-			break;
-		case 'h':
-		default:
-			usage();
-			exit(1);
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	if (argc < 1) {
-		usage();
-		exit(1);
-	}
-
-	path = argv[0];
-
-	smbw_init();
-
-	dir = smbw_opendir(path);
-	if (!dir) {
-		printf("failed to open %s\n", path);
-		exit(1);
-	}
-	
-	while ((dent = smbw_readdir(dir))) {
-		printf("%s\n", dent->d_name);
-	}
-	smbw_closedir(dir);
-	TALLOC_FREE(frame);
-	return 0;
-}
-- 
1.8.1.2


From 55a26402981fd2b13bffa1ac978bdacd5303a09b Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:11:01 +0100
Subject: [PATCH 02/10] lib/replace remove orphaned code

this is not compiled and used anymore
---
 lib/replace/repdir_getdents.c      | 166 ---------------------------------
 lib/replace/repdir_getdirentries.c | 183 -------------------------------------
 2 files changed, 349 deletions(-)
 delete mode 100644 lib/replace/repdir_getdents.c
 delete mode 100644 lib/replace/repdir_getdirentries.c

diff --git a/lib/replace/repdir_getdents.c b/lib/replace/repdir_getdents.c
deleted file mode 100644
index afc634a..0000000
--- a/lib/replace/repdir_getdents.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-
-   Copyright (C) Andrew Tridgell 2005
-
-     ** NOTE! The following LGPL license applies to the replace
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
-   
-   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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-/*
-  a replacement for opendir/readdir/telldir/seekdir/closedir for BSD systems
-
-  This is needed because the existing directory handling in FreeBSD
-  and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink()
-  on files in a directory where telldir() has been used. On a block
-  boundary it will occasionally miss a file when seekdir() is used to
-  return to a position previously recorded with telldir().
-
-  This also fixes a severe performance and memory usage problem with
-  telldir() on BSD systems. Each call to telldir() in BSD adds an
-  entry to a linked list, and those entries are cleaned up on
-  closedir(). This means with a large directory closedir() can take an
-  arbitrary amount of time, causing network timeouts as millions of
-  telldir() entries are freed
-
-  Note! This replacement code is not portable. It relies on getdents()
-  always leaving the file descriptor at a seek offset that is a
-  multiple of DIR_BUF_SIZE. If the code detects that this doesn't
-  happen then it will abort(). It also does not handle directories
-  with offsets larger than can be stored in a long,
-
-  This code is available under other free software licenses as
-  well. Contact the author.
-*/
-
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#define DIR_BUF_BITS 9
-#define DIR_BUF_SIZE (1<<DIR_BUF_BITS)
-
-struct dir_buf {
-	int fd;
-	int nbytes, ofs;
-	off_t seekpos;
-	char buf[DIR_BUF_SIZE];
-};
-
-DIR *opendir(const char *dname)
-{
-	struct dir_buf *d;
-	struct stat sb;
-	d = malloc(sizeof(*d));
-	if (d == NULL) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	d->fd = open(dname, O_RDONLY);
-	if (d->fd == -1) {
-		free(d);
-		return NULL;
-	}
-	if (fstat(d->fd, &sb) < 0) {
-		close(d->fd);
-		free(d);
-		return NULL;
-	}
-	if (!S_ISDIR(sb.st_mode)) {
-		close(d->fd);
-		free(d);   
-		errno = ENOTDIR;
-		return NULL;
-	}
-	d->ofs = 0;
-	d->seekpos = 0;
-	d->nbytes = 0;
-	return (DIR *)d;
-}
-
-struct dirent *readdir(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	struct dirent *de;
-
-	if (d->ofs >= d->nbytes) {
-		d->seekpos = lseek(d->fd, 0, SEEK_CUR);
-		d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE);
-		d->ofs = 0;
-	}
-	if (d->ofs >= d->nbytes) {
-		return NULL;
-	}
-	de = (struct dirent *)&d->buf[d->ofs];
-	d->ofs += de->d_reclen;
-	return de;
-}
-
-long telldir(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	if (d->ofs >= d->nbytes) {
-		d->seekpos = lseek(d->fd, 0, SEEK_CUR);
-		d->ofs = 0;
-		d->nbytes = 0;
-	}
-	/* this relies on seekpos always being a multiple of
-	   DIR_BUF_SIZE. Is that always true on BSD systems? */
-	if (d->seekpos & (DIR_BUF_SIZE-1)) {
-		abort();
-	}
-	return d->seekpos + d->ofs;
-}
-
-void seekdir(DIR *dir, long ofs)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET);
-	d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE);
-	d->ofs = 0;
-	while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) {
-		if (readdir(dir) == NULL) break;
-	}
-}
-
-void rewinddir(DIR *dir)
-{
-	seekdir(dir, 0);
-}
-
-int closedir(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	int r = close(d->fd);
-	if (r != 0) {
-		return r;
-	}
-	free(d);
-	return 0;
-}
-
-#ifndef dirfd
-/* darn, this is a macro on some systems. */
-int dirfd(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	return d->fd;
-}
-#endif
diff --git a/lib/replace/repdir_getdirentries.c b/lib/replace/repdir_getdirentries.c
deleted file mode 100644
index 197e593..0000000
--- a/lib/replace/repdir_getdirentries.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-
-   Copyright (C) Andrew Tridgell 2005
-
-     ** NOTE! The following LGPL license applies to the replace
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
-   
-   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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-/*
-  a replacement for opendir/readdir/telldir/seekdir/closedir for BSD
-  systems using getdirentries
-
-  This is needed because the existing directory handling in FreeBSD
-  and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink()
-  on files in a directory where telldir() has been used. On a block
-  boundary it will occasionally miss a file when seekdir() is used to
-  return to a position previously recorded with telldir().
-
-  This also fixes a severe performance and memory usage problem with
-  telldir() on BSD systems. Each call to telldir() in BSD adds an
-  entry to a linked list, and those entries are cleaned up on
-  closedir(). This means with a large directory closedir() can take an
-  arbitrary amount of time, causing network timeouts as millions of
-  telldir() entries are freed
-
-  Note! This replacement code is not portable. It relies on
-  getdirentries() always leaving the file descriptor at a seek offset
-  that is a multiple of DIR_BUF_SIZE. If the code detects that this
-  doesn't happen then it will abort(). It also does not handle
-  directories with offsets larger than can be stored in a long,
-
-  This code is available under other free software licenses as
-  well. Contact the author.
-*/
-
-#include "replace.h"
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#define DIR_BUF_BITS 9
-#define DIR_BUF_SIZE (1<<DIR_BUF_BITS)
-
-struct dir_buf {
-	int fd;
-	int nbytes, ofs;
-	off_t seekpos;
-	char buf[DIR_BUF_SIZE];
-};
-
-DIR *opendir(const char *dname)
-{
-	struct dir_buf *d;
-	struct stat sb;
-	d = malloc(sizeof(*d));
-	if (d == NULL) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	d->fd = open(dname, O_RDONLY);
-	if (d->fd == -1) {
-		free(d);
-		return NULL;
-	}
-	if (fstat(d->fd, &sb) < 0) {
-		close(d->fd);
-		free(d);
-		return NULL;
-	}
-	if (!S_ISDIR(sb.st_mode)) {
-		close(d->fd);
-		free(d);   
-		errno = ENOTDIR;
-		return NULL;
-	}
-	d->ofs = 0;
-	d->seekpos = 0;
-	d->nbytes = 0;
-	return (DIR *)d;
-}
-
-struct dirent *readdir(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	struct dirent *de;
-
-	if (d->ofs >= d->nbytes) {
-		long pos;
-		d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos);
-		d->seekpos = pos;
-		d->ofs = 0;
-	}
-	if (d->ofs >= d->nbytes) {
-		return NULL;
-	}
-	de = (struct dirent *)&d->buf[d->ofs];
-	d->ofs += de->d_reclen;
-	return de;
-}
-
-#ifdef TELLDIR_TAKES_CONST_DIR
-long telldir(const DIR *dir)
-#else
-long telldir(DIR *dir)
-#endif
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	if (d->ofs >= d->nbytes) {
-		d->seekpos = lseek(d->fd, 0, SEEK_CUR);
-		d->ofs = 0;
-		d->nbytes = 0;
-	}
-	/* this relies on seekpos always being a multiple of
-	   DIR_BUF_SIZE. Is that always true on BSD systems? */
-	if (d->seekpos & (DIR_BUF_SIZE-1)) {
-		abort();
-	}
-	return d->seekpos + d->ofs;
-}
-
-#ifdef SEEKDIR_RETURNS_INT
-int seekdir(DIR *dir, long ofs)
-#else
-void seekdir(DIR *dir, long ofs)
-#endif
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	long pos;
-	d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET);
-	d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos);
-	d->ofs = 0;
-	while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) {
-		if (readdir(dir) == NULL) break;
-	}
-#ifdef SEEKDIR_RETURNS_INT
-	return -1;
-#endif
-}
-
-void rewinddir(DIR *dir)
-{
-	seekdir(dir, 0);
-}
-
-int closedir(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	int r = close(d->fd);
-	if (r != 0) {
-		return r;
-	}
-	free(d);
-	return 0;
-}
-
-#ifndef dirfd
-/* darn, this is a macro on some systems. */
-int dirfd(DIR *dir)
-{
-	struct dir_buf *d = (struct dir_buf *)dir;
-	return d->fd;
-}
-#endif
-
-
-- 
1.8.1.2


From 7a291da6ceee07e9716933f9446cba32fff2058a Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:12:05 +0100
Subject: [PATCH 03/10] s3:lib/asys modify included headers

use the headers from libreplace, not the system ones
---
 source3/lib/asys/asys.h        | 6 ++----
 source3/lib/asys/wscript_build | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/source3/lib/asys/asys.h b/source3/lib/asys/asys.h
index 73f1051..468ac3f 100644
--- a/source3/lib/asys/asys.h
+++ b/source3/lib/asys/asys.h
@@ -19,10 +19,8 @@
 #ifndef __ASYS_H__
 #define __ASYS_H__
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+#include "../lib/replace/replace.h"
+#include "../lib/replace/system/filesys.h"
 
 /**
  * @defgroup asys The async syscall library
diff --git a/source3/lib/asys/wscript_build b/source3/lib/asys/wscript_build
index 15de977..dca56c7 100644
--- a/source3/lib/asys/wscript_build
+++ b/source3/lib/asys/wscript_build
@@ -2,7 +2,7 @@
 
 bld.SAMBA3_SUBSYSTEM('LIBASYS',
 		     source='asys.c',
-		     deps='PTHREADPOOL')
+		     deps='PTHREADPOOL replace')
 
 bld.SAMBA3_BINARY('asystest',
 		  source='tests.c',
-- 
1.8.1.2


From 02ccfef3355768599d3aeb38e89455cd7839d3a5 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:13:17 +0100
Subject: [PATCH 04/10] s3:vfs_btrfs change includes

use the ones from libreplace instead of system ones
---
 source3/modules/vfs_btrfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/source3/modules/vfs_btrfs.c b/source3/modules/vfs_btrfs.c
index c6e90fd..2254fa2 100644
--- a/source3/modules/vfs_btrfs.c
+++ b/source3/modules/vfs_btrfs.c
@@ -20,10 +20,9 @@
 #include <linux/ioctl.h>
 #include <linux/fs.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include "system/filesys.h"
 #include "includes.h"
 #include "smbd/smbd.h"
 #include "librpc/gen_ndr/smbXsrv.h"
-- 
1.8.1.2


From 076c5c06615014ba9ab1f9eb633751bfe52af1c7 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:13:56 +0100
Subject: [PATCH 05/10] s3:pam_smbpass change includes

use the ones from libreplace instead of system ones
---
 source3/pam_smbpass/general.h | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/source3/pam_smbpass/general.h b/source3/pam_smbpass/general.h
index 6e13f8d..1d022ec 100644
--- a/source3/pam_smbpass/general.h
+++ b/source3/pam_smbpass/general.h
@@ -21,13 +21,10 @@
 #define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <syslog.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
+#include "../../lib/replace/replace.h"
+#include "../../lib/replace/system/filesys.h"
+#include "../../lib/replace/system/wait.h"
+#include "../../lib/replace/system/syslog.h"
 
 /*
  * here is the string to inform the user that the new passwords they
-- 
1.8.1.2


From aa957b139e0245e46702e3854d8b4bb1b99124a0 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:15:13 +0100
Subject: [PATCH 06/10] lib/socket_wrapper fix compilation when libreplace is
 not around

---
 lib/socket_wrapper/socket_wrapper.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index 3c9d0f1..8f12592 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -56,7 +56,6 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
-#include <sys/filio.h>
 #include <errno.h>
 #include <sys/un.h>
 #include <netinet/in.h>
@@ -67,9 +66,31 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <arpa/inet.h>
+
+#ifndef MIN
+#define MIN(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#ifndef discard_const
+#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
+#endif
+
+#ifndef discard_const_p
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+#endif
+
+/**
+ * zero a structure
+ */
+#ifndef ZERO_STRUCT
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+#endif
 
 #endif /* HAVE_LIBREPLACE */
 
+#include "socket_wrapper.h"
+
 #ifndef _PUBLIC_
 #define _PUBLIC_
 #endif
-- 
1.8.1.2


From 8956a7f433bae414ef4244a302aff90ea65dacd5 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:15:59 +0100
Subject: [PATCH 07/10] lib/ntdb: fix compilation when libreplace is not around

---
 lib/ntdb/ntdb.c |  1 -
 lib/ntdb/ntdb.h | 10 ++++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/ntdb/ntdb.c b/lib/ntdb/ntdb.c
index 5d56b33..51fbbca 100644
--- a/lib/ntdb/ntdb.c
+++ b/lib/ntdb/ntdb.c
@@ -17,7 +17,6 @@
 */
 #include "private.h"
 #ifndef HAVE_LIBREPLACE
-#include <ccan/asprintf/asprintf.h>
 #include <stdarg.h>
 #endif
 
diff --git a/lib/ntdb/ntdb.h b/lib/ntdb/ntdb.h
index df3a9dd..a3a627f 100644
--- a/lib/ntdb/ntdb.h
+++ b/lib/ntdb/ntdb.h
@@ -31,10 +31,20 @@ extern "C" {
 
 #ifdef HAVE_LIBREPLACE
 #include <replace.h>
+#include <system/filesys.h>
 #else
 #if HAVE_FILE_OFFSET_BITS
 #define _FILE_OFFSET_BITS 64
 #endif
+
+#ifndef _PUBLIC_
+#ifdef HAVE_VISIBILITY_ATTR
+#define _PUBLIC_ __attribute__((visibility("default")))
+#else
+#define _PUBLIC_
+#endif
+#endif
+
 /* For mode_t */
 #include <sys/types.h>
 /* For O_* flags. */
-- 
1.8.1.2


From baaca3e8c59fc9160eae10c86a6683ce4d685895 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:17:38 +0100
Subject: [PATCH 08/10] lib/ntdb: correct includes in private header

include all necessary headers when libreplace is not around
---
 lib/ntdb/private.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/ntdb/private.h b/lib/ntdb/private.h
index 5efd2e0..2492537 100644
--- a/lib/ntdb/private.h
+++ b/lib/ntdb/private.h
@@ -35,6 +35,7 @@
 #include "system/select.h"
 #include "system/wait.h"
 #else
+#include <stdarg.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -47,6 +48,10 @@
 #include <stdio.h>
 #include <utime.h>
 #include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <time.h>
 #endif
 #include <assert.h>
 
-- 
1.8.1.2


From ab15379effa255925d85fa7c4cb0bec95e4868f9 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:18:36 +0100
Subject: [PATCH 09/10] lib/ntdb optimize includes in ntdb tests

use the private header (which will use libreplace or system headers) instead of direct includes of system includes
---
 lib/ntdb/test/api-12-store.c                  | 4 +---
 lib/ntdb/test/api-13-delete.c                 | 3 ---
 lib/ntdb/test/api-14-exists.c                 | 4 +---
 lib/ntdb/test/api-16-wipe_all.c               | 4 +---
 lib/ntdb/test/api-20-alloc-attr.c             | 4 +---
 lib/ntdb/test/api-21-parse_record.c           | 4 +---
 lib/ntdb/test/api-55-transaction.c            | 3 ---
 lib/ntdb/test/api-60-noop-transaction.c       | 3 ---
 lib/ntdb/test/api-80-tdb_fd.c                 | 4 +---
 lib/ntdb/test/api-81-seqnum.c                 | 4 +---
 lib/ntdb/test/api-82-lockattr.c               | 3 ---
 lib/ntdb/test/api-83-openhook.c               | 8 +-------
 lib/ntdb/test/api-91-get-stats.c              | 6 +-----
 lib/ntdb/test/api-92-get-set-readonly.c       | 4 +---
 lib/ntdb/test/api-93-repack.c                 | 4 +---
 lib/ntdb/test/api-94-expand-during-parse.c    | 3 ---
 lib/ntdb/test/api-95-read-only-during-parse.c | 4 +---
 lib/ntdb/test/api-add-remove-flags.c          | 3 ---
 lib/ntdb/test/api-check-callback.c            | 4 +---
 lib/ntdb/test/api-firstkey-nextkey.c          | 5 +----
 lib/ntdb/test/api-fork-test.c                 | 8 +-------
 lib/ntdb/test/api-locktimeout.c               | 7 +------
 lib/ntdb/test/api-missing-entries.c           | 4 +---
 lib/ntdb/test/api-open-multiple-times.c       | 3 ---
 lib/ntdb/test/api-record-expand.c             | 5 +----
 lib/ntdb/test/api-simple-delete.c             | 4 +---
 lib/ntdb/test/api-summary.c                   | 5 +----
 27 files changed, 20 insertions(+), 97 deletions(-)

diff --git a/lib/ntdb/test/api-12-store.c b/lib/ntdb/test/api-12-store.c
index 45274e0..532a8ee 100644
--- a/lib/ntdb/test/api-12-store.c
+++ b/lib/ntdb/test/api-12-store.c
@@ -1,10 +1,8 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
 #include <ccan/hash/hash.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 
 #include "logging.h"
 
diff --git a/lib/ntdb/test/api-13-delete.c b/lib/ntdb/test/api-13-delete.c
index cded8fd..730ade5 100644
--- a/lib/ntdb/test/api-13-delete.c
+++ b/lib/ntdb/test/api-13-delete.c
@@ -1,8 +1,5 @@
 #include "private.h" // For NTDB_TOPLEVEL_HASH_BITS
 #include <ccan/hash/hash.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "ntdb.h"
 #include "tap-interface.h"
 #include "logging.h"
diff --git a/lib/ntdb/test/api-14-exists.c b/lib/ntdb/test/api-14-exists.c
index abaaae0..c40d901 100644
--- a/lib/ntdb/test/api-14-exists.c
+++ b/lib/ntdb/test/api-14-exists.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 static bool test_records(struct ntdb_context *ntdb)
diff --git a/lib/ntdb/test/api-16-wipe_all.c b/lib/ntdb/test/api-16-wipe_all.c
index 6a60752..4eea151 100644
--- a/lib/ntdb/test/api-16-wipe_all.c
+++ b/lib/ntdb/test/api-16-wipe_all.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 static bool add_records(struct ntdb_context *ntdb)
diff --git a/lib/ntdb/test/api-20-alloc-attr.c b/lib/ntdb/test/api-20-alloc-attr.c
index e4ec89a..3df5003 100644
--- a/lib/ntdb/test/api-20-alloc-attr.c
+++ b/lib/ntdb/test/api-20-alloc-attr.c
@@ -1,10 +1,8 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
 #include <ccan/hash/hash.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <assert.h>
 
 #include "logging.h"
diff --git a/lib/ntdb/test/api-21-parse_record.c b/lib/ntdb/test/api-21-parse_record.c
index 975bbfa..5af9abe 100644
--- a/lib/ntdb/test/api-21-parse_record.c
+++ b/lib/ntdb/test/api-21-parse_record.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 static enum NTDB_ERROR parse(NTDB_DATA key, NTDB_DATA data, NTDB_DATA *expected)
diff --git a/lib/ntdb/test/api-55-transaction.c b/lib/ntdb/test/api-55-transaction.c
index 01a1dce..3d3e539 100644
--- a/lib/ntdb/test/api-55-transaction.c
+++ b/lib/ntdb/test/api-55-transaction.c
@@ -1,9 +1,6 @@
 #include "private.h" // struct ntdb_context
 #include "ntdb.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include "logging.h"
 
diff --git a/lib/ntdb/test/api-60-noop-transaction.c b/lib/ntdb/test/api-60-noop-transaction.c
index a429e67..5e56dbc 100644
--- a/lib/ntdb/test/api-60-noop-transaction.c
+++ b/lib/ntdb/test/api-60-noop-transaction.c
@@ -1,9 +1,6 @@
 #include "private.h" // struct ntdb_context
 #include "ntdb.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include "logging.h"
 
diff --git a/lib/ntdb/test/api-80-tdb_fd.c b/lib/ntdb/test/api-80-tdb_fd.c
index 81b7284..ca520a9 100644
--- a/lib/ntdb/test/api-80-tdb_fd.c
+++ b/lib/ntdb/test/api-80-tdb_fd.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 int main(int argc, char *argv[])
diff --git a/lib/ntdb/test/api-81-seqnum.c b/lib/ntdb/test/api-81-seqnum.c
index 04f49cd..45963ff 100644
--- a/lib/ntdb/test/api-81-seqnum.c
+++ b/lib/ntdb/test/api-81-seqnum.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include "logging.h"
 
diff --git a/lib/ntdb/test/api-82-lockattr.c b/lib/ntdb/test/api-82-lockattr.c
index 4fbe1d2..f71600c 100644
--- a/lib/ntdb/test/api-82-lockattr.c
+++ b/lib/ntdb/test/api-82-lockattr.c
@@ -1,9 +1,6 @@
 #include "private.h" // for ntdb_fcntl_unlock
 #include "ntdb.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <errno.h>
 #include "logging.h"
 
diff --git a/lib/ntdb/test/api-83-openhook.c b/lib/ntdb/test/api-83-openhook.c
index 3816eef..d2930ac 100644
--- a/lib/ntdb/test/api-83-openhook.c
+++ b/lib/ntdb/test/api-83-openhook.c
@@ -1,13 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdarg.h>
-#include <unistd.h>
 #include "external-agent.h"
 #include "logging.h"
 
diff --git a/lib/ntdb/test/api-91-get-stats.c b/lib/ntdb/test/api-91-get-stats.c
index 1ed36f0..1041cba 100644
--- a/lib/ntdb/test/api-91-get-stats.c
+++ b/lib/ntdb/test/api-91-get-stats.c
@@ -1,11 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stddef.h>
 #include "logging.h"
 
 int main(int argc, char *argv[])
diff --git a/lib/ntdb/test/api-92-get-set-readonly.c b/lib/ntdb/test/api-92-get-set-readonly.c
index 81eadff..c557f34 100644
--- a/lib/ntdb/test/api-92-get-set-readonly.c
+++ b/lib/ntdb/test/api-92-get-set-readonly.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 int main(int argc, char *argv[])
diff --git a/lib/ntdb/test/api-93-repack.c b/lib/ntdb/test/api-93-repack.c
index 4a30c57..0fade08 100644
--- a/lib/ntdb/test/api-93-repack.c
+++ b/lib/ntdb/test/api-93-repack.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 #define NUM_TESTS 1000
diff --git a/lib/ntdb/test/api-94-expand-during-parse.c b/lib/ntdb/test/api-94-expand-during-parse.c
index 4963e47..3aca88b 100644
--- a/lib/ntdb/test/api-94-expand-during-parse.c
+++ b/lib/ntdb/test/api-94-expand-during-parse.c
@@ -2,9 +2,6 @@
 #include "config.h"
 #include "ntdb.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 #include "../private.h" /* To establish size, esp. for NTDB_INTERNAL dbs */
 
diff --git a/lib/ntdb/test/api-95-read-only-during-parse.c b/lib/ntdb/test/api-95-read-only-during-parse.c
index 8252b81..53adbc3 100644
--- a/lib/ntdb/test/api-95-read-only-during-parse.c
+++ b/lib/ntdb/test/api-95-read-only-during-parse.c
@@ -1,10 +1,8 @@
 /* Make sure write operations fail during ntdb_parse(). */
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 static struct ntdb_context *ntdb;
diff --git a/lib/ntdb/test/api-add-remove-flags.c b/lib/ntdb/test/api-add-remove-flags.c
index c5a3f42..c16ceeb 100644
--- a/lib/ntdb/test/api-add-remove-flags.c
+++ b/lib/ntdb/test/api-add-remove-flags.c
@@ -1,9 +1,6 @@
 #include "private.h" // for ntdb_context
 #include "ntdb.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 int main(int argc, char *argv[])
diff --git a/lib/ntdb/test/api-check-callback.c b/lib/ntdb/test/api-check-callback.c
index b5ca8a0..20c88e7 100644
--- a/lib/ntdb/test/api-check-callback.c
+++ b/lib/ntdb/test/api-check-callback.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 #define NUM_RECORDS 1000
diff --git a/lib/ntdb/test/api-firstkey-nextkey.c b/lib/ntdb/test/api-firstkey-nextkey.c
index 5e83e6b..179cf76 100644
--- a/lib/ntdb/test/api-firstkey-nextkey.c
+++ b/lib/ntdb/test/api-firstkey-nextkey.c
@@ -1,10 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
 #include "logging.h"
 
 #define NUM_RECORDS 1000
diff --git a/lib/ntdb/test/api-fork-test.c b/lib/ntdb/test/api-fork-test.c
index 6298a4a..4b114d6 100644
--- a/lib/ntdb/test/api-fork-test.c
+++ b/lib/ntdb/test/api-fork-test.c
@@ -12,14 +12,8 @@
  */
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include "logging.h"
 
 static bool am_child = false;
diff --git a/lib/ntdb/test/api-locktimeout.c b/lib/ntdb/test/api-locktimeout.c
index 5e24d58..4c0fda2 100644
--- a/lib/ntdb/test/api-locktimeout.c
+++ b/lib/ntdb/test/api-locktimeout.c
@@ -1,13 +1,8 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include "system/wait.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <fcntl.h>
 #include <limits.h>
-#include <errno.h>
 #include "logging.h"
 #include "external-agent.h"
 
diff --git a/lib/ntdb/test/api-missing-entries.c b/lib/ntdb/test/api-missing-entries.c
index d9a1fd9..2a00f1b3 100644
--- a/lib/ntdb/test/api-missing-entries.c
+++ b/lib/ntdb/test/api-missing-entries.c
@@ -1,11 +1,9 @@
 /* Another test revealed that we lost an entry.  This reproduces it. */
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include <ccan/hash/hash.h>
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 #define NUM_RECORDS 1189
diff --git a/lib/ntdb/test/api-open-multiple-times.c b/lib/ntdb/test/api-open-multiple-times.c
index 8663b8a..6b97bc9 100644
--- a/lib/ntdb/test/api-open-multiple-times.c
+++ b/lib/ntdb/test/api-open-multiple-times.c
@@ -1,9 +1,6 @@
 #include "config.h"
 #include "ntdb.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include "logging.h"
 #include "../private.h"
diff --git a/lib/ntdb/test/api-record-expand.c b/lib/ntdb/test/api-record-expand.c
index 8786fc7..74fb27f 100644
--- a/lib/ntdb/test/api-record-expand.c
+++ b/lib/ntdb/test/api-record-expand.c
@@ -1,10 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
 #include "logging.h"
 
 #define MAX_SIZE 10000
diff --git a/lib/ntdb/test/api-simple-delete.c b/lib/ntdb/test/api-simple-delete.c
index dedc433..e8baf4c 100644
--- a/lib/ntdb/test/api-simple-delete.c
+++ b/lib/ntdb/test/api-simple-delete.c
@@ -1,9 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "logging.h"
 
 int main(int argc, char *argv[])
diff --git a/lib/ntdb/test/api-summary.c b/lib/ntdb/test/api-summary.c
index df5d092..af1b595 100644
--- a/lib/ntdb/test/api-summary.c
+++ b/lib/ntdb/test/api-summary.c
@@ -1,10 +1,7 @@
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include "tap-interface.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
 #include "logging.h"
 
 int main(int argc, char *argv[])
-- 
1.8.1.2


From 832a335f79bb20b15eb263e516d341846b5348b7 Mon Sep 17 00:00:00 2001
From: Christian Ambach <ambi at samba.org>
Date: Fri, 22 Nov 2013 05:19:16 +0100
Subject: [PATCH 10/10] lib/ntdb optimize includes in ntdb tools

use the private header (which will use libreplace or system headers) instead of direct includes of system includes
---
 lib/ntdb/tools/growtdb-bench.c |  3 ---
 lib/ntdb/tools/ntdbbackup.c    |  2 +-
 lib/ntdb/tools/ntdbdump.c      | 14 +-------------
 lib/ntdb/tools/ntdbrestore.c   | 11 +----------
 lib/ntdb/tools/ntdbtool.c      | 18 +-----------------
 lib/ntdb/tools/ntdbtorture.c   | 16 +---------------
 lib/ntdb/tools/speed.c         |  2 --
 7 files changed, 5 insertions(+), 61 deletions(-)

diff --git a/lib/ntdb/tools/growtdb-bench.c b/lib/ntdb/tools/growtdb-bench.c
index aa5a406..28c1de8 100644
--- a/lib/ntdb/tools/growtdb-bench.c
+++ b/lib/ntdb/tools/growtdb-bench.c
@@ -4,9 +4,6 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <ccan/err/err.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 
 static void logfn(struct ntdb_context *ntdb,
 		  enum ntdb_log_level level,
diff --git a/lib/ntdb/tools/ntdbbackup.c b/lib/ntdb/tools/ntdbbackup.c
index a76f184..c632f0e 100644
--- a/lib/ntdb/tools/ntdbbackup.c
+++ b/lib/ntdb/tools/ntdbbackup.c
@@ -42,7 +42,7 @@
 
 #include "config.h"
 #include "ntdb.h"
-#include "system/filesys.h"
+#include "private.h"
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
diff --git a/lib/ntdb/tools/ntdbdump.c b/lib/ntdb/tools/ntdbdump.c
index 1b1c59e..fc83796 100644
--- a/lib/ntdb/tools/ntdbdump.c
+++ b/lib/ntdb/tools/ntdbdump.c
@@ -18,19 +18,7 @@
 */
 #include "config.h"
 #include "ntdb.h"
-#ifdef HAVE_LIBREPLACE
-#include <replace.h>
-#include <system/filesys.h>
-#include <system/locale.h>
-#else
-#include <ctype.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#endif
+#include "private.h"
 
 static void print_data(NTDB_DATA d)
 {
diff --git a/lib/ntdb/tools/ntdbrestore.c b/lib/ntdb/tools/ntdbrestore.c
index 1df9322..695af79 100644
--- a/lib/ntdb/tools/ntdbrestore.c
+++ b/lib/ntdb/tools/ntdbrestore.c
@@ -20,17 +20,8 @@
 
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include <assert.h>
-#ifdef HAVE_LIBREPLACE
-#include <replace.h>
-#include <system/filesys.h>
-#else
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#endif
 
 static int read_linehead(FILE *f)
 {
diff --git a/lib/ntdb/tools/ntdbtool.c b/lib/ntdb/tools/ntdbtool.c
index 7c1ef7d..144cd92 100644
--- a/lib/ntdb/tools/ntdbtool.c
+++ b/lib/ntdb/tools/ntdbtool.c
@@ -22,23 +22,7 @@
 
 #include "config.h"
 #include "ntdb.h"
-#ifdef HAVE_LIBREPLACE
-#include <replace.h>
-#include <system/filesys.h>
-#include <system/time.h>
-#include <system/locale.h>
-#else
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#endif
+#include "private.h"
 
 static int do_command(void);
 const char *cmdname;
diff --git a/lib/ntdb/tools/ntdbtorture.c b/lib/ntdb/tools/ntdbtorture.c
index 7ddb5c3..9fd25ca 100644
--- a/lib/ntdb/tools/ntdbtorture.c
+++ b/lib/ntdb/tools/ntdbtorture.c
@@ -4,22 +4,8 @@
 
 #include "config.h"
 #include "ntdb.h"
+#include "private.h"
 #include <ccan/err/err.h>
-#ifdef HAVE_LIBREPLACE
-#include <replace.h>
-#else
-#include <stdlib.h>
-#include <getopt.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/wait.h>
-#endif
 
 //#define REOPEN_PROB 30
 #define DELETE_PROB 8
diff --git a/lib/ntdb/tools/speed.c b/lib/ntdb/tools/speed.c
index 8928d8c..a829321 100644
--- a/lib/ntdb/tools/speed.c
+++ b/lib/ntdb/tools/speed.c
@@ -1,8 +1,6 @@
 /* Simple speed test for NTDB */
 #include <ccan/err/err.h>
 #include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <sys/time.h>
 #include <fcntl.h>
-- 
1.8.1.2


More information about the samba-technical mailing list