1 /* This file is part of centaur.
3 * centaur is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License 2 as
5 * published by the Free Software Foundation.
7 * centaur is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with centaur. If not, see <http://www.gnu.org/licenses/>.
17 #include <sys/types.h>
25 #include "elfhandle.h"
28 void openElf(ELFHandles *h, char *fn, Elf_Cmd elfmode)
40 openflags = O_WRONLY | O_CREAT;
41 openmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
51 h->fd = open(fn, openflags, openmode);
53 fprintf(stderr, "Cannot open %s: %s\n", fn, strerror(errno));
57 h->e = elf_begin(h->fd, elfmode, NULL);
59 fprintf(stderr, "elf_begin() failed on %s: %s\n", fn, elf_errmsg(-1));
63 if (elfmode == ELF_C_READ || elfmode == ELF_C_RDWR) {
64 if (elf_kind(h->e) != ELF_K_ELF) {
65 fprintf(stderr, "Not an ELF object: %s", fn);
81 void closeElf(ELFHandles *h)