Blame tests/early-offscn.c

Packit Service 97d2fb
/* Copyright (C) 2008 Red Hat, Inc.
Packit Service 97d2fb
   This file is part of elfutils.
Packit Service 97d2fb
Packit Service 97d2fb
   This file is free software; you can redistribute it and/or modify
Packit Service 97d2fb
   it under the terms of the GNU General Public License as published by
Packit Service 97d2fb
   the Free Software Foundation; either version 3 of the License, or
Packit Service 97d2fb
   (at your option) any later version.
Packit Service 97d2fb
Packit Service 97d2fb
   elfutils is distributed in the hope that it will be useful, but
Packit Service 97d2fb
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 97d2fb
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 97d2fb
   GNU General Public License for more details.
Packit Service 97d2fb
Packit Service 97d2fb
   You should have received a copy of the GNU General Public License
Packit Service 97d2fb
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef HAVE_CONFIG_H
Packit Service 97d2fb
# include <config.h>
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#include <errno.h>
Packit Service 97d2fb
#include <fcntl.h>
Packit Service 97d2fb
#include <gelf.h>
Packit Service 97d2fb
#include <stdio.h>
Packit Service 97d2fb
#include <stdlib.h>
Packit Service 97d2fb
#include "system.h"
Packit Service 97d2fb
Packit Service 97d2fb
int
Packit Service 97d2fb
main (int argc, char *argv[])
Packit Service 97d2fb
{
Packit Service 97d2fb
  if (argc < 2)
Packit Service 97d2fb
    error (1, 0, "Usage: %s FILE OFFSET", argv[0]);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Set the ELF version.  */
Packit Service 97d2fb
  elf_version (EV_CURRENT);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Open the archive.  */
Packit Service 97d2fb
  int fd = open (argv[1], O_RDONLY);
Packit Service 97d2fb
  if (fd < 0)
Packit Service 97d2fb
    error (1, errno, "cannot open '%s'", argv[1]);
Packit Service 97d2fb
Packit Service 97d2fb
  Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
Packit Service 97d2fb
  if (elf == NULL)
Packit Service 97d2fb
    error (2, 0, "elf_begin: %s", elf_errmsg (-1));
Packit Service 97d2fb
Packit Service 97d2fb
  Elf_Scn *scn = gelf_offscn (elf, strtoull (argv[2], NULL, 0));
Packit Service 97d2fb
  if (scn == NULL)
Packit Service 97d2fb
    error (3, 0, "gelf_offscn: %s", elf_errmsg (-1));
Packit Service 97d2fb
Packit Service 97d2fb
  elf_end (elf);
Packit Service 97d2fb
  return 0;
Packit Service 97d2fb
}