LCOV - code coverage report
Current view: top level - lib/eal/common - eal_common_errno.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 8 9 88.9 %
Date: 2025-01-02 22:41:34 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 7 85.7 %

           Branch data     Line data    Source code
       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                 :         11 : 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         [ +  + ]:         11 :         if (errnum >= RTE_MAX_ERRNO)
      37                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      38                 :            :                 snprintf(ret, RETVAL_SZ, "Unknown error");
      39                 :            : #else
      40                 :          1 :                 snprintf(ret, RETVAL_SZ, "Unknown error%s %d", sep, errnum);
      41                 :            : #endif
      42                 :            :         else
      43      [ +  +  + ]:         10 :                 switch (errnum){
      44                 :            :                 case E_RTE_SECONDARY:
      45                 :            :                         return "Invalid call in secondary process";
      46                 :          1 :                 case E_RTE_NO_CONFIG:
      47                 :          1 :                         return "Missing rte_config structure";
      48                 :          8 :                 default:
      49         [ -  + ]:          8 :                         if (strerror_r(errnum, ret, RETVAL_SZ) != 0)
      50                 :          0 :                                 snprintf(ret, RETVAL_SZ, "Unknown error%s %d",
      51                 :            :                                                 sep, errnum);
      52                 :            :                 }
      53                 :            : 
      54                 :            :         return ret;
      55                 :            : }

Generated by: LCOV version 1.14