From e439b3e7ab0d9f80f2606f5a7bee144ee143f4cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 11 Oct 2008 21:52:55 +0200 Subject: Use xfile from common lib/util in Samba 3. Conflicts: source3/Makefile.in --- lib/util/xfile.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util/xfile.c b/lib/util/xfile.c index a016031a77..b758b1fa9f 100644 --- a/lib/util/xfile.c +++ b/lib/util/xfile.c @@ -36,6 +36,13 @@ #include "includes.h" #include "system/filesys.h" +#if _SAMBA_BUILD_ == 3 +#undef malloc +#define malloc SMB_MALLOC +#undef malloc_p +#define malloc_p SMB_MALLOC_P +#endif + #define XBUFSIZE BUFSIZ static XFILE _x_stdin = { 0, NULL, NULL, XBUFSIZE, 0, O_RDONLY, X_IOFBF, 0 }; @@ -222,7 +229,7 @@ size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) } /* at least fileno() is simple! */ -int x_fileno(XFILE *f) +int x_fileno(const XFILE *f) { return f->fd; } @@ -387,3 +394,25 @@ off_t x_tseek(XFILE *f, off_t offset, int whence) f->flags &= ~X_FLAG_EOF; return lseek(f->fd, offset, whence); } + +XFILE *x_fdup(const XFILE *f) +{ + XFILE *ret; + int fd; + + fd = dup(x_fileno(f)); + if (fd < 0) { + return NULL; + } + + ret = SMB_CALLOC_ARRAY(XFILE, 1); + if (!ret) { + close(fd); + return NULL; + } + + ret->fd = fd; + ret->open_flags = f->open_flags; + x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE); + return ret; +} -- cgit