37 #include <sys/errno.h>
42 #define ELFOSABI_SYSV 0
44 #ifndef ELFOSABI_LINUX
45 #define ELFOSABI_LINUX 3
48 #define ELFOSABI_HURD 4
50 #ifndef ELFOSABI_SOLARIS
51 #define ELFOSABI_SOLARIS 6
53 #ifndef ELFOSABI_FREEBSD
54 #define ELFOSABI_FREEBSD 9
58 static int elftype(
const char *);
59 static const char *iselftype(
int);
60 static void printelftypes(
void);
61 static void usage __P((
void));
68 static struct ELFtypes elftypes[] = {
76 main(
int argc,
char **argv)
79 const char *strtype =
"FreeBSD";
82 int ch, change = 0, verbose = 0, force = 0, listed = 0;
84 while ((ch = getopt(argc, argv,
"f:lt:v")) != -1)
88 errx(1,
"f option incompatable with t option");
92 warnx(
"invalid argument to option f: %s",
106 errx(1,
"t option incompatable with f option");
119 warnx(
"no file(s) specified");
124 if (!force && (type = elftype(strtype)) == -1) {
125 warnx(
"invalid ELF type '%s'", strtype);
134 if ((fd = open(argv[0], change || force ? O_RDWR :
O_RDONLY, 0)) < 0) {
135 warn(
"error opening file %s", argv[0]);
139 if (read(fd, buffer, EI_NIDENT) < EI_NIDENT) {
140 warnx(
"file '%s' too short", argv[0]);
144 if (buffer[0] != ELFMAG0 || buffer[1] != ELFMAG1 ||
145 buffer[2] != ELFMAG2 || buffer[3] != ELFMAG3) {
146 warnx(
"file '%s' is not ELF format", argv[0]);
150 if (!change && !force) {
152 "File '%s' is of brand '%s' (%u).\n",
153 argv[0], iselftype(buffer[EI_OSABI]),
155 if (!iselftype(type)) {
156 warnx(
"ELF ABI Brand '%u' is unknown",
162 buffer[EI_OSABI] =
type;
164 if (write(fd, buffer, EI_NIDENT) != EI_NIDENT) {
165 warn(
"error writing %s %d", argv[0], fd);
182 fprintf(stderr,
"usage: brandelf [-f ELF ABI number] [-v] [-l] [-t string] file ...\n");
187 iselftype(
int elftype)
192 elfwalk <
sizeof(elftypes)/
sizeof(elftypes[0]);
194 if (elftype == elftypes[elfwalk].
value)
195 return elftypes[elfwalk].
str;
200 elftype(
const char *elfstrtype)
205 elfwalk <
sizeof(elftypes)/
sizeof(elftypes[0]);
207 if (
strcmp(elfstrtype, elftypes[elfwalk].
str) == 0)
208 return elftypes[elfwalk].
value;
217 fprintf(stderr,
"known ELF types are: ");
219 elfwalk <
sizeof(elftypes)/
sizeof(elftypes[0]);
221 fprintf(stderr,
"%s(%u) ", elftypes[elfwalk].
str,
222 elftypes[elfwalk].
value);
223 fprintf(stderr,
"\n");
GLsizei const GLfloat * value
GLsizeiptr const GLvoid GLenum usage
GLuint GLuint GLsizei GLenum type
int main(int argc, char **argv)