OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/linux/tests/scoped_temporary_file.h" | 5 #include "sandbox/linux/tests/scoped_temporary_file.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 | 14 |
15 namespace sandbox { | 15 namespace sandbox { |
16 | 16 |
17 ScopedTemporaryFile::ScopedTemporaryFile() : fd_(-1) { | 17 ScopedTemporaryFile::ScopedTemporaryFile() : fd_(-1) { |
18 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
19 static const char file_template[] = "/data/local/tmp/ScopedTempFileXXXXXX"; | 19 static const char file_template[] = "/data/local/tmp/ScopedTempFileXXXXXX"; |
20 #else | 20 #else |
21 static const char file_template[] = "/tmp/ScopedTempFileXXXXXX"; | 21 static const char file_template[] = "/tmp/ScopedTempFileXXXXXX"; |
22 #endif // defined(OS_ANDROID) | 22 #endif // defined(OS_ANDROID) |
23 COMPILE_ASSERT(sizeof(full_file_name_) >= sizeof(file_template), | 23 static_assert(sizeof(full_file_name_) >= sizeof(file_template), |
24 full_file_name_is_large_enough); | 24 "full_file_name is not large enough"); |
25 memcpy(full_file_name_, file_template, sizeof(file_template)); | 25 memcpy(full_file_name_, file_template, sizeof(file_template)); |
26 fd_ = mkstemp(full_file_name_); | 26 fd_ = mkstemp(full_file_name_); |
27 CHECK_LE(0, fd_); | 27 CHECK_LE(0, fd_); |
28 } | 28 } |
29 | 29 |
30 ScopedTemporaryFile::~ScopedTemporaryFile() { | 30 ScopedTemporaryFile::~ScopedTemporaryFile() { |
31 CHECK_EQ(0, unlink(full_file_name_)); | 31 CHECK_EQ(0, unlink(full_file_name_)); |
32 CHECK_EQ(0, IGNORE_EINTR(close(fd_))); | 32 CHECK_EQ(0, IGNORE_EINTR(close(fd_))); |
33 } | 33 } |
34 | 34 |
35 } // namespace sandbox | 35 } // namespace sandbox |
OLD | NEW |