2005-11-16 Roland McGrath <roland@redhat.com>
[platform/upstream/elfutils.git] / tests / newscn.c
1 /* Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
2
3    This program is Open Source software; you can redistribute it and/or
4    modify it under the terms of the Open Software License version 1.0 as
5    published by the Open Source Initiative.
6
7    You should have received a copy of the Open Software License along
8    with this program; if not, you may obtain a copy of the Open Software
9    License version 1.0 from http://www.opensource.org/licenses/osl.php or
10    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
11    3001 King Ranch Road, Ukiah, CA 95482.   */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 #include <assert.h>
18 #include <fcntl.h>
19 #include <libelf.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23
24
25 int
26 main (void)
27 {
28   Elf *elf;
29   int fd;
30   Elf_Scn *section;
31
32   if (elf_version (EV_CURRENT) == EV_NONE)
33     {
34       fprintf (stderr, "library fd of date\n");
35       exit (1);
36     }
37
38   char name[] = "test.XXXXXX";
39   fd = mkstemp (name);
40   if (fd < 0)
41     {
42       fprintf (stderr, "Failed to open fdput file: %s\n", name);
43       exit (1);
44     }
45   unlink (name);
46
47   elf = elf_begin (fd, ELF_C_WRITE, NULL);
48   if (elf == NULL)
49     {
50       fprintf (stderr, "Failed to elf_begin fdput file: %s\n", name);
51       exit (1);
52     }
53
54   section = elf_newscn (elf);
55   section = elf_nextscn (elf, section);
56   assert (section == NULL);
57
58   elf_end (elf);
59   close (fd);
60
61   return 0;
62 }