Home | History | Annotate | Download | only in android-base
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 // Portable error handling functions. This is only necessary for host-side
     18 // code that needs to be cross-platform; code that is only run on Unix should
     19 // just use errno and strerror() for simplicity.
     20 //
     21 // There is some complexity since Windows has (at least) three different error
     22 // numbers, not all of which share the same type:
     23 //   * errno: for C runtime errors.
     24 //   * GetLastError(): Windows non-socket errors.
     25 //   * WSAGetLastError(): Windows socket errors.
     26 // errno can be passed to strerror() on all platforms, but the other two require
     27 // special handling to get the error string. Refer to Microsoft documentation
     28 // to determine which error code to check for each function.
     29 
     30 #ifndef ANDROID_BASE_ERRORS_H
     31 #define ANDROID_BASE_ERRORS_H
     32 
     33 #include <string>
     34 
     35 namespace android {
     36 namespace base {
     37 
     38 // Returns a string describing the given system error code. |error_code| must
     39 // be errno on Unix or GetLastError()/WSAGetLastError() on Windows. Passing
     40 // errno on Windows has undefined behavior.
     41 std::string SystemErrorCodeToString(int error_code);
     42 
     43 }  // namespace base
     44 }  // namespace android
     45 
     46 #endif  // ANDROID_BASE_ERRORS_H
     47