• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
31 
32 #include <string>
33 
34 namespace android {
35 namespace base {
36 
37 // Returns a string describing the given system error code. |error_code| must
38 // be errno on Unix or GetLastError()/WSAGetLastError() on Windows. Passing
39 // errno on Windows has undefined behavior.
40 std::string SystemErrorCodeToString(int error_code);
41 
42 }  // namespace base
43 }  // namespace android
44