1/* Test program for dwelf_elf_e_machine_string 2 Copyright (C) 2019 Red Hat, Inc. 3 This file is part of elfutils. 4 5 This file is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 elfutils is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18#ifdef HAVE_CONFIG_H 19# include <config.h> 20#endif 21 22#include <system.h> 23 24#include <assert.h> 25#include <errno.h> 26#include <inttypes.h> 27#include <stdio.h> 28#include <stdlib.h> 29#include <limits.h> 30#include <string.h> 31#include <unistd.h> 32 33#include ELFUTILS_HEADER(dwelf) 34 35int 36main (int argc, char **argv) 37{ 38 int i; 39 for (i = 1; i < argc; i++) 40 { 41 long val; 42 int em; 43 const char *machine; 44 45 errno = 0; 46 if (startswith (argv[i], "0x")) 47 val = strtol (&argv[i][2], NULL, 16); 48 else 49 val = strtol (argv[i], NULL, 10); 50 51 if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) 52 || (errno != 0 && val == 0)) 53 { 54 perror ("strtol"); 55 exit (EXIT_FAILURE); 56 } 57 58 em = val; 59 assert (em == val); 60 61 machine = dwelf_elf_e_machine_string (em); 62 printf ("0x%x %s\n", em, machine); 63 assert (machine != NULL); 64 } 65 66 return 0; 67} 68