Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7 KiB

  1. //===- llvm/Support/FileUtilities.h - File System Utilities -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines a family of utility functions which are useful for doing
  11. // various things with files.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_FILEUTILITIES_H
  15. #define LLVM_SUPPORT_FILEUTILITIES_H
  16. #include "llvm/Support/FileSystem.h"
  17. #include "llvm/Support/Path.h"
  18. namespace llvm {
  19. /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
  20. /// the files match, 1 if they are different, and 2 if there is a file error.
  21. /// This function allows you to specify an absolute and relative FP error that
  22. /// is allowed to exist. If you specify a string to fill in for the error
  23. /// option, it will set the string to an error message if an error occurs, or
  24. /// if the files are different.
  25. ///
  26. int DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
  27. const sys::PathWithStatus &FileB,
  28. double AbsTol, double RelTol,
  29. std::string *Error = 0);
  30. /// FileRemover - This class is a simple object meant to be stack allocated.
  31. /// If an exception is thrown from a region, the object removes the filename
  32. /// specified (if deleteIt is true).
  33. ///
  34. class FileRemover {
  35. SmallString<128> Filename;
  36. bool DeleteIt;
  37. public:
  38. FileRemover() : DeleteIt(false) {}
  39. explicit FileRemover(const Twine& filename, bool deleteIt = true)
  40. : DeleteIt(deleteIt) {
  41. filename.toVector(Filename);
  42. }
  43. ~FileRemover() {
  44. if (DeleteIt) {
  45. // Ignore problems deleting the file.
  46. bool existed;
  47. sys::fs::remove(Filename.str(), existed);
  48. }
  49. }
  50. /// setFile - Give ownership of the file to the FileRemover so it will
  51. /// be removed when the object is destroyed. If the FileRemover already
  52. /// had ownership of a file, remove it first.
  53. void setFile(const Twine& filename, bool deleteIt = true) {
  54. if (DeleteIt) {
  55. // Ignore problems deleting the file.
  56. bool existed;
  57. sys::fs::remove(Filename.str(), existed);
  58. }
  59. Filename.clear();
  60. filename.toVector(Filename);
  61. DeleteIt = deleteIt;
  62. }
  63. /// releaseFile - Take ownership of the file away from the FileRemover so it
  64. /// will not be removed when the object is destroyed.
  65. void releaseFile() { DeleteIt = false; }
  66. };
  67. } // End llvm namespace
  68. #endif