summaryrefslogtreecommitdiff
path: root/cpu_ref
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-02-23 18:25:55 -0800
committerYabin Cui <yabinc@google.com>2015-02-24 13:35:50 -0800
commit433558f0f9abbf07770db288183a15fd261cace2 (patch)
tree20ae0cee2f9f1228a7cac9fed707b80288e62c5a /cpu_ref
parent96652efab9f341b4f3aa4a9f9357d3b09ba3fbb2 (diff)
downloadrs-433558f0f9abbf07770db288183a15fd261cace2.tar.gz
Move use of tempnam to mkstemp.
Bug: 19340053 Change-Id: I1734e085beef395ebcc6453af1efaa19f7409e22
Diffstat (limited to 'cpu_ref')
-rw-r--r--cpu_ref/rsCpuScriptGroup2.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/cpu_ref/rsCpuScriptGroup2.cpp b/cpu_ref/rsCpuScriptGroup2.cpp
index 80c46a03..27b8def4 100644
--- a/cpu_ref/rsCpuScriptGroup2.cpp
+++ b/cpu_ref/rsCpuScriptGroup2.cpp
@@ -1,6 +1,9 @@
#include "rsCpuScriptGroup2.h"
#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <string>
#include <vector>
@@ -288,10 +291,17 @@ void Batch::tryToCreateFusedKernel(const char *cacheDir) {
slots.push_back(kernelID->mSlot);
}
- string outputPath(tempnam(cacheDir, "fused"));
- string outputFileName = getFileName(outputPath);
- string objFilePath(outputPath);
- objFilePath.append(".o");
+ rsAssert(cacheDir != nullptr);
+ string objFilePath(cacheDir);
+ objFilePath.append("/fusedXXXXXX.o");
+ // Find unique object file name, to make following file names unique.
+ int tempfd = mkstemps(&objFilePath[0], 2);
+ if (tempfd == -1) {
+ return;
+ }
+ TEMP_FAILURE_RETRY(close(tempfd));
+
+ string outputFileName = getFileName(objFilePath.substr(0, objFilePath.size() - 2));
string rsLibPath(SYSLIBPATH"/libclcore.bc");
vector<const char*> arguments;
setupCompileArguments(inputFiles, slots, cacheDir, outputFileName, rsLibPath,
@@ -300,6 +310,7 @@ void Batch::tryToCreateFusedKernel(const char *cacheDir) {
convertListToString(arguments.size() - 1, arguments.data());
if (!fuseAndCompile(arguments.data(), commandLine)) {
+ unlink(objFilePath.c_str());
return;
}