Skip to content

Commit

Permalink
Moved removeFile() and getUniqueFilename() into FileUtilities.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7691 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
mbrukman committed Aug 7, 2003
1 parent 57d708b commit 3d1b0c7
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 92 deletions.
10 changes: 10 additions & 0 deletions include/Support/FileUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ bool DiffFiles(const std::string &FileA, const std::string &FileB,
///
void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename);

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase);

#endif
10 changes: 0 additions & 10 deletions include/Support/SystemUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ bool isExecutableFile(const std::string &ExeFileName);
std::string FindExecutable(const std::string &ExeName,
const std::string &BugPointPath);

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename);

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase);

/// RunProgramWithTimeout - This function executes the specified program, with
/// the specified null-terminated argument array, with the stdin/out/err fd's
/// redirected, with a timeout specified on the commandline. This terminates
Expand Down
10 changes: 10 additions & 0 deletions include/llvm/Support/FileUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ bool DiffFiles(const std::string &FileA, const std::string &FileB,
///
void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename);

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase);

#endif
10 changes: 0 additions & 10 deletions include/llvm/Support/SystemUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ bool isExecutableFile(const std::string &ExeFileName);
std::string FindExecutable(const std::string &ExeName,
const std::string &BugPointPath);

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename);

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase);

/// RunProgramWithTimeout - This function executes the specified program, with
/// the specified null-terminated argument array, with the stdin/out/err fd's
/// redirected, with a timeout specified on the commandline. This terminates
Expand Down
35 changes: 35 additions & 0 deletions lib/Support/FileUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,38 @@ void MoveFileOverIfUpdated(const std::string &New, const std::string &Old) {
std::remove(New.c_str());
}
}

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename) {
std::remove(Filename.c_str());
}

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase) {
if (!std::ifstream(FilenameBase.c_str()))
return FilenameBase; // Couldn't open the file? Use it!

// Create a pattern for mkstemp...
char *FNBuffer = new char[FilenameBase.size()+8];
strcpy(FNBuffer, FilenameBase.c_str());
strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX");

// Agree on a temporary file name to use....
int TempFD;
if ((TempFD = mkstemp(FNBuffer)) == -1) {
std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current "
<< " directory!\n";
exit(1);
}

// We don't need to hold the temp file descriptor... we will trust that noone
// will overwrite/delete the file while we are working on it...
close(TempFD);
std::string Result(FNBuffer);
delete[] FNBuffer;
return Result;
}
37 changes: 1 addition & 36 deletions lib/Support/SystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
//===----------------------------------------------------------------------===//

#include "SystemUtils.h"
#include "Support/SystemUtils.h"
#include <algorithm>
#include <fstream>
#include <iostream>
Expand All @@ -17,41 +17,6 @@
#include "Config/unistd.h"
#include "Config/errno.h"

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename) {
std::remove(Filename.c_str());
}

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase) {
if (!std::ifstream(FilenameBase.c_str()))
return FilenameBase; // Couldn't open the file? Use it!

// Create a pattern for mkstemp...
char *FNBuffer = new char[FilenameBase.size()+8];
strcpy(FNBuffer, FilenameBase.c_str());
strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX");

// Agree on a temporary file name to use....
int TempFD;
if ((TempFD = mkstemp(FNBuffer)) == -1) {
std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current "
<< " directory!\n";
exit(1);
}

// We don't need to hold the temp file descriptor... we will trust that noone
// will overwrite/delete the file while we are working on it...
close(TempFD);
std::string Result(FNBuffer);
delete[] FNBuffer;
return Result;
}

/// isExecutableFile - This function returns true if the filename specified
/// exists and is executable.
///
Expand Down
35 changes: 35 additions & 0 deletions support/lib/Support/FileUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,38 @@ void MoveFileOverIfUpdated(const std::string &New, const std::string &Old) {
std::remove(New.c_str());
}
}

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename) {
std::remove(Filename.c_str());
}

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase) {
if (!std::ifstream(FilenameBase.c_str()))
return FilenameBase; // Couldn't open the file? Use it!

// Create a pattern for mkstemp...
char *FNBuffer = new char[FilenameBase.size()+8];
strcpy(FNBuffer, FilenameBase.c_str());
strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX");

// Agree on a temporary file name to use....
int TempFD;
if ((TempFD = mkstemp(FNBuffer)) == -1) {
std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current "
<< " directory!\n";
exit(1);
}

// We don't need to hold the temp file descriptor... we will trust that noone
// will overwrite/delete the file while we are working on it...
close(TempFD);
std::string Result(FNBuffer);
delete[] FNBuffer;
return Result;
}
37 changes: 1 addition & 36 deletions support/lib/Support/SystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
//===----------------------------------------------------------------------===//

#include "SystemUtils.h"
#include "Support/SystemUtils.h"
#include <algorithm>
#include <fstream>
#include <iostream>
Expand All @@ -17,41 +17,6 @@
#include "Config/unistd.h"
#include "Config/errno.h"

/// removeFile - Delete the specified file
///
void removeFile(const std::string &Filename) {
std::remove(Filename.c_str());
}

/// getUniqueFilename - Return a filename with the specified prefix. If the
/// file does not exist yet, return it, otherwise add a suffix to make it
/// unique.
///
std::string getUniqueFilename(const std::string &FilenameBase) {
if (!std::ifstream(FilenameBase.c_str()))
return FilenameBase; // Couldn't open the file? Use it!

// Create a pattern for mkstemp...
char *FNBuffer = new char[FilenameBase.size()+8];
strcpy(FNBuffer, FilenameBase.c_str());
strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX");

// Agree on a temporary file name to use....
int TempFD;
if ((TempFD = mkstemp(FNBuffer)) == -1) {
std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current "
<< " directory!\n";
exit(1);
}

// We don't need to hold the temp file descriptor... we will trust that noone
// will overwrite/delete the file while we are working on it...
close(TempFD);
std::string Result(FNBuffer);
delete[] FNBuffer;
return Result;
}

/// isExecutableFile - This function returns true if the filename specified
/// exists and is executable.
///
Expand Down

0 comments on commit 3d1b0c7

Please sign in to comment.