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