OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #if defined(__ANDROID__) | 5 #if defined(__ANDROID__) |
6 // Post-L versions of bionic define the GNU-specific strerror_r if _GNU_SOURCE | 6 // Post-L versions of bionic define the GNU-specific strerror_r if _GNU_SOURCE |
7 // is defined, but the symbol is renamed to __gnu_strerror_r which only exists | 7 // is defined, but the symbol is renamed to __gnu_strerror_r which only exists |
8 // on those later versions. To preserve ABI compatibility with older versions, | 8 // on those later versions. To preserve ABI compatibility with older versions, |
9 // undefine _GNU_SOURCE and use the POSIX version. | 9 // undefine _GNU_SOURCE and use the POSIX version. |
10 #undef _GNU_SOURCE | 10 #undef _GNU_SOURCE |
11 #endif | 11 #endif |
12 | 12 |
13 #include "build/build_config.h" | 13 #include "base/posix/safe_strerror.h" |
14 #include "base/safe_strerror_posix.h" | |
15 | 14 |
16 #include <errno.h> | 15 #include <errno.h> |
17 #include <stdio.h> | 16 #include <stdio.h> |
18 #include <string.h> | 17 #include <string.h> |
19 | 18 |
| 19 #include "build/build_config.h" |
| 20 |
| 21 namespace base { |
| 22 |
20 #define USE_HISTORICAL_STRERRO_R (defined(__GLIBC__) || defined(OS_NACL)) | 23 #define USE_HISTORICAL_STRERRO_R (defined(__GLIBC__) || defined(OS_NACL)) |
21 | 24 |
22 #if USE_HISTORICAL_STRERRO_R && defined(__GNUC__) | 25 #if USE_HISTORICAL_STRERRO_R && defined(__GNUC__) |
23 // GCC will complain about the unused second wrap function unless we tell it | 26 // GCC will complain about the unused second wrap function unless we tell it |
24 // that we meant for them to be potentially unused, which is exactly what this | 27 // that we meant for them to be potentially unused, which is exactly what this |
25 // attribute is for. | 28 // attribute is for. |
26 #define POSSIBLY_UNUSED __attribute__((unused)) | 29 #define POSSIBLY_UNUSED __attribute__((unused)) |
27 #else | 30 #else |
28 #define POSSIBLY_UNUSED | 31 #define POSSIBLY_UNUSED |
29 #endif | 32 #endif |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // static. | 113 // static. |
111 wrap_posix_strerror_r(&strerror_r, err, buf, len); | 114 wrap_posix_strerror_r(&strerror_r, err, buf, len); |
112 } | 115 } |
113 | 116 |
114 std::string safe_strerror(int err) { | 117 std::string safe_strerror(int err) { |
115 const int buffer_size = 256; | 118 const int buffer_size = 256; |
116 char buf[buffer_size]; | 119 char buf[buffer_size]; |
117 safe_strerror_r(err, buf, sizeof(buf)); | 120 safe_strerror_r(err, buf, sizeof(buf)); |
118 return std::string(buf); | 121 return std::string(buf); |
119 } | 122 } |
| 123 |
| 124 } // namespace base |
OLD | NEW |