LCOV - code coverage report
Current view: top level - libasm - asm_error.c (source / functions) Hit Total Coverage
Test: elfutils-0.192 Lines: 0 17 0.0 %
Date: 2024-11-08 23:03:42 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 8 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* Error handling in libasm.
       2                 :            :    Copyright (C) 2002, 2004, 2005, 2009 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
       5                 :            : 
       6                 :            :    This file is free software; you can redistribute it and/or modify
       7                 :            :    it under the terms of either
       8                 :            : 
       9                 :            :      * the GNU Lesser General Public License as published by the Free
      10                 :            :        Software Foundation; either version 3 of the License, or (at
      11                 :            :        your option) any later version
      12                 :            : 
      13                 :            :    or
      14                 :            : 
      15                 :            :      * the GNU General Public License as published by the Free
      16                 :            :        Software Foundation; either version 2 of the License, or (at
      17                 :            :        your option) any later version
      18                 :            : 
      19                 :            :    or both in parallel, as here.
      20                 :            : 
      21                 :            :    elfutils is distributed in the hope that it will be useful, but
      22                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :    General Public License for more details.
      25                 :            : 
      26                 :            :    You should have received copies of the GNU General Public License and
      27                 :            :    the GNU Lesser General Public License along with this program.  If
      28                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      29                 :            : 
      30                 :            : #ifdef HAVE_CONFIG_H
      31                 :            : # include <config.h>
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include <stdbool.h>
      35                 :            : #include <stdlib.h>
      36                 :            : 
      37                 :            : #include "libasmP.h"
      38                 :            : 
      39                 :            : 
      40                 :            : /* This is the key for the thread specific memory.  */
      41                 :            : static __thread int global_error;
      42                 :            : 
      43                 :            : 
      44                 :            : int
      45                 :          0 : asm_errno (void)
      46                 :            : {
      47                 :          0 :   int result = global_error;
      48                 :          0 :   global_error = ASM_E_NOERROR;
      49                 :          0 :   return result;
      50                 :            : }
      51                 :            : 
      52                 :            : 
      53                 :            : void
      54                 :            : internal_function
      55                 :          0 : __libasm_seterrno (int value)
      56                 :            : {
      57                 :          0 :   global_error = value;
      58                 :          0 : }
      59                 :            : 
      60                 :            : 
      61                 :            : /* Return the appropriate message for the error.  */
      62                 :            : static const char *msgs[ASM_E_NUM] =
      63                 :            : {
      64                 :            :   [ASM_E_NOERROR] = N_("no error"),
      65                 :            :   [ASM_E_NOMEM] = N_("out of memory"),
      66                 :            :   [ASM_E_CANNOT_CREATE] = N_("cannot create output file"),
      67                 :            :   [ASM_E_INVALID] = N_("invalid parameter"),
      68                 :            :   [ASM_E_CANNOT_CHMOD] = N_("cannot change mode of output file"),
      69                 :            :   [ASM_E_CANNOT_RENAME] = N_("cannot rename output file"),
      70                 :            :   [ASM_E_DUPLSYM] = N_("duplicate symbol"),
      71                 :            :   [ASM_E_TYPE] = N_("invalid section type for operation"),
      72                 :            :   [ASM_E_IOERROR] = N_("error during output of data"),
      73                 :            :   [ASM_E_ENOSUP] = N_("no backend support available"),
      74                 :            : };
      75                 :            : 
      76                 :            : const char *
      77                 :          0 : asm_errmsg (int error)
      78                 :            : {
      79                 :          0 :   int last_error = global_error;
      80                 :            : 
      81         [ #  # ]:          0 :   if (error < -1)
      82                 :          0 :     return _("unknown error");
      83         [ #  # ]:          0 :   if (error == 0 && last_error == 0)
      84                 :            :     /* No error.  */
      85                 :            :     return NULL;
      86                 :            : 
      87         [ #  # ]:          0 :   if (error != -1)
      88                 :          0 :     last_error = error;
      89                 :            : 
      90         [ #  # ]:          0 :   if (last_error == ASM_E_LIBELF)
      91                 :          0 :     return elf_errmsg (-1);
      92                 :            : 
      93                 :          0 :   return _(msgs[last_error]);
      94                 :            : }

Generated by: LCOV version 1.16