libctf, link: add CTF_LINK_OMIT_VARIABLES_SECTION
[deliverable/binutils-gdb.git] / libctf / ctf-error.c
CommitLineData
479604f4 1/* Error table.
b3adc24a 2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
479604f4
NA
3
4 This file is part of libctf.
5
6 libctf is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not see
18 <http://www.gnu.org/licenses/>. */
19
20#include <ctf-impl.h>
7eea9d3b 21#include <stddef.h>
e148b730 22#include <string.h>
479604f4 23
7eea9d3b
NA
24/* This construct is due to Bruno Haible: much thanks. */
25
26/* Give each structure member a unique name. The name does not matter, so we
27 use the line number in ctf-error.h to uniquify them. */
28
29#define ERRSTRFIELD(line) ERRSTRFIELD1 (line)
30#define ERRSTRFIELD1(line) ctf_errstr##line
31
32/* The error message strings, each in a unique structure member precisely big
33 enough for that error, plus a str member to access them all as a string
34 table. */
35
36static const union _ctf_errlist_t
37{
38 __extension__ struct
39 {
40#define _CTF_STR(n, s) char ERRSTRFIELD (__LINE__) [sizeof (s)];
41#include "ctf-error.h"
42#undef _CTF_STR
43 };
44 char str[1];
45} _ctf_errlist =
46 {
47 {
48#define _CTF_STR(n, s) s,
49#include "ctf-error.h"
50#undef _CTF_STR
51 }
52 };
53
54/* Offsets to each member in the string table, computed using offsetof. */
55
56static const unsigned int _ctf_erridx[] =
57 {
58#define _CTF_STR(n, s) [n - ECTF_BASE] = offsetof (union _ctf_errlist_t, ERRSTRFIELD (__LINE__)),
59#include "ctf-error.h"
60#undef _CTF_STR
61 };
479604f4
NA
62
63const char *
64ctf_errmsg (int error)
65{
66 const char *str;
67
7eea9d3b
NA
68 if (error >= ECTF_BASE && (error - ECTF_BASE) < ECTF_NERR)
69 str = _ctf_errlist.str + _ctf_erridx[error - ECTF_BASE];
479604f4 70 else
e148b730 71 str = (const char *) strerror (error);
479604f4
NA
72
73 return (str ? str : "Unknown error");
74}
75
76int
77ctf_errno (ctf_file_t * fp)
78{
79 return fp->ctf_errno;
80}
This page took 0.080244 seconds and 4 git commands to generate.