summaryrefslogtreecommitdiff
path: root/lib/util/util.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2011-04-21 09:45:27 -0400
committerAndreas Schneider <asn@samba.org>2011-08-10 18:14:02 +0200
commit05455b459a93f620143d90fd34a28e4485fd606a (patch)
tree5176d1a248ccc76fdff12cd5e8e0968b426b30ee /lib/util/util.c
parent185cd4c79492a7de5988f9407d764cdb3a0e2e10 (diff)
downloadsamba-05455b459a93f620143d90fd34a28e4485fd606a.tar.gz
samba-05455b459a93f620143d90fd34a28e4485fd606a.tar.bz2
samba-05455b459a93f620143d90fd34a28e4485fd606a.zip
lib-util: Make useful function a common utility.
Signed-off-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'lib/util/util.c')
-rw-r--r--lib/util/util.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 7f30d436e8..4dd79266af 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -6,6 +6,7 @@
Copyright (C) Simo Sorce 2001
Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
Copyright (C) James J Myers 2003
+ Copyright (C) Volker Lendecke 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -61,6 +62,37 @@ _PUBLIC_ const char *tmpdir(void)
/**
+ Create a tmp file, open it and immediately unlink it.
+ Returns the file descriptor or -1 on error.
+**/
+int create_unlink_tmp(const char *dir)
+{
+ char *fname;
+ int fd;
+
+ fname = talloc_asprintf(talloc_tos(), "%s/listenerlock_XXXXXX", dir);
+ if (fname == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ fd = mkstemp(fname);
+ if (fd == -1) {
+ TALLOC_FREE(fname);
+ return -1;
+ }
+ if (unlink(fname) == -1) {
+ int sys_errno = errno;
+ close(fd);
+ TALLOC_FREE(fname);
+ errno = sys_errno;
+ return -1;
+ }
+ TALLOC_FREE(fname);
+ return fd;
+}
+
+
+/**
Check if a file exists - call vfs_file_exist for samba files.
**/
_PUBLIC_ bool file_exist(const char *fname)