// Copyright 2006-2009 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/40284755): Remove this and spanify to fix the errors. #pragma allow_unsafe_buffers #endif #include "base/posix/safe_strerror.h" #include <errno.h> #include <stdio.h> #include <string.h> #include "build/build_config.h" namespace base { #if defined(__GLIBC__) || BUILDFLAG(IS_NACL) #define USE_HISTORICAL_STRERROR_R … // Post-L versions of bionic define the GNU-specific strerror_r if _GNU_SOURCE // is defined, but the symbol is renamed to __gnu_strerror_r which only exists // on those later versions. For parity, add the same condition as bionic. #elif defined(__BIONIC__) && defined(_GNU_SOURCE) && __ANDROID_API__ >= 23 #define USE_HISTORICAL_STRERROR_R … #else #define USE_HISTORICAL_STRERROR_R … #endif #if USE_HISTORICAL_STRERROR_R // glibc has two strerror_r functions: a historical GNU-specific one that // returns type char *, and a POSIX.1-2001 compliant one available since 2.3.4 // that returns int. This wraps the GNU-specific one. [[maybe_unused]] static void wrap_posix_strerror_r( char* (*strerror_r_ptr)(int, char*, size_t), int err, char* buf, size_t len) { … } #endif // USE_HISTORICAL_STRERROR_R // Wrapper for strerror_r functions that implement the POSIX interface. POSIX // does not define the behaviour for some of the edge cases, so we wrap it to // guarantee that they are handled. This is compiled on all POSIX platforms, but // it will only be used on Linux if the POSIX strerror_r implementation is // being used (see below). [[maybe_unused]] static void wrap_posix_strerror_r( int (*strerror_r_ptr)(int, char*, size_t), int err, char* buf, size_t len) { … } void safe_strerror_r(int err, char *buf, size_t len) { … } std::string safe_strerror(int err) { … } } // namespace base