From ba45beb562bbed7baefc4018946270d271bdbded Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Tue, 27 Jun 2000 03:35:32 +0000 Subject: [PATCH] Bug 43314. r=Henry Sobotka a=brendan@mozilla.org s=Robert O'Callahan git-svn-id: svn://10.0.0.236/trunk@73281 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsLocalFileOS2.cpp | 6 ++++-- mozilla/xpcom/io/nsLocalFileUnix.cpp | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mozilla/xpcom/io/nsLocalFileOS2.cpp b/mozilla/xpcom/io/nsLocalFileOS2.cpp index 61c92589fd7..9b4a4ddf427 100644 --- a/mozilla/xpcom/io/nsLocalFileOS2.cpp +++ b/mozilla/xpcom/io/nsLocalFileOS2.cpp @@ -740,8 +740,10 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) if (type == NORMAL_FILE_TYPE) { - PRFileDesc* file = PR_Open(mResolvedPath, PR_RDONLY | PR_CREATE_FILE | PR_APPEND, attributes); - if (file) PR_Close(file); + PRFileDesc* file = PR_Open(mResolvedPath, PR_RDONLY | PR_CREATE_FILE | PR_APPEND | PR_EXCL, attributes); + if (!file) return NS_ERROR_FILE_ALREADY_EXISTS; + + PR_Close(file); return NS_OK; } diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index d3466931496..93a5c206ba6 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -363,6 +363,9 @@ nsLocalFile::OpenANSIFileDesc(const char *mode, FILE * *_retval) return NS_ERROR_FAILURE; } +static int exclusive_create(const char * path, mode_t mode) { + return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode); +} NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 permissions) @@ -378,7 +381,7 @@ nsLocalFile::Create(PRUint32 type, PRUint32 permissions) #else int (*creationFunc)(const char *, mode_t) = #endif - type == NORMAL_FILE_TYPE ? creat : mkdir; + type == NORMAL_FILE_TYPE ? exclusive_create : mkdir; result = creationFunc((const char *)mPath, permissions);