summaryrefslogtreecommitdiff
path: root/source4/lib/replace
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-09-06 11:31:59 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:17:44 -0500
commit3ca73facc59ed8a97abbc28c1b4bedde87e109a6 (patch)
tree6959d7d7e546cf8be7e57eb9bcd1cdfb1170b412 /source4/lib/replace
parentd093b28b55bac53c32cf3bf35424ca967b55bfc5 (diff)
downloadsamba-3ca73facc59ed8a97abbc28c1b4bedde87e109a6.tar.gz
samba-3ca73facc59ed8a97abbc28c1b4bedde87e109a6.tar.bz2
samba-3ca73facc59ed8a97abbc28c1b4bedde87e109a6.zip
r18160: - pread and pwrite replacements need to be non-static
- replacing rename() is pointless - all platforms have it (and the #define of rename breaks some code) - use system/locale.h in snprintf.c - fix passwd.h for initgroups - stdlib is in replace.h, not needed elsewhere - fix the initgroups replacement - fix mapping of dl functions to rep_* (This used to be commit 57cd0ca176387d6a3acabf9fedeef4f2a3a3dad7)
Diffstat (limited to 'source4/lib/replace')
-rw-r--r--source4/lib/replace/dlfcn.c3
-rw-r--r--source4/lib/replace/getpass.c1
-rw-r--r--source4/lib/replace/replace.c29
-rw-r--r--source4/lib/replace/replace.h34
-rw-r--r--source4/lib/replace/snprintf.c17
-rw-r--r--source4/lib/replace/system/passwd.h5
-rw-r--r--source4/lib/replace/test/testsuite.c7
7 files changed, 36 insertions, 60 deletions
diff --git a/source4/lib/replace/dlfcn.c b/source4/lib/replace/dlfcn.c
index 79005c0d2b..e25ac9dfe5 100644
--- a/source4/lib/replace/dlfcn.c
+++ b/source4/lib/replace/dlfcn.c
@@ -24,7 +24,6 @@
*/
#include "replace.h"
-#include <stdlib.h>
#ifndef HAVE_DLOPEN
void *dlopen(const char *name, int flags)
@@ -41,7 +40,7 @@ void *dlsym(void *handle, const char *symbol)
#endif
#ifndef HAVE_DLERROR
-const char *dlerror(void)
+char *dlerror(void)
{
return "dynamic loading of objects not supported on this platform";
}
diff --git a/source4/lib/replace/getpass.c b/source4/lib/replace/getpass.c
index 05fb7976b9..2ccbf7b733 100644
--- a/source4/lib/replace/getpass.c
+++ b/source4/lib/replace/getpass.c
@@ -19,7 +19,6 @@ Cambridge, MA 02139, USA. */
/* Modified to use with samba by Jeremy Allison, 8th July 1995. */
#include "replace.h"
-#include <stdlib.h>
#if defined(HAVE_TERMIOS_H)
/* POSIX terminal handling. */
diff --git a/source4/lib/replace/replace.c b/source4/lib/replace/replace.c
index db07e49941..048ea3a998 100644
--- a/source4/lib/replace/replace.c
+++ b/source4/lib/replace/replace.c
@@ -30,6 +30,7 @@
#include "system/syslog.h"
#include "system/network.h"
#include "system/locale.h"
+#include "system/wait.h"
void replace_dummy(void);
void replace_dummy(void) {}
@@ -42,7 +43,7 @@ int rep_ftruncate(int f, off_t l)
{
#ifdef HAVE_CHSIZE
return chsize(f,l);
-#else
+#elif defined(F_FREESP)
struct flock fl;
fl.l_whence = 0;
@@ -50,6 +51,8 @@ int rep_ftruncate(int f, off_t l)
fl.l_start = l;
fl.l_type = F_WRLCK;
return fcntl(f, F_FREESP, &fl);
+#else
+#error "you must have a ftruncate function"
#endif
}
#endif /* HAVE_FTRUNCATE */
@@ -151,24 +154,6 @@ time_t rep_mktime(struct tm *t)
#endif /* !HAVE_MKTIME */
-
-#ifndef HAVE_RENAME
-/* Rename a file. (from libiberty in GNU binutils) */
-int rep_rename(const char *zfrom, const char *zto)
-{
- if (link (zfrom, zto) < 0)
- {
- if (errno != EEXIST)
- return -1;
- if (unlink (zto) < 0
- || link (zfrom, zto) < 0)
- return -1;
- }
- return unlink (zfrom);
-}
-#endif /* HAVE_RENAME */
-
-
#ifndef HAVE_INNETGR
#if defined(HAVE_SETNETGRENT) && defined(HAVE_GETNETGRENT) && defined(HAVE_ENDNETGRENT)
/*
@@ -211,7 +196,7 @@ int rep_initgroups(char *name, gid_t id)
#include <grp.h>
gid_t *grouplst = NULL;
- int max_gr = groups_max();
+ int max_gr = 32;
int ret;
int i,j;
struct group *g;
@@ -481,7 +466,7 @@ char *rep_mkdtemp(char *template)
#endif
#ifndef HAVE_PREAD
-static ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
+ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
{
if (lseek(__fd, __offset, SEEK_SET) != __offset) {
return -1;
@@ -491,7 +476,7 @@ static ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
#endif
#ifndef HAVE_PWRITE
-static ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
+ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
{
if (lseek(__fd, __offset, SEEK_SET) != __offset) {
return -1;
diff --git a/source4/lib/replace/replace.h b/source4/lib/replace/replace.h
index 38b4e08704..90fd994ca5 100644
--- a/source4/lib/replace/replace.h
+++ b/source4/lib/replace/replace.h
@@ -61,7 +61,6 @@
#include <strings.h>
#endif
-
#ifndef HAVE_STRERROR
extern char *sys_errlist[];
#define strerror(i) sys_errlist[i]
@@ -121,11 +120,6 @@ size_t rep_strnlen(const char *s, size_t n);
int rep_setenv(const char *name, const char *value, int overwrite);
#endif
-#ifndef HAVE_RENAME
-#define rename rep_rename
-int rep_rename(const char *zfrom, const char *zto);
-#endif
-
#ifndef HAVE_STRCASESTR
#define strcasestr rep_strcasestr
char *rep_strcasestr(const char *haystack, const char *needle);
@@ -148,13 +142,38 @@ unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
#ifndef HAVE_FTRUNCATE
#define ftruncate rep_ftruncate
-int rep_ftruncate(int f,long l);
+int rep_ftruncate(int,off_t);
+#endif
+
+#ifndef HAVE_INITGROUPS
+#define ftruncate rep_ftruncate
+int rep_initgroups(char *name, gid_t id);
#endif
#if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
#define bzero(a,b) memset((a),'\0',(b))
#endif
+#ifndef HAVE_DLERROR
+#define dlerror rep_dlerror
+char *rep_dlerror(void);
+#endif
+
+#ifndef HAVE_DLOPEN
+#define dlopen rep_dlopen
+void *rep_dlopen(const char *name, int flags);
+#endif
+
+#ifndef HAVE_DLSYM
+#define dlsym rep_dlsym
+void *rep_dlsym(void *handle, const char *symbol);
+#endif
+
+#ifndef HAVE_DLCLOSE
+#define dlclose rep_dlclose
+int rep_dlclose(void *handle);
+#endif
+
#ifndef PRINTF_ATTRIBUTE
#if __GNUC__ >= 3
@@ -195,6 +214,7 @@ int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
#ifndef HAVE_VA_COPY
+#undef va_copy
#ifdef HAVE___VA_COPY
#define va_copy(dest, src) __va_copy(dest, src)
#else
diff --git a/source4/lib/replace/snprintf.c b/source4/lib/replace/snprintf.c
index dd41ca3306..5416a9d3e2 100644
--- a/source4/lib/replace/snprintf.c
+++ b/source4/lib/replace/snprintf.c
@@ -104,6 +104,7 @@
**************************************************************/
#include "replace.h"
+#include "system/locale.h"
#ifdef TEST_SNPRINTF /* need math library headers for testing */
@@ -117,22 +118,6 @@
# include <math.h>
#endif /* TEST_SNPRINTF */
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#ifdef HAVE_CTYPE_H
-#include <ctype.h>
-#endif
-#include <sys/types.h>
-#include <stdarg.h>
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF)
/* only include stdio.h if we are not re-defining snprintf or vsnprintf */
#include <stdio.h>
diff --git a/source4/lib/replace/system/passwd.h b/source4/lib/replace/system/passwd.h
index 6f8d729a7c..21f31f0388 100644
--- a/source4/lib/replace/system/passwd.h
+++ b/source4/lib/replace/system/passwd.h
@@ -88,9 +88,4 @@
#define ULTRIX_AUTH 1
#endif
-
-#ifndef HAVE_INITGROUPS
-int initgroups(char *name,gid_t id);
-#endif
-
#endif
diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c
index ddc9550f61..33270d9a4a 100644
--- a/source4/lib/replace/test/testsuite.c
+++ b/source4/lib/replace/test/testsuite.c
@@ -120,12 +120,6 @@ static int test_mktime(void)
return true;
}
-static int test_rename(void)
-{
- /* FIXME */
- return true;
-}
-
static int test_innetgr(void)
{
/* FIXME */
@@ -378,7 +372,6 @@ int torture_local_replace(void *ctx)
ret &= test_strlcpy();
ret &= test_strlcat();
ret &= test_mktime();
- ret &= test_rename();
ret &= test_innetgr();
ret &= test_initgroups();
ret &= test_memmove();