New upstream version 18.02
[deb_dpdk.git] / lib / librte_eal / common / eal_common_errno.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdarg.h>
9 #include <errno.h>
10
11 #include <rte_per_lcore.h>
12 #include <rte_errno.h>
13 #include <rte_string_fns.h>
14
15 RTE_DEFINE_PER_LCORE(int, _rte_errno);
16
17 const char *
18 rte_strerror(int errnum)
19 {
20         /* BSD puts a colon in the "unknown error" messages, Linux doesn't */
21 #ifdef RTE_EXEC_ENV_BSDAPP
22         static const char *sep = ":";
23 #else
24         static const char *sep = "";
25 #endif
26 #define RETVAL_SZ 256
27         static RTE_DEFINE_PER_LCORE(char[RETVAL_SZ], retval);
28         char *ret = RTE_PER_LCORE(retval);
29
30         /* since some implementations of strerror_r throw an error
31          * themselves if errnum is too big, we handle that case here */
32         if (errnum >= RTE_MAX_ERRNO)
33                 snprintf(ret, RETVAL_SZ, "Unknown error%s %d", sep, errnum);
34         else
35                 switch (errnum){
36                 case E_RTE_SECONDARY:
37                         return "Invalid call in secondary process";
38                 case E_RTE_NO_CONFIG:
39                         return "Missing rte_config structure";
40                 default:
41                         if (strerror_r(errnum, ret, RETVAL_SZ) != 0)
42                                 snprintf(ret, RETVAL_SZ, "Unknown error%s %d",
43                                                 sep, errnum);
44                 }
45
46         return ret;
47 }