lib-util: Make create_unlink_tmp argument optional
authorSimo Sorce <idra@samba.org>
Thu, 21 Apr 2011 14:04:06 +0000 (10:04 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 10 Aug 2011 16:14:02 +0000 (18:14 +0200)
Use tmpdir() if no dir is provided.

Signed-off-by: Andreas Schneider <asn@samba.org>
lib/util/util.c

index 4dd79266aff240eb28e5196005ecadf87dbce6ba..2d1d83036d36b85faf82e6e4b2951695f93bc59d 100644 (file)
@@ -3,7 +3,7 @@
    Samba utility functions
    Copyright (C) Andrew Tridgell 1992-1998
    Copyright (C) Jeremy Allison 2001-2002
-   Copyright (C) Simo Sorce 2001
+   Copyright (C) Simo Sorce 2001-2011
    Copyright (C) Jim McDonough (jmcd@us.ibm.com)  2003.
    Copyright (C) James J Myers 2003
    Copyright (C) Volker Lendecke 2010
@@ -63,6 +63,7 @@ _PUBLIC_ const char *tmpdir(void)
 
 /**
  Create a tmp file, open it and immediately unlink it.
+ If dir is NULL uses tmpdir()
  Returns the file descriptor or -1 on error.
 **/
 int create_unlink_tmp(const char *dir)
@@ -70,6 +71,10 @@ int create_unlink_tmp(const char *dir)
        char *fname;
        int fd;
 
+       if (!dir) {
+               dir = tmpdir();
+       }
+
        fname = talloc_asprintf(talloc_tos(), "%s/listenerlock_XXXXXX", dir);
        if (fname == NULL) {
                errno = ENOMEM;