Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright (c) 2012, Google Inc. | 1 // Copyright (c) 2012, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
11 // copyright notice, this list of conditions and the following disclaimer | 11 // copyright notice, this list of conditions and the following disclaimer |
12 // in the documentation and/or other materials provided with the | 12 // in the documentation and/or other materials provided with the |
13 // distribution. | 13 // distribution. |
14 // * Neither the name of Google Inc. nor the names of its | 14 // * Neither the name of Google Inc. nor the names of its |
15 // contributors may be used to endorse or promote products derived from | 15 // contributors may be used to endorse or promote products derived from |
16 // this software without specific prior written permission. | 16 // this software without specific prior written permission. |
17 // | 17 // |
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // Android doesn't provide mkdtemp(). Keep this implementation in an | 30 // mkdtemp() wasn't declared in <stdlib.h> until NDK r9b due to a simple |
31 // C++ anonymous namespace to avoid conflicts on Chromium (which | 31 // packaging bug (the function has always been implemented in all versions |
Mark Mentovai
2013/12/13 14:24:28
Oh, so it’s just a missing declaration?
Is there
digit
2013/12/13 15:40:19
Yes, just a missing declaration. There is no macro
| |
32 // already provides an extern "C" mkdtemp function). | 32 // of the C library). This header is provided to build Breakpad with earlier |
33 // NDK revisions (e.g. the one used by Chromium). It may be removed in the | |
34 // future once all major projects upgrade to use a more recent NDK. | |
33 // | 35 // |
34 // The reason this is inlined here is to avoid linking a new object file | 36 // The reason this is inlined here is to avoid linking a new object file |
35 // into each unit test program (i.e. keep build files simple). | 37 // into each unit test program (i.e. keep build files simple). |
36 | 38 |
37 #ifndef GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_MKDTEMP_H | 39 #ifndef GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_MKDTEMP_H |
38 #define GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_MKDTEMP_H | 40 #define GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_MKDTEMP_H |
39 | 41 |
40 #include <assert.h> | 42 #include <assert.h> |
41 #include <errno.h> | 43 #include <errno.h> |
42 #include <stdlib.h> | 44 #include <stdlib.h> |
43 #include <stdio.h> | 45 #include <stdio.h> |
44 #include <string.h> | 46 #include <string.h> |
45 #include <sys/stat.h> | 47 #include <sys/stat.h> |
46 | 48 |
49 // Using a macro renaming trick here is necessary when building against | |
50 // NDK r9b. Otherwise the compiler will complain that calls to mkdtemp() | |
51 // are ambiguous. | |
52 #define mkdtemp breakpad_mkdtemp | |
53 | |
47 namespace { | 54 namespace { |
48 | 55 |
49 char* mkdtemp(char* path) { | 56 char* breakpad_mkdtemp(char* path) { |
50 if (path == NULL) { | 57 if (path == NULL) { |
51 errno = EINVAL; | 58 errno = EINVAL; |
52 return NULL; | 59 return NULL; |
53 } | 60 } |
54 | 61 |
55 // 'path' must be terminated with six 'X' | 62 // 'path' must be terminated with six 'X' |
56 const char kSuffix[] = "XXXXXX"; | 63 const char kSuffix[] = "XXXXXX"; |
57 const size_t kSuffixLen = strlen(kSuffix); | 64 const size_t kSuffixLen = strlen(kSuffix); |
58 char* path_end = path + strlen(path); | 65 char* path_end = path + strlen(path); |
59 | 66 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 return NULL; | 101 return NULL; |
95 } | 102 } |
96 | 103 |
97 assert(errno == EEXIST); | 104 assert(errno == EEXIST); |
98 return NULL; | 105 return NULL; |
99 } | 106 } |
100 | 107 |
101 } // namespace | 108 } // namespace |
102 | 109 |
103 #endif // GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_MKDTEMP_H | 110 #endif // GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_MKDTEMP_H |
OLD | NEW |