]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Mon, 22 Aug 2011 19:52:31 +0000 (12:52 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 22 Aug 2011 19:52:31 +0000 (12:52 -0700)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/posix.h
open-vm-tools/lib/misc/posixPosix.c

index 361fe567a6b6799b047ff47a43596282cf72ba55..79a33f2435ce8a9643d9023bd3b4aedd22ae0b77 100644 (file)
@@ -86,6 +86,7 @@ int Posix_Chdir(ConstUnicode pathName);
 Unicode Posix_Getenv(ConstUnicode name);
 long Posix_Pathconf(ConstUnicode pathName, int name);
 int Posix_Lstat(ConstUnicode pathName, struct stat *statbuf);
+Unicode Posix_MkTemp(ConstUnicode pathName);
 
 #if !defined(_WIN32)
 /*
index 340017faf0803cd7cb6dce2fd45af51fa17a79b8..6c0df44f53c2e9ebc96ea0d3bdfe171376487131 100644 (file)
@@ -3259,5 +3259,45 @@ Posix_Getmntent(FILE *fp,           // IN:
 
    return ret;
 }
-
 #endif // } !defined(sun)
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Posix_MkTemp --
+ *
+ *      POSIX mktemp().  It is implemented via mkstemp() to avoid
+ *      warning about using dangerous mktemp() API - but note that
+ *      it suffers from all mktemp() problems - caller has to use
+ *      O_EXCL when creating file, and retry if file already exists.
+ *
+ * Results:
+ *      NULL    Error
+ *      !NULL   Success (result must be freed by the caller)
+ *
+ * Side effects:
+ *      errno is set on error
+ *
+ *----------------------------------------------------------------------
+ */
+
+Unicode
+Posix_MkTemp(ConstUnicode pathName)  // IN:
+{
+   Unicode result = NULL;
+   char *path;
+   int fd;
+
+   if (!PosixConvertToCurrent(pathName, &path)) {
+      return NULL;
+   }
+   fd = mkstemp(path);
+   if (fd >= 0) {
+      close(fd);
+      unlink(path);
+      result = Unicode_Alloc(path, STRING_ENCODING_DEFAULT);
+   }
+   free(path);
+   return result;
+}