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 <stdio.h> 9 #include <string.h> 10 11 #include <rte_per_lcore.h> 12 #include <rte_errno.h> 13 14 #ifdef RTE_EXEC_ENV_WINDOWS 15 #define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum) 16 #endif 17 18 RTE_DEFINE_PER_LCORE(int, _rte_errno); 19 20 const char * 21 rte_strerror(int errnum) 22 { 23 /* BSD puts a colon in the "unknown error" messages, Linux doesn't */ 24 #ifdef RTE_EXEC_ENV_FREEBSD 25 static const char *sep = ":"; 26 #else 27 static const char *sep = ""; 28 #endif 29 #define RETVAL_SZ 256 30 static RTE_DEFINE_PER_LCORE(char[RETVAL_SZ], retval); 31 char *ret = RTE_PER_LCORE(retval); 32 33 /* since some implementations of strerror_r throw an error 34 * themselves if errnum is too big, we handle that case here */ 35 if (errnum >= RTE_MAX_ERRNO) 36 #ifdef RTE_EXEC_ENV_WINDOWS 37 snprintf(ret, RETVAL_SZ, "Unknown error"); 38 #else 39 snprintf(ret, RETVAL_SZ, "Unknown error%s %d", sep, errnum); 40 #endif 41 else 42 switch (errnum){ 43 case E_RTE_SECONDARY: 44 return "Invalid call in secondary process"; 45 case E_RTE_NO_CONFIG: 46 return "Missing rte_config structure"; 47 default: 48 if (strerror_r(errnum, ret, RETVAL_SZ) != 0) 49 snprintf(ret, RETVAL_SZ, "Unknown error%s %d", 50 sep, errnum); 51 } 52 53 return ret; 54 } 55