mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
Revert 91528 and use a std::vector instead, fixing an abuse of std::string.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101781 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
//=== is guaranteed to work on *all* UNIX variants.
|
//=== is guaranteed to work on *all* UNIX variants.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "Unix.h"
|
#include "Unix.h"
|
||||||
#if HAVE_SYS_STAT_H
|
#if HAVE_SYS_STAT_H
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -858,15 +859,20 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
|
|||||||
|
|
||||||
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
|
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
|
||||||
// mktemp or our own implementation.
|
// mktemp or our own implementation.
|
||||||
std::string Buf(path);
|
// This uses std::vector instead of SmallVector to avoid a dependence on
|
||||||
|
// libSupport. And performance isn't critical here.
|
||||||
|
std::vector<char> Buf;
|
||||||
|
Buf.resize(path.size()+8);
|
||||||
|
char *FNBuffer = Buf.data();
|
||||||
|
path.copy(FNBuffer,path.size());
|
||||||
if (isDirectory())
|
if (isDirectory())
|
||||||
Buf += "/XXXXXX";
|
strcpy(FNBuffer+path.size(), "/XXXXXX");
|
||||||
else
|
else
|
||||||
Buf += "-XXXXXX";
|
strcpy(FNBuffer+path.size(), "-XXXXXX");
|
||||||
|
|
||||||
#if defined(HAVE_MKSTEMP)
|
#if defined(HAVE_MKSTEMP)
|
||||||
int TempFD;
|
int TempFD;
|
||||||
if ((TempFD = mkstemp((char*)Buf.c_str())) == -1)
|
if ((TempFD = mkstemp(FNBuffer)) == -1)
|
||||||
return MakeErrMsg(ErrMsg, path + ": can't make unique filename");
|
return MakeErrMsg(ErrMsg, path + ": can't make unique filename");
|
||||||
|
|
||||||
// We don't need to hold the temp file descriptor... we will trust that no one
|
// We don't need to hold the temp file descriptor... we will trust that no one
|
||||||
@@ -874,21 +880,21 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) {
|
|||||||
close(TempFD);
|
close(TempFD);
|
||||||
|
|
||||||
// Save the name
|
// Save the name
|
||||||
path = Buf;
|
path = FNBuffer;
|
||||||
#elif defined(HAVE_MKTEMP)
|
#elif defined(HAVE_MKTEMP)
|
||||||
// If we don't have mkstemp, use the old and obsolete mktemp function.
|
// If we don't have mkstemp, use the old and obsolete mktemp function.
|
||||||
if (mktemp(Buf.c_str()) == 0)
|
if (mktemp(FNBuffer) == 0)
|
||||||
return MakeErrMsg(ErrMsg, path + ": can't make unique filename");
|
return MakeErrMsg(ErrMsg, path + ": can't make unique filename");
|
||||||
|
|
||||||
// Save the name
|
// Save the name
|
||||||
path = Buf;
|
path = FNBuffer;
|
||||||
#else
|
#else
|
||||||
// Okay, looks like we have to do it all by our lonesome.
|
// Okay, looks like we have to do it all by our lonesome.
|
||||||
static unsigned FCounter = 0;
|
static unsigned FCounter = 0;
|
||||||
unsigned offset = path.size() + 1;
|
unsigned offset = path.size() + 1;
|
||||||
while (FCounter < 999999 && exists()) {
|
while ( FCounter < 999999 && exists()) {
|
||||||
sprintf(Buf.data()+offset, "%06u", ++FCounter);
|
sprintf(FNBuffer+offset,"%06u",++FCounter);
|
||||||
path = Buf;
|
path = FNBuffer;
|
||||||
}
|
}
|
||||||
if (FCounter > 999999)
|
if (FCounter > 999999)
|
||||||
return MakeErrMsg(ErrMsg,
|
return MakeErrMsg(ErrMsg,
|
||||||
|
Reference in New Issue
Block a user