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-05-01 17:49:45 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 <eal_export.h>
      13                 :            : #include <rte_per_lcore.h>
      14                 :            : #include <rte_errno.h>
      15                 :            : 
      16                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      17                 :            : #define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
      18                 :            : #endif
      19                 :            : 
      20                 :            : RTE_EXPORT_SYMBOL(per_lcore__rte_errno)
      21                 :            : RTE_DEFINE_PER_LCORE(int, _rte_errno);
      22                 :            : 
      23                 :            : RTE_EXPORT_SYMBOL(rte_strerror)
      24                 :            : const char *
      25                 :         11 : 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[RETVAL_SZ]);
      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         [ +  + ]:         11 :         if (errnum >= RTE_MAX_ERRNO)
      40                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      41                 :            :                 snprintf(ret, RETVAL_SZ, "Unknown error");
      42                 :            : #else
      43                 :          1 :                 snprintf(ret, RETVAL_SZ, "Unknown error%s %d", sep, errnum);
      44                 :            : #endif
      45                 :            :         else
      46      [ +  +  + ]:         10 :                 switch (errnum){
      47                 :            :                 case E_RTE_SECONDARY:
      48                 :            :                         return "Invalid call in secondary process";
      49                 :          1 :                 case E_RTE_NO_CONFIG:
      50                 :          1 :                         return "Missing rte_config structure";
      51                 :          8 :                 default:
      52         [ -  + ]:          8 :                         if (strerror_r(errnum, ret, RETVAL_SZ) != 0)
      53                 :          0 :                                 snprintf(ret, RETVAL_SZ, "Unknown error%s %d",
      54                 :            :                                                 sep, errnum);
      55                 :            :                 }
      56                 :            : 
      57                 :            :         return ret;
      58                 :            : }

Generated by: LCOV version 1.14