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