summaryrefslogtreecommitdiff
path: root/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp')
-rw-r--r--gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
index 0b92dccde4a..7ef499ce07b 100644
--- a/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ b/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -19,6 +19,7 @@
#include "sanitizer_common.h"
#include "sanitizer_file.h"
+# include "sanitizer_interface_internal.h"
namespace __sanitizer {
@@ -75,6 +76,24 @@ void ReportFile::ReopenIfNecessary() {
fd_pid = pid;
}
+static void RecursiveCreateParentDirs(char *path) {
+ if (path[0] == '\0')
+ return;
+ for (int i = 1; path[i] != '\0'; ++i) {
+ char save = path[i];
+ if (!IsPathSeparator(path[i]))
+ continue;
+ path[i] = '\0';
+ if (!DirExists(path) && !CreateDir(path)) {
+ const char *ErrorMsgPrefix = "ERROR: Can't create directory: ";
+ WriteToFile(kStderrFd, ErrorMsgPrefix, internal_strlen(ErrorMsgPrefix));
+ WriteToFile(kStderrFd, path, internal_strlen(path));
+ Die();
+ }
+ path[i] = save;
+ }
+}
+
void ReportFile::SetReportPath(const char *path) {
if (path) {
uptr len = internal_strlen(path);
@@ -95,6 +114,7 @@ void ReportFile::SetReportPath(const char *path) {
fd = kStdoutFd;
} else {
internal_snprintf(path_prefix, kMaxPathLength, "%s", path);
+ RecursiveCreateParentDirs(path_prefix);
}
}