Home | History | Annotate | Download | only in tests
      1 /* Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
      2    This file is part of elfutils.
      3 
      4    This file is free software; you can redistribute it and/or modify
      5    it under the terms of the GNU General Public License as published by
      6    the Free Software Foundation; either version 3 of the License, or
      7    (at your option) any later version.
      8 
      9    elfutils is distributed in the hope that it will be useful, but
     10    WITHOUT ANY WARRANTY; without even the implied warranty of
     11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12    GNU General Public License for more details.
     13 
     14    You should have received a copy of the GNU General Public License
     15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     16 
     17 #ifdef HAVE_CONFIG_H
     18 # include <config.h>
     19 #endif
     20 
     21 #include <assert.h>
     22 #include <fcntl.h>
     23 #include <libelf.h>
     24 #include <stdio.h>
     25 #include <stdlib.h>
     26 #include <unistd.h>
     27 
     28 
     29 int
     30 main (void)
     31 {
     32   Elf *elf;
     33   int fd;
     34   Elf_Scn *section;
     35 
     36   if (elf_version (EV_CURRENT) == EV_NONE)
     37     {
     38       fprintf (stderr, "library fd of date\n");
     39       exit (1);
     40     }
     41 
     42   char name[] = "test.XXXXXX";
     43   fd = mkstemp (name);
     44   if (fd < 0)
     45     {
     46       fprintf (stderr, "Failed to open fdput file: %s\n", name);
     47       exit (1);
     48     }
     49   unlink (name);
     50 
     51   elf = elf_begin (fd, ELF_C_WRITE, NULL);
     52   if (elf == NULL)
     53     {
     54       fprintf (stderr, "Failed to elf_begin fdput file: %s\n", name);
     55       exit (1);
     56     }
     57 
     58   section = elf_newscn (elf);
     59   section = elf_nextscn (elf, section);
     60   assert (section == NULL);
     61 
     62   elf_end (elf);
     63   close (fd);
     64 
     65   return 0;
     66 }
     67