summaryrefslogtreecommitdiff
path: root/usr.sbin/crunchgen/crunchide.c
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2015-01-18 05:30:59 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2015-01-18 05:30:59 +0000
commit853dea894400a993c12db5bc792aaf4020440897 (patch)
treee0b48f26f45b4fd339f56a565278e2d1c04a7a2e /usr.sbin/crunchgen/crunchide.c
parent2fe134007d1bf961edea5e74e5a3075a795a6a55 (diff)
The world is ELF: use <sys/exec_elf.h> instead of <a.out.h> or <sys/exec.h>
Use a better test for an input being ELF: struct exec is dead and there are defines for the ELF magic. Reorder #includes and do some whitespace cleanup. Oh, and don't lead the fd if an input file isn't ELF. ok deraadt@
Diffstat (limited to 'usr.sbin/crunchgen/crunchide.c')
-rw-r--r--usr.sbin/crunchgen/crunchide.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/usr.sbin/crunchgen/crunchide.c b/usr.sbin/crunchgen/crunchide.c
index 7c01e422cfd..1720dd08fde 100644
--- a/usr.sbin/crunchgen/crunchide.c
+++ b/usr.sbin/crunchgen/crunchide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crunchide.c,v 1.8 2014/03/16 20:45:47 guenther Exp $ */
+/* $OpenBSD: crunchide.c,v 1.9 2015/01/18 05:30:58 guenther Exp $ */
/*
* Copyright (c) 1994 University of Maryland
@@ -51,27 +51,27 @@
* that the final crunched binary BSS size is the max of all the
* component programs' BSS sizes, rather than their sum.
*/
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <a.out.h>
+
#include <sys/types.h>
+#include <sys/exec_elf.h>
#include <sys/mman.h>
#include <sys/stat.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
#include "mangle.h"
-void usage(void);
+void usage(void);
-void add_to_keep_list(char *);
-void add_file_to_keep_list(char *);
+void add_to_keep_list(char *);
+void add_file_to_keep_list(char *);
-void hide_syms(char *);
-#ifdef _NLIST_DO_ELF
-void elf_hide(int, char *);
-#endif
+void hide_syms(char *);
+void elf_hide(int, char *);
int in_keep_list(char *symbol);
int crunchide_main(int argc, char *argv[]);
@@ -206,7 +206,7 @@ hide_syms(char *filename)
close(inf);
return;
}
- if (infstat.st_size < sizeof(struct exec)) {
+ if (infstat.st_size < sizeof(Elf_Ehdr)) {
fprintf(stderr, "%s: short file\n", filename);
close(inf);
return;
@@ -218,11 +218,11 @@ hide_syms(char *filename)
return;
}
-#ifdef _NLIST_DO_ELF
- if (buf[0] == 0x7f && (buf[1] == 'E' || buf[1] == 'O') &&
- buf[2] == 'L' && buf[3] == 'F') {
+ if (buf[0] == ELFMAG0 && buf[1] == ELFMAG1 &&
+ buf[2] == ELFMAG2 && buf[3] == ELFMAG3) {
elf_hide(inf, buf);
return;
}
-#endif /* _NLIST_DO_ELF */
+
+ close(inf);
}