OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include <stdlib.h> | |
9 | |
10 #include "TempDir.h" | |
11 | |
12 #include "SkCommandLineFlags.h" | |
13 #include "SkOSFile.h" | |
14 | |
15 DEFINE_string2(tmpDir, t, NULL, "Temp directory to use."); | |
mtklein
2015/01/18 22:57:55
It doesn't look like anyone sets this flag.
So, a
hal.canary
2015/01/20 16:01:52
Done.
| |
16 | |
17 static bool nonempty_string(const char s[]) { return s && s[0]; } | |
18 | |
19 // Logic borrowed from | |
20 // https://docs.python.org/2/library/tempfile.html#tempfile.tempdir | |
mtklein
2015/01/18 22:57:55
Let's not do this. This is way more complicated t
hal.canary
2015/01/20 16:01:52
Done.
| |
21 SkString sk_tools::GetTmpDir() { | |
22 const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0]; | |
23 if (nonempty_string(tmpDir)) { | |
mtklein
2015/01/18 22:57:55
This seems like a weird way to write
if (!FLAGS_t
hal.canary
2015/01/20 16:01:52
Acknowledged.
| |
24 return SkString(tmpDir); | |
25 } | |
26 | |
27 const char* const kVariables[] = {"TMPDIR", "TEMP", "TMP"}; | |
mtklein
2015/01/18 22:57:55
Why are we getting so complicated with features no
hal.canary
2015/01/20 16:01:52
Acknowledged.
| |
28 for (size_t i = 0; i < SK_ARRAY_COUNT(kVariables); ++i) { | |
29 tmpDir = getenv(kVariables[i]); | |
30 if (nonempty_string(tmpDir)) { | |
31 return SkString(tmpDir); | |
32 } | |
33 } | |
34 | |
35 #ifdef SK_BUILD_FOR_WIN | |
36 const char* const kDirectories[] = { | |
37 "C:\\TEMP", "C:\\TMP", "\\TEMP", "\\TMP"}; | |
38 #else | |
39 const char* const kDirectories[] = {"/tmp", "/var/tmp", "/usr/tmp"}; | |
40 #endif | |
41 | |
42 for (size_t i = 0; i < SK_ARRAY_COUNT(kDirectories); ++i) { | |
43 if (sk_isdir(kDirectories[i])) { | |
44 return SkString(kDirectories[i]); | |
45 } | |
46 } | |
47 return SkString("."); | |
mtklein
2015/01/18 22:57:55
This seems like a bad idea. I'd rather return no
hal.canary
2015/01/20 16:01:52
Acknowledged.
| |
48 } | |
OLD | NEW |