summaryrefslogtreecommitdiff
path: root/lib/util/xfile.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-10-11 21:52:55 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-10-11 21:52:55 +0200
commite439b3e7ab0d9f80f2606f5a7bee144ee143f4cf (patch)
tree92c1b8e947237c579d4aaa689e5271bef0afd1c1 /lib/util/xfile.c
parent7a27c07a2765020cb4a07073327bba1435e33f87 (diff)
downloadsamba-e439b3e7ab0d9f80f2606f5a7bee144ee143f4cf.tar.gz
samba-e439b3e7ab0d9f80f2606f5a7bee144ee143f4cf.tar.bz2
samba-e439b3e7ab0d9f80f2606f5a7bee144ee143f4cf.zip
Use xfile from common lib/util in Samba 3.
Conflicts: source3/Makefile.in
Diffstat (limited to 'lib/util/xfile.c')
-rw-r--r--lib/util/xfile.c31
1 files changed, 30 insertions, 1 deletions
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;
+}