• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2002 Red Hat, Inc.
2    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
3 
4    This program is Open Source software; you can redistribute it and/or
5    modify it under the terms of the Open Software License version 1.0 as
6    published by the Open Source Initiative.
7 
8    You should have received a copy of the Open Software License along
9    with this program; if not, you may obtain a copy of the Open Software
10    License version 1.0 from http://www.opensource.org/licenses/osl.php or
11    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12    3001 King Ranch Road, Ukiah, CA 95482.   */
13 
14 #include <config.h>
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include <libelfP.h>
21 
22 static struct
23 {
24   int id;
25   const char *expected;
26 } libelf_msgs[ELF_E_NUM] =
27   {
28     { ELF_E_NOERROR, "no error" },
29     { ELF_E_UNKNOWN_ERROR, "unknown error" },
30     { ELF_E_UNKNOWN_VERSION, "unknown version" },
31     { ELF_E_UNKNOWN_TYPE, "unknown type" },
32     { ELF_E_INVALID_HANDLE, "invalid `Elf' handle" },
33     { ELF_E_SOURCE_SIZE, "invalid size of source operand" },
34     { ELF_E_DEST_SIZE, "invalid size of destination operand" },
35     { ELF_E_INVALID_ENCODING, "invalid encoding" },
36     { ELF_E_NOMEM, "out of memory" },
37     { ELF_E_INVALID_FILE, "invalid file descriptor" },
38     { ELF_E_INVALID_OP, "invalid operation" },
39     { ELF_E_NO_VERSION, "ELF version not set" },
40     { ELF_E_INVALID_CMD, "invalid command" },
41     { ELF_E_RANGE, "offset out of range" },
42     { ELF_E_ARCHIVE_FMAG, "invalid fmag field in archive header" },
43     { ELF_E_INVALID_ARCHIVE, "invalid archive file" },
44     { ELF_E_NO_ARCHIVE, "descriptor is not for an archive" },
45     { ELF_E_NO_INDEX, "no index available" },
46     { ELF_E_READ_ERROR, "cannot read data from file" },
47     { ELF_E_WRITE_ERROR, "cannot write data to file" },
48     { ELF_E_INVALID_CLASS, "invalid binary class" },
49     { ELF_E_INVALID_INDEX, "invalid section index" },
50     { ELF_E_INVALID_OPERAND, "invalid operand" },
51     { ELF_E_INVALID_SECTION, "invalid section" },
52     { ELF_E_INVALID_COMMAND, "invalid command" },
53     { ELF_E_WRONG_ORDER_EHDR, "executable header not created first" },
54     { ELF_E_FD_DISABLED, "file descriptor disabled" },
55     { ELF_E_FD_MISMATCH, "archive/member fildes mismatch" },
56     { ELF_E_OFFSET_RANGE, "offset out of range" },
57     { ELF_E_NOT_NUL_SECTION, "cannot manipulate null section" },
58     { ELF_E_DATA_MISMATCH, "data/scn mismatch" },
59     { ELF_E_INVALID_SECTION_HEADER, "invalid section header" },
60     { ELF_E_INVALID_DATA, "invalid data" },
61     { ELF_E_DATA_ENCODING, "unknown data encoding" },
62     { ELF_E_SECTION_TOO_SMALL, "section `sh_size' too small for data" },
63     { ELF_E_INVALID_ALIGN, "invalid section alignment" },
64     { ELF_E_INVALID_SHENTSIZE, "invalid section entry size" },
65     { ELF_E_UPDATE_RO, "update() for write on read-only file" },
66     { ELF_E_NOFILE, "no such file" },
67     { ELF_E_GROUP_NOT_REL,
68       "only relocatable files can contain section groups" },
69     { ELF_E_INVALID_PHDR,
70       "program header only allowed in executables and shared objects" },
71     { ELF_E_NO_PHDR,
72       "file has no program header" }
73   };
74 
75 
76 int
main(void)77 main (void)
78 {
79   size_t cnt;
80   int result = EXIT_SUCCESS;
81 
82   /* Clear the error state.  */
83   (void) elf_errno ();
84 
85   /* Check all the messages of libelf.  */
86   for (cnt = 1; cnt < ELF_E_NUM; ++cnt)
87     {
88       const char *str = elf_errmsg (libelf_msgs[cnt].id);
89 
90       if (strcmp (str, libelf_msgs[cnt].expected) != 0)
91 	{
92 	  printf ("libelf msg %zu: expected \"%s\", got \"%s\"\n",
93 		  cnt, libelf_msgs[cnt].expected, str);
94 	  result = EXIT_FAILURE;
95 	}
96     }
97 
98   return result;
99 }
100