From: VMware, Inc <> Date: Mon, 22 Aug 2011 19:52:31 +0000 (-0700) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2011.08.21-471295~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc7b2a2f8555ea092352ea973462cbf5014ccb6f;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/posix.h b/open-vm-tools/lib/include/posix.h index 361fe567a..79a33f243 100644 --- a/open-vm-tools/lib/include/posix.h +++ b/open-vm-tools/lib/include/posix.h @@ -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) /* diff --git a/open-vm-tools/lib/misc/posixPosix.c b/open-vm-tools/lib/misc/posixPosix.c index 340017faf..6c0df44f5 100644 --- a/open-vm-tools/lib/misc/posixPosix.c +++ b/open-vm-tools/lib/misc/posixPosix.c @@ -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; +}