diff options
author | cvs2svn <cvs2svn@FreeBSD.org> | 1999-01-21 00:55:32 +0000 |
---|---|---|
committer | cvs2svn <cvs2svn@FreeBSD.org> | 1999-01-21 00:55:32 +0000 |
commit | 76b5366091f76c9bc73570149ef5055648fc2c39 (patch) | |
tree | 590d020e0f2a5bea6e09d66d951a674443b21d67 /usr.bin/objformat | |
parent | 4b4d01da6f07f7754ff6a6e4f5223e9f0984d1a6 (diff) |
Notes
Diffstat (limited to 'usr.bin/objformat')
-rw-r--r-- | usr.bin/objformat/Makefile | 10 | ||||
-rw-r--r-- | usr.bin/objformat/objformat.1 | 94 | ||||
-rw-r--r-- | usr.bin/objformat/objformat.c | 124 |
3 files changed, 116 insertions, 112 deletions
diff --git a/usr.bin/objformat/Makefile b/usr.bin/objformat/Makefile index a56fdd4f8b8c..1f28d3b5201c 100644 --- a/usr.bin/objformat/Makefile +++ b/usr.bin/objformat/Makefile @@ -1,8 +1,14 @@ # $FreeBSD$ PROG= objformat -CFLAGS+= -Wall -NOSHARED?= YES +NOMAN= not yet +CFLAGS+= -DMAIN + +.if ${OBJFORMAT} == elf +CFLAGS+= -DFREEBSD_ELF +.else +CFLAGS+= -DFREEBSD_AOUT +.endif LINKS+= ${BINDIR}/objformat ${BINDIR}/addr2line LINKS+= ${BINDIR}/objformat ${BINDIR}/ar diff --git a/usr.bin/objformat/objformat.1 b/usr.bin/objformat/objformat.1 deleted file mode 100644 index fe924450f026..000000000000 --- a/usr.bin/objformat/objformat.1 +++ /dev/null @@ -1,94 +0,0 @@ -.\" -.\" Copyright (c) 1998 David E. O'Brien -.\" -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $Id: kzip.8,v 1.5 1998/03/23 07:44:18 charnier Exp $ -.\" -.Dd October 25, 1998 -.Os -.Dt OBJFORMAT 1 -.Sh NAME -.Nm objformat -.Nd reports default binary format and program deflector -.Sh SYNOPSIS -.Nm objformat -.Nm prog -.Sh DESCRIPTION -If run as -.Nm -the default object file format is reported. The two different object file -formats are -.Ar a.out -and -.Ar ELF . -.Pp -If invoked by any other name, -.Nm prog -is expanded to -.Pa /usr/libexec/<objformat>/prog -and executed. -.Sh DIAGNOSTICS -The -.Nm -utility returns with exit code 1 -if called with an improper number of arguments, or if -.Nm prog -could not be executed. -.Sh ENVIRONMENT -.Bl -tag -width OBJFORMAT_PATH -.It Ev OBJFORMAT -If the environment variable -.Ev OBJFORMAT -is set, it overrides the default object file format. -.Ev OBJFORMAT takes precedence over -.Pa /etc/objformat . -.It Ev OBJFORMAT_PATH -If the environment variable -.Ev OBJFORMAT_PATH -is set, its value is used as the base path to -.Nm prog . -The default is -.Pa /usr/libexec . -.El -.Sh FILES -.Bl -tag -width /etc/objformat -compact -.It Pa /etc/objformat -If present, specifies the object file format to use. Syntax is -.Ql OBJFORMAT=xxx . -.Sh SEE ALSO -.Xr file 1 , -.Xr getobjformat 3 -.\" .Sh STANDARDS -.Sh HISTORY -The -.Nm -command appeared in -.Fx 3.0 . -.Sh AUTHORS -.Nm -was written by -.An Peter Wemm Aq peter@netplex.com.au . -This manual page was written by -.An David O'Brien Aq obrien@NUXI.com . -.\" .Sh BUGS diff --git a/usr.bin/objformat/objformat.c b/usr.bin/objformat/objformat.c index 8d75f5ea64ae..827af6eda1e9 100644 --- a/usr.bin/objformat/objformat.c +++ b/usr.bin/objformat/objformat.c @@ -26,36 +26,112 @@ * $FreeBSD$ */ -#include <err.h> -#include <objformat.h> +#include <sys/types.h> + #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> +#include <string.h> + +#ifdef FREEBSD_ELF +int objformat_aout = 0; +#else +int objformat_aout = 1; +#endif +void +getobjfmt(void) +{ + char *env; + int i; + + /* first hint is /etc/objformat */ + FILE *fp = fopen("/etc/objformat", "r"); + if (fp) { + char buf[1024]; + buf[1023] = '\0'; + while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { + i = strlen(buf); + if (buf[i - 1] == '\n') + buf[i - 1] = '\0'; + if (strcmp(buf, "OBJFORMAT=aout") == 0) + objformat_aout = 1; + else if (strcmp(buf, "OBJFORMAT=elf") == 0) + objformat_aout = 0; + else + fprintf(stderr, "Unrecognized line in /etc/objformat: %s\n", buf); + } + fclose(fp); + } + /* but the user $OBJFORMAT overrides system default */ + env = getenv("OBJFORMAT"); + if (env) { + if (strcmp(env, "aout") == 0) + objformat_aout = 1; + else if (strcmp(env, "elf") == 0) + objformat_aout = 0; + else + fprintf(stderr, "Unrecognized value of $OBJFORMAT: %s\n", env); + } +} + +void +scanargv(int *argc, char **argv, int strip) +{ + int i, j; + + for (i = 1; i < *argc; i++) { + if (strcmp (argv[i], "-aout") == 0) { + objformat_aout = 1; + continue; + } else if (strcmp (argv[i], "-elf") == 0) { + objformat_aout = 0; + continue; + } + } + + /* if just looking, return now */ + if (!strip) + return; + + /* otherwise, remove all traces of switches from argv */ + for (i = 1; i < *argc; i++) { + if (strcmp (argv[i], "-aout") == 0 || + strcmp (argv[i], "-elf") == 0) { + /* copy NULL at end of argv as well */ + for (j = i + 1; j <= *argc; j++) { + argv[j - 1] = argv[j]; + } + (*argc)--; + } + } +} + + +#ifdef MAIN int main(int argc, char **argv) { - char objformat[32]; char *path, *chunk; + char *postfix; char *cmd, *newcmd = NULL; char *objformat_path; - - if (getobjformat(objformat, sizeof objformat, &argc, argv) == -1) - errx(1, "Invalid object format"); + int i; cmd = strrchr(argv[0], '/'); - if (cmd != NULL) + if (cmd) cmd++; else cmd = argv[0]; + getobjfmt(); + scanargv(&argc, argv, 1); + if (strcmp(cmd, "objformat") == 0) { - if (argc != 1) { - fprintf(stderr, "Usage: objformat\n"); - exit(1); - } - printf("%s\n", objformat); + if (objformat_aout) + printf("aout\n"); + else + printf("elf\n"); exit(0); } @@ -65,19 +141,35 @@ main(int argc, char **argv) objformat_path = "/usr/libexec"; path = strdup(objformat_path); - setenv("OBJFORMAT", objformat, 1); + if (objformat_aout) { + putenv("OBJFORMAT=aout"); + postfix = "aout"; + } else { + putenv("OBJFORMAT=elf"); + postfix = "elf"; + } while ((chunk = strsep(&path, ":")) != NULL) { if (newcmd != NULL) { free(newcmd); newcmd = NULL; } - asprintf(&newcmd, "%s/%s/%s", chunk, objformat, cmd); + asprintf(&newcmd, "%s/%s/%s", chunk, postfix, cmd); if (newcmd == NULL) err(1, "cannot allocate memory for new command"); + if (getenv("OBJFORMAT_DEBUG") != NULL) { + fprintf(stderr, "objformat: %s -> %s\n", cmd, newcmd); +#if 0 + for (i = 1; i < argc; i++) + fprintf(stderr, "argv[%d]: %s\n", i, argv[i]); +#endif + } + argv[0] = newcmd; execv(newcmd, argv); } - err(1, "could not exec %s/%s in %s", objformat, cmd, objformat_path); + err(1, "could not exec %s/%s in %s", postfix, cmd, objformat_path); } + +#endif |