Finish the deorbital burn of the i386-only a.out toolchain.
This commit is contained in:
parent
850a2bd817
commit
f6d8a17fe8
@ -1,12 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= ar
|
||||
SRCS= append.c ar.c archive.c contents.c delete.c extract.c misc.c \
|
||||
move.c print.c replace.c
|
||||
CFLAGS+=-I${.CURDIR}
|
||||
MAN= ar.1aout ar.5
|
||||
BINDIR= /usr/libexec/aout
|
||||
WARNS?= 4
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,94 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)append.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* append --
|
||||
* Append files to the archive - modifies original archive or creates
|
||||
* a new archive if named archive does not exist.
|
||||
*/
|
||||
int
|
||||
append(argv)
|
||||
char **argv;
|
||||
{
|
||||
int afd, fd, eval;
|
||||
char *file;
|
||||
CF cf;
|
||||
struct stat sb;
|
||||
|
||||
afd = open_archive(O_CREAT|O_RDWR);
|
||||
if (lseek(afd, (off_t)0, SEEK_END) == (off_t)-1)
|
||||
error(archive);
|
||||
|
||||
/* Read from disk, write to an archive; pad on write. */
|
||||
SETCF(0, 0, afd, archive, WPAD);
|
||||
for (eval = 0; (file = *argv++); ) {
|
||||
if ((fd = open(file, O_RDONLY)) < 0) {
|
||||
warn("%s", file);
|
||||
eval = 1;
|
||||
continue;
|
||||
}
|
||||
if (options & AR_V)
|
||||
(void)printf("q - %s\n", file);
|
||||
cf.rfd = fd;
|
||||
cf.rname = file;
|
||||
put_arobj(&cf, &sb);
|
||||
(void)close(fd);
|
||||
}
|
||||
close_archive(afd);
|
||||
return (eval);
|
||||
}
|
318
usr.bin/ar/ar.1
318
usr.bin/ar/ar.1
@ -1,318 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Hugh Smith at The University of Guelph.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)ar.1 8.1 (Berkeley) 6/29/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 29, 1993
|
||||
.Dt AR 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ar
|
||||
.Nd create and maintain library archives
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Fl d
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl m
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl m
|
||||
.Op Fl abiTv
|
||||
.Ar position archive Ar
|
||||
.Nm
|
||||
.Fl p
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Op Ar
|
||||
.Nm
|
||||
.Fl q
|
||||
.Op Fl cTv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl r
|
||||
.Op Fl cuTv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl r
|
||||
.Op Fl abciuTv
|
||||
.Ar position archive Ar
|
||||
.Nm
|
||||
.Fl t
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Op Ar
|
||||
.Nm
|
||||
.Fl x
|
||||
.Op Fl ouTv
|
||||
.Ar archive Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility creates and maintains groups of files combined into an archive.
|
||||
Once an archive has been created, new files can be added and existing
|
||||
files can be extracted, deleted, or replaced.
|
||||
.Pp
|
||||
Files are named in the archive by a single component, i.e., if a file
|
||||
referenced by a path containing a slash (``/'') is archived it will be
|
||||
named by the last component of that path.
|
||||
When matching paths listed on the command line against file names stored
|
||||
in the archive, only the last component of the path will be compared.
|
||||
.Pp
|
||||
All informational and error messages use the path listed on the command
|
||||
line, if any was specified; otherwise the name in the archive is used.
|
||||
If multiple files in the archive have the same name, and paths are listed
|
||||
on the command line to ``select'' archive files for an operation, only the
|
||||
.Em first
|
||||
file with a matching name will be selected.
|
||||
.Pp
|
||||
The normal use of
|
||||
.Nm
|
||||
is for the creation and maintenance of libraries suitable for use with
|
||||
the loader (see
|
||||
.Xr ld 1 )
|
||||
although it is not restricted to this purpose.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
A positioning modifier used with the options
|
||||
.Fl r
|
||||
and
|
||||
.Fl m .
|
||||
The files are entered or moved
|
||||
.Em after
|
||||
the archive member
|
||||
.Ar position ,
|
||||
which must be specified.
|
||||
.It Fl b
|
||||
A positioning modifier used with the options
|
||||
.Fl r
|
||||
and
|
||||
.Fl m .
|
||||
The files are entered or moved
|
||||
.Em before
|
||||
the archive member
|
||||
.Ar position ,
|
||||
which must be specified.
|
||||
.It Fl c
|
||||
Whenever an archive is created, an informational message to that effect
|
||||
is written to standard error.
|
||||
If the
|
||||
.Fl c
|
||||
option is specified,
|
||||
.Nm
|
||||
creates the archive silently.
|
||||
.It Fl d
|
||||
Delete the specified archive files.
|
||||
.It Fl i
|
||||
Identical to the
|
||||
.Fl b
|
||||
option.
|
||||
.It Fl m
|
||||
Move the specified archive files within the archive.
|
||||
If one of the options
|
||||
.Fl a ,
|
||||
.Fl b
|
||||
or
|
||||
.Fl i
|
||||
is specified, the files are moved
|
||||
before or after the
|
||||
.Ar position
|
||||
file in the archive.
|
||||
If none of those options are specified, the files are moved
|
||||
to the end of the archive.
|
||||
.It Fl o
|
||||
Set the access and modification times of extracted files to the
|
||||
modification time of the file when it was entered into the archive.
|
||||
This will fail if the user is not the owner of the extracted file
|
||||
or the super-user.
|
||||
.It Fl p
|
||||
Write the contents of the specified archive files to the standard output.
|
||||
If no files are specified, the contents of all the files in the archive
|
||||
are written in the order they appear in the archive.
|
||||
.It Fl q
|
||||
(Quickly) append the specified files to the archive.
|
||||
If the archive does not exist a new archive file is created.
|
||||
Much faster than the
|
||||
.Fl r
|
||||
option, when creating a large archive
|
||||
piece-by-piece, as no checking is done to see if the files already
|
||||
exist in the archive.
|
||||
.It Fl r
|
||||
Replace or add the specified files to the archive.
|
||||
If the archive does not exist a new archive file is created.
|
||||
Files that replace existing files do not change the order of the files
|
||||
within the archive.
|
||||
New files are appended to the archive unless one of the options
|
||||
.Fl a ,
|
||||
.Fl b
|
||||
or
|
||||
.Fl i
|
||||
is specified.
|
||||
.It Fl T
|
||||
Select and/or name archive members using only the first fifteen characters
|
||||
of the archive member or command line file name.
|
||||
The historic archive format had sixteen bytes for the name, but some
|
||||
historic archiver and loader implementations were unable to handle names
|
||||
that used the entire space.
|
||||
This means that file names that are not unique in their first fifteen
|
||||
characters can subsequently be confused.
|
||||
A warning message is printed to the standard error output if any file
|
||||
names are truncated.
|
||||
(See
|
||||
.Xr ar 5
|
||||
for more information.)
|
||||
.It Fl t
|
||||
List the specified files in the order in which they appear in the archive,
|
||||
each on a separate line.
|
||||
If no files are specified, all files in the archive are listed.
|
||||
.It Fl u
|
||||
Update files.
|
||||
When used with the
|
||||
.Fl r
|
||||
option, files in the archive will be replaced
|
||||
only if the disk file has a newer modification time than the file in
|
||||
the archive.
|
||||
When used with the
|
||||
.Fl x
|
||||
option, files in the archive will be extracted
|
||||
only if the archive file has a newer modification time than the file
|
||||
on disk.
|
||||
.It Fl v
|
||||
Provide verbose output.
|
||||
When used with the
|
||||
.Fl d ,
|
||||
.Fl m ,
|
||||
.Fl q
|
||||
or
|
||||
.Fl x
|
||||
options,
|
||||
.Nm
|
||||
gives a file-by-file description of the archive modification.
|
||||
This description consists of three, white-space separated fields: the
|
||||
option letter, a dash (``-'') and the file name.
|
||||
When used with the
|
||||
.Fl r
|
||||
option,
|
||||
.Nm
|
||||
displays the description as above, but the initial letter is an ``a'' if
|
||||
the file is added to the archive and an ``r'' if the file replaces a file
|
||||
already in the archive.
|
||||
.Pp
|
||||
When used with the
|
||||
.Fl p
|
||||
option,
|
||||
the name of each printed file,
|
||||
enclosed in less-than (``<'') and greater-than (``>'') characters,
|
||||
is written to the standard output before
|
||||
the contents of the file;
|
||||
it is preceded by a single newline character, and
|
||||
followed by two newline characters.
|
||||
.Pp
|
||||
When used with the
|
||||
.Fl t
|
||||
option,
|
||||
.Nm
|
||||
displays an ``ls -l'' style listing of information about the members of
|
||||
the archive.
|
||||
This listing consists of eight, white-space separated fields:
|
||||
the file permissions (see
|
||||
.Xr strmode 3 ) ,
|
||||
the decimal user and group ID's, separated by a single slash (``/''),
|
||||
the file size (in bytes), the file modification time (in the
|
||||
.Xr date 1
|
||||
format ``%b %e %H:%M %Y''), and the name of the file.
|
||||
.It Fl x
|
||||
Extract the specified archive members into the files named by the command
|
||||
line arguments.
|
||||
If no members are specified, all the members of the archive are extracted into
|
||||
the current directory.
|
||||
.Pp
|
||||
If the file does not exist, it is created; if it does exist, the owner
|
||||
and group will be unchanged.
|
||||
The file access and modification times are the time of the extraction
|
||||
(but see the
|
||||
.Fl o
|
||||
option).
|
||||
The file permissions will be set to those of the file when it was entered
|
||||
into the archive; this will fail if the user is not the owner of the
|
||||
extracted file or the super-user.
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
.Ex -std
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width indent -compact
|
||||
.It Ev TMPDIR
|
||||
The pathname of the directory to use when creating temporary files.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent -compact
|
||||
.It Pa /tmp
|
||||
default temporary file directory
|
||||
.It Pa ar.XXXXXX
|
||||
temporary file names
|
||||
.El
|
||||
.Sh COMPATIBILITY
|
||||
By default,
|
||||
.Nm
|
||||
writes archives that may be incompatible with historic archives, as
|
||||
the format used for storing archive members with names longer than
|
||||
fifteen characters has changed.
|
||||
This implementation of
|
||||
.Nm
|
||||
is backward compatible with previous versions of
|
||||
.Nm
|
||||
in that it can read and write (using the
|
||||
.Fl T
|
||||
option) historic archives.
|
||||
The
|
||||
.Fl T
|
||||
option is provided for compatibility only, and will be deleted
|
||||
in a future release.
|
||||
See
|
||||
.Xr ar 5
|
||||
for more information.
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to offer a superset of the
|
||||
.St -p1003.2
|
||||
functionality.
|
||||
.Sh SEE ALSO
|
||||
.Xr ld 1 ,
|
||||
.Xr ranlib 1 ,
|
||||
.Xr strmode 3 ,
|
||||
.Xr ar 5
|
@ -1,318 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Hugh Smith at The University of Guelph.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)ar.1 8.1 (Berkeley) 6/29/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 29, 1993
|
||||
.Dt AR 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ar
|
||||
.Nd create and maintain library archives
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Fl d
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl m
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl m
|
||||
.Op Fl abiTv
|
||||
.Ar position archive Ar
|
||||
.Nm
|
||||
.Fl p
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Op Ar
|
||||
.Nm
|
||||
.Fl q
|
||||
.Op Fl cTv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl r
|
||||
.Op Fl cuTv
|
||||
.Ar archive Ar
|
||||
.Nm
|
||||
.Fl r
|
||||
.Op Fl abciuTv
|
||||
.Ar position archive Ar
|
||||
.Nm
|
||||
.Fl t
|
||||
.Op Fl \&Tv
|
||||
.Ar archive Op Ar
|
||||
.Nm
|
||||
.Fl x
|
||||
.Op Fl ouTv
|
||||
.Ar archive Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility creates and maintains groups of files combined into an archive.
|
||||
Once an archive has been created, new files can be added and existing
|
||||
files can be extracted, deleted, or replaced.
|
||||
.Pp
|
||||
Files are named in the archive by a single component, i.e., if a file
|
||||
referenced by a path containing a slash (``/'') is archived it will be
|
||||
named by the last component of that path.
|
||||
When matching paths listed on the command line against file names stored
|
||||
in the archive, only the last component of the path will be compared.
|
||||
.Pp
|
||||
All informational and error messages use the path listed on the command
|
||||
line, if any was specified; otherwise the name in the archive is used.
|
||||
If multiple files in the archive have the same name, and paths are listed
|
||||
on the command line to ``select'' archive files for an operation, only the
|
||||
.Em first
|
||||
file with a matching name will be selected.
|
||||
.Pp
|
||||
The normal use of
|
||||
.Nm
|
||||
is for the creation and maintenance of libraries suitable for use with
|
||||
the loader (see
|
||||
.Xr ld 1 )
|
||||
although it is not restricted to this purpose.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
A positioning modifier used with the options
|
||||
.Fl r
|
||||
and
|
||||
.Fl m .
|
||||
The files are entered or moved
|
||||
.Em after
|
||||
the archive member
|
||||
.Ar position ,
|
||||
which must be specified.
|
||||
.It Fl b
|
||||
A positioning modifier used with the options
|
||||
.Fl r
|
||||
and
|
||||
.Fl m .
|
||||
The files are entered or moved
|
||||
.Em before
|
||||
the archive member
|
||||
.Ar position ,
|
||||
which must be specified.
|
||||
.It Fl c
|
||||
Whenever an archive is created, an informational message to that effect
|
||||
is written to standard error.
|
||||
If the
|
||||
.Fl c
|
||||
option is specified,
|
||||
.Nm
|
||||
creates the archive silently.
|
||||
.It Fl d
|
||||
Delete the specified archive files.
|
||||
.It Fl i
|
||||
Identical to the
|
||||
.Fl b
|
||||
option.
|
||||
.It Fl m
|
||||
Move the specified archive files within the archive.
|
||||
If one of the options
|
||||
.Fl a ,
|
||||
.Fl b
|
||||
or
|
||||
.Fl i
|
||||
is specified, the files are moved
|
||||
before or after the
|
||||
.Ar position
|
||||
file in the archive.
|
||||
If none of those options are specified, the files are moved
|
||||
to the end of the archive.
|
||||
.It Fl o
|
||||
Set the access and modification times of extracted files to the
|
||||
modification time of the file when it was entered into the archive.
|
||||
This will fail if the user is not the owner of the extracted file
|
||||
or the super-user.
|
||||
.It Fl p
|
||||
Write the contents of the specified archive files to the standard output.
|
||||
If no files are specified, the contents of all the files in the archive
|
||||
are written in the order they appear in the archive.
|
||||
.It Fl q
|
||||
(Quickly) append the specified files to the archive.
|
||||
If the archive does not exist a new archive file is created.
|
||||
Much faster than the
|
||||
.Fl r
|
||||
option, when creating a large archive
|
||||
piece-by-piece, as no checking is done to see if the files already
|
||||
exist in the archive.
|
||||
.It Fl r
|
||||
Replace or add the specified files to the archive.
|
||||
If the archive does not exist a new archive file is created.
|
||||
Files that replace existing files do not change the order of the files
|
||||
within the archive.
|
||||
New files are appended to the archive unless one of the options
|
||||
.Fl a ,
|
||||
.Fl b
|
||||
or
|
||||
.Fl i
|
||||
is specified.
|
||||
.It Fl T
|
||||
Select and/or name archive members using only the first fifteen characters
|
||||
of the archive member or command line file name.
|
||||
The historic archive format had sixteen bytes for the name, but some
|
||||
historic archiver and loader implementations were unable to handle names
|
||||
that used the entire space.
|
||||
This means that file names that are not unique in their first fifteen
|
||||
characters can subsequently be confused.
|
||||
A warning message is printed to the standard error output if any file
|
||||
names are truncated.
|
||||
(See
|
||||
.Xr ar 5
|
||||
for more information.)
|
||||
.It Fl t
|
||||
List the specified files in the order in which they appear in the archive,
|
||||
each on a separate line.
|
||||
If no files are specified, all files in the archive are listed.
|
||||
.It Fl u
|
||||
Update files.
|
||||
When used with the
|
||||
.Fl r
|
||||
option, files in the archive will be replaced
|
||||
only if the disk file has a newer modification time than the file in
|
||||
the archive.
|
||||
When used with the
|
||||
.Fl x
|
||||
option, files in the archive will be extracted
|
||||
only if the archive file has a newer modification time than the file
|
||||
on disk.
|
||||
.It Fl v
|
||||
Provide verbose output.
|
||||
When used with the
|
||||
.Fl d ,
|
||||
.Fl m ,
|
||||
.Fl q
|
||||
or
|
||||
.Fl x
|
||||
options,
|
||||
.Nm
|
||||
gives a file-by-file description of the archive modification.
|
||||
This description consists of three, white-space separated fields: the
|
||||
option letter, a dash (``-'') and the file name.
|
||||
When used with the
|
||||
.Fl r
|
||||
option,
|
||||
.Nm
|
||||
displays the description as above, but the initial letter is an ``a'' if
|
||||
the file is added to the archive and an ``r'' if the file replaces a file
|
||||
already in the archive.
|
||||
.Pp
|
||||
When used with the
|
||||
.Fl p
|
||||
option,
|
||||
the name of each printed file,
|
||||
enclosed in less-than (``<'') and greater-than (``>'') characters,
|
||||
is written to the standard output before
|
||||
the contents of the file;
|
||||
it is preceded by a single newline character, and
|
||||
followed by two newline characters.
|
||||
.Pp
|
||||
When used with the
|
||||
.Fl t
|
||||
option,
|
||||
.Nm
|
||||
displays an ``ls -l'' style listing of information about the members of
|
||||
the archive.
|
||||
This listing consists of eight, white-space separated fields:
|
||||
the file permissions (see
|
||||
.Xr strmode 3 ) ,
|
||||
the decimal user and group ID's, separated by a single slash (``/''),
|
||||
the file size (in bytes), the file modification time (in the
|
||||
.Xr date 1
|
||||
format ``%b %e %H:%M %Y''), and the name of the file.
|
||||
.It Fl x
|
||||
Extract the specified archive members into the files named by the command
|
||||
line arguments.
|
||||
If no members are specified, all the members of the archive are extracted into
|
||||
the current directory.
|
||||
.Pp
|
||||
If the file does not exist, it is created; if it does exist, the owner
|
||||
and group will be unchanged.
|
||||
The file access and modification times are the time of the extraction
|
||||
(but see the
|
||||
.Fl o
|
||||
option).
|
||||
The file permissions will be set to those of the file when it was entered
|
||||
into the archive; this will fail if the user is not the owner of the
|
||||
extracted file or the super-user.
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
.Ex -std
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width indent -compact
|
||||
.It Ev TMPDIR
|
||||
The pathname of the directory to use when creating temporary files.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent -compact
|
||||
.It Pa /tmp
|
||||
default temporary file directory
|
||||
.It Pa ar.XXXXXX
|
||||
temporary file names
|
||||
.El
|
||||
.Sh COMPATIBILITY
|
||||
By default,
|
||||
.Nm
|
||||
writes archives that may be incompatible with historic archives, as
|
||||
the format used for storing archive members with names longer than
|
||||
fifteen characters has changed.
|
||||
This implementation of
|
||||
.Nm
|
||||
is backward compatible with previous versions of
|
||||
.Nm
|
||||
in that it can read and write (using the
|
||||
.Fl T
|
||||
option) historic archives.
|
||||
The
|
||||
.Fl T
|
||||
option is provided for compatibility only, and will be deleted
|
||||
in a future release.
|
||||
See
|
||||
.Xr ar 5
|
||||
for more information.
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to offer a superset of the
|
||||
.St -p1003.2
|
||||
functionality.
|
||||
.Sh SEE ALSO
|
||||
.Xr ld 1 ,
|
||||
.Xr ranlib 1 ,
|
||||
.Xr strmode 3 ,
|
||||
.Xr ar 5
|
147
usr.bin/ar/ar.5
147
usr.bin/ar/ar.5
@ -1,147 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)ar.5.5 8.1 (Berkeley) 6/9/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 9, 1993
|
||||
.Dt AR 5
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ar
|
||||
.Nd archive (library) file format
|
||||
.Sh SYNOPSIS
|
||||
.In ar.h
|
||||
.Sh DESCRIPTION
|
||||
The archive command
|
||||
.Nm
|
||||
combines several files into one.
|
||||
Archives are mainly used as libraries of object files intended to be
|
||||
loaded using the link-editor
|
||||
.Xr ld 1 .
|
||||
.Pp
|
||||
A file created with
|
||||
.Nm
|
||||
begins with the ``magic'' string "!<arch>\en".
|
||||
The rest of the archive is made up of objects, each of which is composed
|
||||
of a header for a file, a possible file name, and the file contents.
|
||||
The header is portable between machine architectures, and, if the file
|
||||
contents are printable, the archive is itself printable.
|
||||
.Pp
|
||||
The header is made up of six variable length
|
||||
.Tn ASCII
|
||||
fields, followed by a
|
||||
two character trailer.
|
||||
The fields are the object name (16 characters), the file last modification
|
||||
time (12 characters), the user and group id's (each 6 characters), the file
|
||||
mode (8 characters) and the file size (10 characters).
|
||||
All numeric fields are in decimal, except for the file mode which is in
|
||||
octal.
|
||||
.Pp
|
||||
The modification time is the file
|
||||
.Fa st_mtime
|
||||
field, i.e.,
|
||||
.Dv CUT
|
||||
seconds since
|
||||
the epoch.
|
||||
The user and group id's are the file
|
||||
.Fa st_uid
|
||||
and
|
||||
.Fa st_gid
|
||||
fields.
|
||||
The file mode is the file
|
||||
.Fa st_mode
|
||||
field.
|
||||
The file size is the file
|
||||
.Fa st_size
|
||||
field.
|
||||
The two-byte trailer is the string "\`\en".
|
||||
.Pp
|
||||
Only the name field has any provision for overflow.
|
||||
If any file name is more than 16 characters in length or contains an
|
||||
embedded space, the string "#1/" followed by the
|
||||
.Tn ASCII
|
||||
length of the
|
||||
name is written in the name field.
|
||||
The file size (stored in the archive header) is incremented by the length
|
||||
of the name.
|
||||
The name is then written immediately following the archive header.
|
||||
.Pp
|
||||
Any unused characters in any of these fields are written as space
|
||||
characters.
|
||||
If any fields are their particular maximum number of characters in
|
||||
length, there will be no separation between the fields.
|
||||
.Pp
|
||||
Objects in the archive are always an even number of bytes long; files
|
||||
which are an odd number of bytes long are padded with a newline (``\en'')
|
||||
character, although the size in the header does not reflect this.
|
||||
.Sh SEE ALSO
|
||||
.Xr ar 1 ,
|
||||
.Xr stat 2
|
||||
.Sh HISTORY
|
||||
There have been at least four
|
||||
.Nm
|
||||
formats.
|
||||
The first was denoted by the leading ``magic'' number 0177555 (stored as
|
||||
type int).
|
||||
These archives were almost certainly created on a 16-bit machine, and
|
||||
contain headers made up of five fields.
|
||||
The fields are the object name (8 characters), the file last modification
|
||||
time (type long), the user id (type char), the file mode (type char) and
|
||||
the file size (type unsigned int).
|
||||
Files were padded to an even number of bytes.
|
||||
.Pp
|
||||
The second was denoted by the leading ``magic'' number 0177545 (stored as
|
||||
type int).
|
||||
These archives may have been created on either 16 or 32-bit machines, and
|
||||
contain headers made up of six fields.
|
||||
The fields are the object name (14 characters), the file last modification
|
||||
time (type long), the user and group id's (each type char), the file mode
|
||||
(type int) and the file size (type long).
|
||||
Files were padded to an even number of bytes.
|
||||
.\" For more information on converting from this format see
|
||||
.\" .Xr arcv 8 .
|
||||
.Pp
|
||||
The current archive format (without support for long character names and
|
||||
names with embedded spaces) was introduced in
|
||||
.Bx 4.0 .
|
||||
The headers were the same as the current format, with the exception that
|
||||
names longer than 16 characters were truncated, and names with embedded
|
||||
spaces (and often trailing spaces) were not supported.
|
||||
It has been extended for these reasons,
|
||||
as described above.
|
||||
This format first appeared in
|
||||
.Bx 4.4 .
|
||||
.Sh COMPATIBILITY
|
||||
No archive format is currently specified by any standard.
|
||||
.At V
|
||||
has historically distributed archives in a different format from
|
||||
all of the above.
|
246
usr.bin/ar/ar.c
246
usr.bin/ar/ar.c
@ -1,246 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1990, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ar.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <ar.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <libgen.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
CHDR chdr;
|
||||
u_int options;
|
||||
char *archive, *posarg, *posname;
|
||||
const char *envtmp;
|
||||
static void badoptions(const char *);
|
||||
static void usage(void);
|
||||
|
||||
/*
|
||||
* main --
|
||||
* main basically uses getopt to parse options and calls the appropriate
|
||||
* functions. Some hacks that let us be backward compatible with 4.3 ar
|
||||
* option parsing and sanity checking.
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
char *p;
|
||||
int (*fcall)(char **) = NULL;
|
||||
|
||||
(void) setlocale(LC_TIME, "");;
|
||||
|
||||
if (argc < 3)
|
||||
usage();
|
||||
|
||||
/*
|
||||
* Historic versions didn't require a '-' in front of the options.
|
||||
* Fix it, if necessary.
|
||||
*/
|
||||
if (*argv[1] != '-') {
|
||||
if (!(p = malloc((u_int)(strlen(argv[1]) + 2))))
|
||||
err(1, NULL);
|
||||
*p = '-';
|
||||
(void)strcpy(p + 1, argv[1]);
|
||||
argv[1] = p;
|
||||
}
|
||||
|
||||
while ((c = getopt(argc, argv, "abcdilmopqrTtuvx")) != -1) {
|
||||
switch(c) {
|
||||
case 'a':
|
||||
options |= AR_A;
|
||||
break;
|
||||
case 'b':
|
||||
case 'i':
|
||||
options |= AR_B;
|
||||
break;
|
||||
case 'c':
|
||||
options |= AR_C;
|
||||
break;
|
||||
case 'd':
|
||||
options |= AR_D;
|
||||
fcall = delete;
|
||||
break;
|
||||
case 'l': /* not documented, compatibility only */
|
||||
envtmp = ".";
|
||||
break;
|
||||
case 'm':
|
||||
options |= AR_M;
|
||||
fcall = move;
|
||||
break;
|
||||
case 'o':
|
||||
options |= AR_O;
|
||||
break;
|
||||
case 'p':
|
||||
options |= AR_P;
|
||||
fcall = print;
|
||||
break;
|
||||
case 'q':
|
||||
options |= AR_Q;
|
||||
fcall = append;
|
||||
break;
|
||||
case 'r':
|
||||
options |= AR_R;
|
||||
fcall = replace;
|
||||
break;
|
||||
case 'T':
|
||||
options |= AR_TR;
|
||||
break;
|
||||
case 't':
|
||||
options |= AR_T;
|
||||
fcall = contents;
|
||||
break;
|
||||
case 'u':
|
||||
options |= AR_U;
|
||||
break;
|
||||
case 'v':
|
||||
options |= AR_V;
|
||||
break;
|
||||
case 'x':
|
||||
options |= AR_X;
|
||||
fcall = extract;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
/* One of -dmpqrtx required. */
|
||||
if (!(options & (AR_D|AR_M|AR_P|AR_Q|AR_R|AR_T|AR_X))) {
|
||||
warnx("one of options -dmpqrtx is required");
|
||||
usage();
|
||||
}
|
||||
/* Only one of -a and -bi allowed. */
|
||||
if (options & AR_A && options & AR_B) {
|
||||
warnx("only one of -a and -[bi] options allowed");
|
||||
usage();
|
||||
}
|
||||
/* -ab require a position argument. */
|
||||
if (options & (AR_A|AR_B)) {
|
||||
if (!(posarg = *argv++)) {
|
||||
warnx("no position operand specified");
|
||||
usage();
|
||||
}
|
||||
posname = basename(posarg);
|
||||
}
|
||||
/* -d only valid with -Tv. */
|
||||
if (options & AR_D && options & ~(AR_D|AR_TR|AR_V))
|
||||
badoptions("-d");
|
||||
/* -m only valid with -abiTv. */
|
||||
if (options & AR_M && options & ~(AR_A|AR_B|AR_M|AR_TR|AR_V))
|
||||
badoptions("-m");
|
||||
/* -p only valid with -Tv. */
|
||||
if (options & AR_P && options & ~(AR_P|AR_TR|AR_V))
|
||||
badoptions("-p");
|
||||
/* -q only valid with -cTv. */
|
||||
if (options & AR_Q && options & ~(AR_C|AR_Q|AR_TR|AR_V))
|
||||
badoptions("-q");
|
||||
/* -r only valid with -abcuTv. */
|
||||
if (options & AR_R && options & ~(AR_A|AR_B|AR_C|AR_R|AR_U|AR_TR|AR_V))
|
||||
badoptions("-r");
|
||||
/* -t only valid with -Tv. */
|
||||
if (options & AR_T && options & ~(AR_T|AR_TR|AR_V))
|
||||
badoptions("-t");
|
||||
/* -x only valid with -ouTv. */
|
||||
if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X))
|
||||
badoptions("-x");
|
||||
|
||||
if (!(archive = *argv++)) {
|
||||
warnx("no archive specified");
|
||||
usage();
|
||||
}
|
||||
|
||||
/* -dmr require a list of archive elements. */
|
||||
if (options & (AR_D|AR_M|AR_R) && !*argv) {
|
||||
warnx("no archive members specified");
|
||||
usage();
|
||||
}
|
||||
|
||||
exit((*fcall)(argv));
|
||||
}
|
||||
|
||||
static void
|
||||
badoptions(arg)
|
||||
const char *arg;
|
||||
{
|
||||
|
||||
warnx("illegal option combination for %s", arg);
|
||||
usage();
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
||||
"usage: ar -d [-Tv] archive file ...",
|
||||
" ar -m [-Tv] archive file ...",
|
||||
" ar -m [-abiTv] position archive file ...",
|
||||
" ar -p [-Tv] archive [file ...]",
|
||||
" ar -q [-cTv] archive file ...",
|
||||
" ar -r [-cuTv] archive file ...",
|
||||
" ar -r [-abciuTv] position archive file ...",
|
||||
" ar -t [-Tv] archive [file ...]",
|
||||
" ar -x [-ouTv] archive [file ...]");
|
||||
exit(1);
|
||||
}
|
@ -1,333 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)archive.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ar.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
typedef struct ar_hdr HDR;
|
||||
static char hb[sizeof(HDR) + 1]; /* real header */
|
||||
|
||||
int
|
||||
open_archive(mode)
|
||||
int mode;
|
||||
{
|
||||
int created, fd, nr;
|
||||
char buf[SARMAG];
|
||||
|
||||
created = 0;
|
||||
if (mode & O_CREAT) {
|
||||
mode |= O_EXCL;
|
||||
if ((fd = open(archive, mode, DEFFILEMODE)) >= 0) {
|
||||
/* POSIX.2 puts create message on stderr. */
|
||||
if (!(options & AR_C))
|
||||
warnx("creating archive %s", archive);
|
||||
created = 1;
|
||||
goto opened;
|
||||
}
|
||||
if (errno != EEXIST)
|
||||
error(archive);
|
||||
mode &= ~O_EXCL;
|
||||
}
|
||||
if ((fd = open(archive, mode, DEFFILEMODE)) < 0)
|
||||
error(archive);
|
||||
|
||||
/*
|
||||
* Attempt to place a lock on the opened file - if we get an
|
||||
* error then someone is already working on this library (or
|
||||
* it's going across NFS).
|
||||
*/
|
||||
opened: if (flock(fd, LOCK_EX|LOCK_NB) && errno != EOPNOTSUPP)
|
||||
error(archive);
|
||||
|
||||
/*
|
||||
* If not created, O_RDONLY|O_RDWR indicates that it has to be
|
||||
* in archive format.
|
||||
*/
|
||||
if (!created &&
|
||||
((mode & O_ACCMODE) == O_RDONLY || (mode & O_ACCMODE) == O_RDWR)) {
|
||||
if ((nr = read(fd, buf, SARMAG) != SARMAG)) {
|
||||
if (nr >= 0)
|
||||
badfmt();
|
||||
error(archive);
|
||||
} else if (bcmp(buf, ARMAG, SARMAG))
|
||||
badfmt();
|
||||
} else if (write(fd, ARMAG, SARMAG) != SARMAG)
|
||||
error(archive);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
void
|
||||
close_archive(fd)
|
||||
int fd;
|
||||
{
|
||||
|
||||
(void)close(fd); /* Implicit unlock. */
|
||||
}
|
||||
|
||||
/* Convert ar header field to an integer. */
|
||||
#define AR_ATOI(from, to, len, base) { \
|
||||
memmove(buf, from, len); \
|
||||
buf[len] = '\0'; \
|
||||
to = strtol(buf, (char **)NULL, base); \
|
||||
}
|
||||
|
||||
/*
|
||||
* get_arobj --
|
||||
* read the archive header for this member
|
||||
*/
|
||||
int
|
||||
get_arobj(fd)
|
||||
int fd;
|
||||
{
|
||||
struct ar_hdr *hdr;
|
||||
int len, nr;
|
||||
char *p, buf[20];
|
||||
|
||||
nr = read(fd, hb, sizeof(HDR));
|
||||
if (nr != sizeof(HDR)) {
|
||||
if (!nr)
|
||||
return (0);
|
||||
if (nr < 0)
|
||||
error(archive);
|
||||
badfmt();
|
||||
}
|
||||
|
||||
hdr = (struct ar_hdr *)hb;
|
||||
if (strncmp(hdr->ar_fmag, ARFMAG, sizeof(ARFMAG) - 1))
|
||||
badfmt();
|
||||
|
||||
/* Convert the header into the internal format. */
|
||||
#define DECIMAL 10
|
||||
#define OCTAL 8
|
||||
|
||||
AR_ATOI(hdr->ar_date, chdr.date, sizeof(hdr->ar_date), DECIMAL);
|
||||
AR_ATOI(hdr->ar_uid, chdr.uid, sizeof(hdr->ar_uid), DECIMAL);
|
||||
AR_ATOI(hdr->ar_gid, chdr.gid, sizeof(hdr->ar_gid), DECIMAL);
|
||||
AR_ATOI(hdr->ar_mode, chdr.mode, sizeof(hdr->ar_mode), OCTAL);
|
||||
AR_ATOI(hdr->ar_size, chdr.size, sizeof(hdr->ar_size), DECIMAL);
|
||||
|
||||
/* Leading spaces should never happen. */
|
||||
if (hdr->ar_name[0] == ' ')
|
||||
badfmt();
|
||||
|
||||
/*
|
||||
* Long name support. Set the "real" size of the file, and the
|
||||
* long name flag/size.
|
||||
*/
|
||||
if (!bcmp(hdr->ar_name, AR_EFMT1, sizeof(AR_EFMT1) - 1)) {
|
||||
chdr.lname = len = atoi(hdr->ar_name + sizeof(AR_EFMT1) - 1);
|
||||
if (len <= 0 || len > MAXNAMLEN)
|
||||
badfmt();
|
||||
nr = read(fd, chdr.name, len);
|
||||
if (nr != len) {
|
||||
if (nr < 0)
|
||||
error(archive);
|
||||
badfmt();
|
||||
}
|
||||
chdr.name[len] = 0;
|
||||
chdr.size -= len;
|
||||
} else {
|
||||
chdr.lname = 0;
|
||||
memmove(chdr.name, hdr->ar_name, sizeof(hdr->ar_name));
|
||||
|
||||
/* Strip trailing spaces, null terminate. */
|
||||
for (p = chdr.name + sizeof(hdr->ar_name) - 1; *p == ' '; --p);
|
||||
*++p = '\0';
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int already_written;
|
||||
|
||||
/*
|
||||
* put_arobj --
|
||||
* Write an archive member to a file.
|
||||
*/
|
||||
void
|
||||
put_arobj(cfp, sb)
|
||||
CF *cfp;
|
||||
struct stat *sb;
|
||||
{
|
||||
size_t lname;
|
||||
char *name;
|
||||
struct ar_hdr *hdr;
|
||||
off_t size;
|
||||
|
||||
/*
|
||||
* If passed an sb structure, reading a file from disk. Get stat(2)
|
||||
* information, build a name and construct a header. (Files are named
|
||||
* by their last component in the archive.) If not, then just write
|
||||
* the last header read.
|
||||
*/
|
||||
if (sb) {
|
||||
name = basename(cfp->rname);
|
||||
(void)fstat(cfp->rfd, sb);
|
||||
|
||||
/*
|
||||
* If not truncating names and the name is too long or contains
|
||||
* a space, use extended format 1.
|
||||
*/
|
||||
lname = strlen(name);
|
||||
if (options & AR_TR) {
|
||||
if (lname > OLDARMAXNAME) {
|
||||
(void)fflush(stdout);
|
||||
warnx("warning: %s truncated to %.*s",
|
||||
name, OLDARMAXNAME, name);
|
||||
(void)fflush(stderr);
|
||||
}
|
||||
(void)sprintf(hb, HDR3, name,
|
||||
(long)sb->st_mtimespec.tv_sec, sb->st_uid,
|
||||
sb->st_gid, sb->st_mode, sb->st_size, ARFMAG);
|
||||
lname = 0;
|
||||
} else if (lname > sizeof(hdr->ar_name) || strchr(name, ' '))
|
||||
(void)sprintf(hb, HDR1, AR_EFMT1, lname,
|
||||
(long)sb->st_mtimespec.tv_sec, sb->st_uid,
|
||||
sb->st_gid, sb->st_mode, sb->st_size + lname,
|
||||
ARFMAG);
|
||||
else {
|
||||
lname = 0;
|
||||
(void)sprintf(hb, HDR2, name,
|
||||
(long)sb->st_mtimespec.tv_sec, sb->st_uid,
|
||||
sb->st_gid, sb->st_mode, sb->st_size, ARFMAG);
|
||||
}
|
||||
size = sb->st_size;
|
||||
} else {
|
||||
lname = chdr.lname;
|
||||
name = chdr.name;
|
||||
size = chdr.size;
|
||||
}
|
||||
|
||||
if (write(cfp->wfd, hb, sizeof(HDR)) != sizeof(HDR))
|
||||
error(cfp->wname);
|
||||
if (lname) {
|
||||
if ((size_t)write(cfp->wfd, name, lname) != lname)
|
||||
error(cfp->wname);
|
||||
already_written = lname;
|
||||
}
|
||||
copy_ar(cfp, size);
|
||||
already_written = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* copy_ar --
|
||||
* Copy size bytes from one file to another - taking care to handle the
|
||||
* extra byte (for odd size files) when reading archives and writing an
|
||||
* extra byte if necessary when adding files to archive. The length of
|
||||
* the object is the long name plus the object itself; the variable
|
||||
* already_written gets set if a long name was written.
|
||||
*
|
||||
* The padding is really unnecessary, and is almost certainly a remnant
|
||||
* of early archive formats where the header included binary data which
|
||||
* a PDP-11 required to start on an even byte boundary. (Or, perhaps,
|
||||
* because 16-bit word addressed copies were faster?) Anyhow, it should
|
||||
* have been ripped out long ago.
|
||||
*/
|
||||
void
|
||||
copy_ar(cfp, size)
|
||||
CF *cfp;
|
||||
off_t size;
|
||||
{
|
||||
static char pad = '\n';
|
||||
off_t sz;
|
||||
int from, nr = 0, nw, off, to;
|
||||
char buf[8*1024];
|
||||
|
||||
if (!(sz = size))
|
||||
return;
|
||||
|
||||
from = cfp->rfd;
|
||||
to = cfp->wfd;
|
||||
sz = size;
|
||||
while (sz && (nr = read(from, buf, MIN(sz, sizeof(buf)))) > 0) {
|
||||
sz -= nr;
|
||||
for (off = 0; off < nr; nr -= off, off += nw)
|
||||
if ((nw = write(to, buf + off, nr)) < 0)
|
||||
error(cfp->wname);
|
||||
}
|
||||
if (sz) {
|
||||
if (nr == 0)
|
||||
badfmt();
|
||||
error(cfp->rname);
|
||||
}
|
||||
|
||||
if (cfp->flags & RPAD && (size + chdr.lname) & 1 &&
|
||||
(nr = read(from, buf, 1)) != 1) {
|
||||
if (nr == 0)
|
||||
badfmt();
|
||||
error(cfp->rname);
|
||||
}
|
||||
if (cfp->flags & WPAD && (size + already_written) & 1 &&
|
||||
write(to, &pad, 1) != 1)
|
||||
error(cfp->wname);
|
||||
}
|
||||
|
||||
/*
|
||||
* skip_arobj -
|
||||
* Skip over an object -- taking care to skip the pad bytes.
|
||||
*/
|
||||
void
|
||||
skip_arobj(fd)
|
||||
int fd;
|
||||
{
|
||||
off_t len;
|
||||
|
||||
len = chdr.size + ( (chdr.size + chdr.lname) & 1);
|
||||
if (lseek(fd, len, SEEK_CUR) == (off_t)-1)
|
||||
error(archive);
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*
|
||||
* @(#)archive.h 8.3 (Berkeley) 4/2/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/* Ar(1) options. */
|
||||
#define AR_A 0x0001
|
||||
#define AR_B 0x0002
|
||||
#define AR_C 0x0004
|
||||
#define AR_D 0x0008
|
||||
#define AR_M 0x0010
|
||||
#define AR_O 0x0020
|
||||
#define AR_P 0x0040
|
||||
#define AR_Q 0x0080
|
||||
#define AR_R 0x0100
|
||||
#define AR_T 0x0200
|
||||
#define AR_TR 0x0400
|
||||
#define AR_U 0x0800
|
||||
#define AR_V 0x1000
|
||||
#define AR_X 0x2000
|
||||
extern u_int options;
|
||||
|
||||
/* Set up file copy. */
|
||||
#define SETCF(from, fromname, to, toname, pad) { \
|
||||
cf.rfd = from; \
|
||||
cf.rname = fromname; \
|
||||
cf.wfd = to; \
|
||||
cf.wname = toname; \
|
||||
cf.flags = pad; \
|
||||
}
|
||||
|
||||
/* File copy structure. */
|
||||
typedef struct {
|
||||
int rfd; /* read file descriptor */
|
||||
const char *rname; /* read name */
|
||||
int wfd; /* write file descriptor */
|
||||
const char *wname; /* write name */
|
||||
#define NOPAD 0x00 /* don't pad */
|
||||
#define RPAD 0x01 /* pad on reads */
|
||||
#define WPAD 0x02 /* pad on writes */
|
||||
u_int flags; /* pad flags */
|
||||
} CF;
|
||||
|
||||
/* Header structure internal format. */
|
||||
typedef struct {
|
||||
off_t size; /* size of the object in bytes */
|
||||
time_t date; /* date */
|
||||
int lname; /* size of the long name in bytes */
|
||||
int gid; /* group */
|
||||
int uid; /* owner */
|
||||
u_short mode; /* permissions */
|
||||
char name[MAXNAMLEN + 1]; /* name */
|
||||
} CHDR;
|
||||
|
||||
/* Header format strings. */
|
||||
#define HDR1 "%s%-13d%-12ld%-6u%-6u%-8o%-10qd%2s"
|
||||
#define HDR2 "%-16.16s%-12ld%-6u%-6u%-8o%-10qd%2s"
|
||||
|
||||
#define OLDARMAXNAME 15
|
||||
#define HDR3 "%-16.15s%-12ld%-6u%-6u%-8o%-10qd%2s"
|
||||
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
struct stat;
|
||||
|
||||
void close_archive(int);
|
||||
void copy_ar(CF *, off_t);
|
||||
int get_arobj(int);
|
||||
int open_archive(int);
|
||||
void put_arobj(CF *, struct stat *);
|
||||
void skip_arobj(int);
|
@ -1,109 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)contents.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ar.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <langinfo.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* contents --
|
||||
* Handles t[v] option - opens the archive and then reads headers,
|
||||
* skipping member contents.
|
||||
*/
|
||||
int
|
||||
contents(argv)
|
||||
char **argv;
|
||||
{
|
||||
int afd, all;
|
||||
struct tm *tp;
|
||||
char *file, buf[80];
|
||||
|
||||
afd = open_archive(O_RDONLY);
|
||||
|
||||
for (all = !*argv; get_arobj(afd);) {
|
||||
if (all)
|
||||
file = chdr.name;
|
||||
else if (!(file = files(argv)))
|
||||
goto next;
|
||||
if (options & AR_V) {
|
||||
static int d_first = -1;
|
||||
|
||||
(void)strmode(chdr.mode, buf);
|
||||
(void)printf("%s %6d/%-6d %8qd ",
|
||||
buf + 1, chdr.uid, chdr.gid, chdr.size);
|
||||
|
||||
if (d_first < 0)
|
||||
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
|
||||
tp = localtime(&chdr.date);
|
||||
(void)strftime(buf, sizeof(buf),
|
||||
d_first ? "%e %b %R %Y" :
|
||||
"%b %e %R %Y",
|
||||
tp);
|
||||
(void)printf("%s %s\n", buf, file);
|
||||
} else
|
||||
(void)printf("%s\n", file);
|
||||
if (!all && !*argv)
|
||||
break;
|
||||
next: skip_arobj(afd);
|
||||
}
|
||||
close_archive(afd);
|
||||
|
||||
if (*argv) {
|
||||
orphans(argv);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)delete.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ar.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
/*-
|
||||
* delete --
|
||||
* Deletes named members from the archive.
|
||||
*/
|
||||
int
|
||||
delete(argv)
|
||||
char **argv;
|
||||
{
|
||||
CF cf;
|
||||
off_t size;
|
||||
int afd, tfd;
|
||||
char *file;
|
||||
|
||||
afd = open_archive(O_RDWR);
|
||||
tfd = tmp();
|
||||
|
||||
/* Read and write to an archive; pad on both. */
|
||||
SETCF(afd, archive, tfd, tname, RPAD|WPAD);
|
||||
while (get_arobj(afd)) {
|
||||
if (*argv && (file = files(argv))) {
|
||||
if (options & AR_V)
|
||||
(void)printf("d - %s\n", file);
|
||||
skip_arobj(afd);
|
||||
continue;
|
||||
}
|
||||
put_arobj(&cf, (struct stat *)NULL);
|
||||
}
|
||||
|
||||
size = lseek(tfd, (off_t)0, SEEK_CUR);
|
||||
(void)lseek(tfd, (off_t)0, SEEK_SET);
|
||||
(void)lseek(afd, (off_t)SARMAG, SEEK_SET);
|
||||
SETCF(tfd, tname, afd, archive, NOPAD);
|
||||
copy_ar(&cf, size);
|
||||
(void)close(tfd);
|
||||
(void)ftruncate(afd, size + SARMAG);
|
||||
close_archive(afd);
|
||||
|
||||
if (*argv) {
|
||||
orphans(argv);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*
|
||||
* @(#)extern.h 8.3 (Berkeley) 4/2/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
int append(char **);
|
||||
void badfmt(void);
|
||||
int compare(char *);
|
||||
int contents(char **);
|
||||
int delete(char **);
|
||||
void error(const char *);
|
||||
int extract(char **);
|
||||
char *files(char **argv);
|
||||
int move(char **);
|
||||
void orphans(char **argv);
|
||||
int print(char **);
|
||||
int replace(char **);
|
||||
int tmp(void);
|
||||
|
||||
extern char *archive;
|
||||
extern char *posarg, *posname; /* positioning file name */
|
||||
extern const char *tname; /* temporary file "name" */
|
||||
extern CHDR chdr; /* converted header */
|
@ -1,133 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)extract.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* extract --
|
||||
* Extract files from the named archive - if member names given only
|
||||
* extract those members otherwise extract all members. If 'o' option
|
||||
* selected modify date of newly created file to be same as archive
|
||||
* members date otherwise date is time of extraction. Does not modify
|
||||
* archive.
|
||||
*/
|
||||
int
|
||||
extract(argv)
|
||||
char **argv;
|
||||
{
|
||||
char *file;
|
||||
int afd, all, eval, tfd;
|
||||
struct timeval tv[2];
|
||||
struct stat sb;
|
||||
CF cf;
|
||||
|
||||
eval = 0;
|
||||
tv[0].tv_usec = tv[1].tv_usec = 0;
|
||||
|
||||
afd = open_archive(O_RDONLY);
|
||||
|
||||
/* Read from an archive, write to disk; pad on read. */
|
||||
SETCF(afd, archive, 0, 0, RPAD);
|
||||
for (all = !*argv; get_arobj(afd);) {
|
||||
if (all)
|
||||
file = chdr.name;
|
||||
else if (!(file = files(argv))) {
|
||||
skip_arobj(afd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options & AR_U && !stat(file, &sb) &&
|
||||
sb.st_mtime > chdr.date)
|
||||
continue;
|
||||
|
||||
if ((tfd = open(file, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR)) < 0) {
|
||||
warn("%s", file);
|
||||
skip_arobj(afd);
|
||||
eval = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options & AR_V)
|
||||
(void)printf("x - %s\n", file);
|
||||
|
||||
cf.wfd = tfd;
|
||||
cf.wname = file;
|
||||
copy_ar(&cf, chdr.size);
|
||||
|
||||
if (fchmod(tfd, (short)chdr.mode)) {
|
||||
warn("chmod: %s", file);
|
||||
eval = 1;
|
||||
}
|
||||
if (options & AR_O) {
|
||||
tv[0].tv_sec = tv[1].tv_sec = chdr.date;
|
||||
if (utimes(file, tv)) {
|
||||
warn("utimes: %s", file);
|
||||
eval = 1;
|
||||
}
|
||||
}
|
||||
(void)close(tfd);
|
||||
if (!all && !*argv)
|
||||
break;
|
||||
}
|
||||
close_archive(afd);
|
||||
|
||||
if (*argv) {
|
||||
orphans(argv);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
const char *tname = "temporary file"; /* temporary file "name" */
|
||||
|
||||
int
|
||||
tmp()
|
||||
{
|
||||
extern char *envtmp;
|
||||
sigset_t set, oset;
|
||||
static int first;
|
||||
int fd;
|
||||
char path[MAXPATHLEN];
|
||||
|
||||
if (!first && !envtmp) {
|
||||
envtmp = getenv("TMPDIR");
|
||||
first = 1;
|
||||
}
|
||||
|
||||
if (envtmp)
|
||||
(void)snprintf(path, sizeof(path), "%s/%s", envtmp,
|
||||
_NAME_ARTMP);
|
||||
else
|
||||
strlcpy(path, _PATH_ARTMP, sizeof(path));
|
||||
|
||||
sigfillset(&set);
|
||||
(void)sigprocmask(SIG_BLOCK, &set, &oset);
|
||||
if ((fd = mkstemp(path)) == -1)
|
||||
error(tname);
|
||||
(void)unlink(path);
|
||||
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* files --
|
||||
* See if the current file matches any file in the argument list; if it
|
||||
* does, remove it from the argument list.
|
||||
*/
|
||||
char *
|
||||
files(argv)
|
||||
char **argv;
|
||||
{
|
||||
char **list, *p;
|
||||
|
||||
for (list = argv; *list; ++list)
|
||||
if (compare(*list)) {
|
||||
p = *list;
|
||||
for (; (list[0] = list[1]); ++list)
|
||||
continue;
|
||||
return (p);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
orphans(argv)
|
||||
char **argv;
|
||||
{
|
||||
|
||||
for (; *argv; ++argv)
|
||||
warnx("%s: not found in archive", *argv);
|
||||
}
|
||||
|
||||
int
|
||||
compare(dest)
|
||||
char *dest;
|
||||
{
|
||||
int maxname = (options & AR_TR) ? OLDARMAXNAME : MAXNAMLEN;
|
||||
return (!strncmp(chdr.name, basename(dest), maxname));
|
||||
}
|
||||
|
||||
void
|
||||
badfmt()
|
||||
{
|
||||
|
||||
errx(1, "%s: %s", archive, strerror(EFTYPE));
|
||||
}
|
||||
|
||||
void
|
||||
error(name)
|
||||
const char *name;
|
||||
{
|
||||
|
||||
err(1, "%s", name);
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)move.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ar.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
/*
|
||||
* move --
|
||||
* Change location of named members in archive - if 'b' or 'i' option
|
||||
* selected then named members are placed before 'posname'. If 'a'
|
||||
* option selected members go after 'posname'. If no options, members
|
||||
* are moved to end of archive.
|
||||
*/
|
||||
int
|
||||
move(argv)
|
||||
char **argv;
|
||||
{
|
||||
CF cf;
|
||||
off_t size, tsize;
|
||||
int afd, curfd, mods, tfd1, tfd2, tfd3;
|
||||
char *file;
|
||||
|
||||
afd = open_archive(O_RDWR);
|
||||
mods = options & (AR_A|AR_B);
|
||||
|
||||
tfd1 = tmp(); /* Files before key file. */
|
||||
tfd2 = tmp(); /* Files selected by user. */
|
||||
tfd3 = tmp(); /* Files after key file. */
|
||||
|
||||
/*
|
||||
* Break archive into three parts -- selected entries and entries
|
||||
* before and after the key entry. If positioning before the key,
|
||||
* place the key at the beginning of the after key entries and if
|
||||
* positioning after the key, place the key at the end of the before
|
||||
* key entries. Put it all back together at the end.
|
||||
*/
|
||||
|
||||
/* Read and write to an archive; pad on both. */
|
||||
SETCF(afd, archive, 0, tname, RPAD|WPAD);
|
||||
for (curfd = tfd1; get_arobj(afd);) {
|
||||
if (*argv && (file = files(argv))) {
|
||||
if (options & AR_V)
|
||||
(void)printf("m - %s\n", file);
|
||||
cf.wfd = tfd2;
|
||||
put_arobj(&cf, (struct stat *)NULL);
|
||||
continue;
|
||||
}
|
||||
if (mods && compare(posname)) {
|
||||
mods = 0;
|
||||
if (options & AR_B)
|
||||
curfd = tfd3;
|
||||
cf.wfd = curfd;
|
||||
put_arobj(&cf, (struct stat *)NULL);
|
||||
if (options & AR_A)
|
||||
curfd = tfd3;
|
||||
} else {
|
||||
cf.wfd = curfd;
|
||||
put_arobj(&cf, (struct stat *)NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (mods) {
|
||||
warnx("%s: archive member not found", posarg);
|
||||
close_archive(afd);
|
||||
return (1);
|
||||
}
|
||||
(void)lseek(afd, (off_t)SARMAG, SEEK_SET);
|
||||
|
||||
SETCF(tfd1, tname, afd, archive, NOPAD);
|
||||
tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR);
|
||||
(void)lseek(tfd1, (off_t)0, SEEK_SET);
|
||||
copy_ar(&cf, size);
|
||||
|
||||
tsize += size = lseek(tfd2, (off_t)0, SEEK_CUR);
|
||||
(void)lseek(tfd2, (off_t)0, SEEK_SET);
|
||||
cf.rfd = tfd2;
|
||||
copy_ar(&cf, size);
|
||||
|
||||
tsize += size = lseek(tfd3, (off_t)0, SEEK_CUR);
|
||||
(void)lseek(tfd3, (off_t)0, SEEK_SET);
|
||||
cf.rfd = tfd3;
|
||||
copy_ar(&cf, size);
|
||||
|
||||
(void)ftruncate(afd, tsize + SARMAG);
|
||||
close_archive(afd);
|
||||
|
||||
if (*argv) {
|
||||
orphans(argv);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
|
||||
*/
|
||||
|
||||
#define _NAME_ARTMP "ar.XXXXXX"
|
||||
#define _PATH_ARTMP "/tmp/ar.XXXXXX"
|
@ -1,95 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* print --
|
||||
* Prints archive members on stdout - if member names given only
|
||||
* print those members, otherwise print all members.
|
||||
*/
|
||||
int
|
||||
print(argv)
|
||||
char **argv;
|
||||
{
|
||||
CF cf;
|
||||
int afd, all;
|
||||
char *file;
|
||||
|
||||
afd = open_archive(O_RDONLY);
|
||||
|
||||
/* Read from an archive, write to stdout; pad on read. */
|
||||
SETCF(afd, archive, STDOUT_FILENO, "stdout", RPAD);
|
||||
for (all = !*argv; get_arobj(afd);) {
|
||||
if (all)
|
||||
file = chdr.name;
|
||||
else if (!(file = files(argv))) {
|
||||
skip_arobj(afd);
|
||||
continue;
|
||||
}
|
||||
if (options & AR_V) {
|
||||
(void)printf("\n<%s>\n\n", file);
|
||||
(void)fflush(stdout);
|
||||
}
|
||||
copy_ar(&cf, chdr.size);
|
||||
if (!all && !*argv)
|
||||
break;
|
||||
}
|
||||
close_archive(afd);
|
||||
|
||||
if (*argv) {
|
||||
orphans(argv);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hugh Smith at The University of Guelph.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)replace.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ar.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "archive.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* replace --
|
||||
* Replace or add named members to archive. Entries already in the
|
||||
* archive are swapped in place. Others are added before or after
|
||||
* the key entry, based on the a, b and i options. If the u option
|
||||
* is specified, modification dates select for replacement.
|
||||
*/
|
||||
int
|
||||
replace(argv)
|
||||
char **argv;
|
||||
{
|
||||
char *file;
|
||||
int afd, curfd, errflg, exists, mods, sfd, tfd1, tfd2;
|
||||
struct stat sb;
|
||||
CF cf;
|
||||
off_t size, tsize;
|
||||
|
||||
errflg = 0;
|
||||
/*
|
||||
* If doesn't exist, simply append to the archive. There's
|
||||
* a race here, but it's pretty short, and not worth fixing.
|
||||
*/
|
||||
exists = !stat(archive, &sb);
|
||||
afd = open_archive(O_CREAT|O_RDWR);
|
||||
|
||||
if (!exists) {
|
||||
tfd1 = -1;
|
||||
tfd2 = tmp();
|
||||
goto append;
|
||||
}
|
||||
|
||||
tfd1 = tmp(); /* Files before key file. */
|
||||
tfd2 = tmp(); /* Files after key file. */
|
||||
|
||||
/*
|
||||
* Break archive into two parts -- entries before and after the key
|
||||
* entry. If positioning before the key, place the key at the
|
||||
* beginning of the after key entries and if positioning after the
|
||||
* key, place the key at the end of the before key entries. Put it
|
||||
* all back together at the end.
|
||||
*/
|
||||
mods = (options & (AR_A|AR_B));
|
||||
for (curfd = tfd1; get_arobj(afd);) {
|
||||
if (*argv && (file = files(argv))) {
|
||||
if ((sfd = open(file, O_RDONLY)) < 0) {
|
||||
errflg = 1;
|
||||
warn("%s", file);
|
||||
goto useold;
|
||||
}
|
||||
(void)fstat(sfd, &sb);
|
||||
if (options & AR_U && sb.st_mtime <= chdr.date) {
|
||||
(void) close(sfd);
|
||||
goto useold;
|
||||
}
|
||||
|
||||
if (options & AR_V)
|
||||
(void)printf("r - %s\n", file);
|
||||
|
||||
/* Read from disk, write to an archive; pad on write */
|
||||
SETCF(sfd, file, curfd, tname, WPAD);
|
||||
put_arobj(&cf, &sb);
|
||||
(void)close(sfd);
|
||||
skip_arobj(afd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mods && compare(posname)) {
|
||||
mods = 0;
|
||||
if (options & AR_B)
|
||||
curfd = tfd2;
|
||||
/* Read and write to an archive; pad on both. */
|
||||
SETCF(afd, archive, curfd, tname, RPAD|WPAD);
|
||||
put_arobj(&cf, (struct stat *)NULL);
|
||||
if (options & AR_A)
|
||||
curfd = tfd2;
|
||||
} else {
|
||||
/* Read and write to an archive; pad on both. */
|
||||
useold: SETCF(afd, archive, curfd, tname, RPAD|WPAD);
|
||||
put_arobj(&cf, (struct stat *)NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (mods) {
|
||||
warnx("%s: archive member not found", posarg);
|
||||
close_archive(afd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Append any left-over arguments to the end of the after file. */
|
||||
append: while ( (file = *argv++) ) {
|
||||
if (options & AR_V)
|
||||
(void)printf("a - %s\n", file);
|
||||
if ((sfd = open(file, O_RDONLY)) < 0) {
|
||||
errflg = 1;
|
||||
warn("%s", file);
|
||||
continue;
|
||||
}
|
||||
(void)fstat(sfd, &sb);
|
||||
/* Read from disk, write to an archive; pad on write. */
|
||||
SETCF(sfd, file,
|
||||
options & (AR_A|AR_B) ? tfd1 : tfd2, tname, WPAD);
|
||||
put_arobj(&cf, &sb);
|
||||
(void)close(sfd);
|
||||
}
|
||||
|
||||
(void)lseek(afd, (off_t)SARMAG, SEEK_SET);
|
||||
|
||||
SETCF(tfd1, tname, afd, archive, NOPAD);
|
||||
if (tfd1 != -1) {
|
||||
tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR);
|
||||
(void)lseek(tfd1, (off_t)0, SEEK_SET);
|
||||
copy_ar(&cf, size);
|
||||
} else
|
||||
tsize = 0;
|
||||
|
||||
tsize += size = lseek(tfd2, (off_t)0, SEEK_CUR);
|
||||
(void)lseek(tfd2, (off_t)0, SEEK_SET);
|
||||
cf.rfd = tfd2;
|
||||
copy_ar(&cf, size);
|
||||
|
||||
(void)ftruncate(afd, tsize + SARMAG);
|
||||
close_archive(afd);
|
||||
return (errflg);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= nm
|
||||
BINDIR= /usr/libexec/aout
|
||||
MAN= nm.1aout
|
||||
|
||||
.include <bsd.prog.mk>
|
155
usr.bin/nm/nm.1
155
usr.bin/nm/nm.1
@ -1,155 +0,0 @@
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)nm.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt NM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm nm
|
||||
.Nd display name list (symbol table)
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl agnoprtuwW
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The symbol table (name list) of each object in
|
||||
.Ar file Ns (s)
|
||||
is displayed.
|
||||
If a library (archive) is given,
|
||||
.Nm
|
||||
displays a list for each
|
||||
object archive member.
|
||||
If
|
||||
.Ar file
|
||||
is not present,
|
||||
.Nm
|
||||
searches for the file
|
||||
.Pa a.out
|
||||
and if present, displays the symbol
|
||||
table for
|
||||
.Pa a.out .
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
Display symbol table entries inserted for use by debuggers.
|
||||
.It Fl g
|
||||
Restrict display to external (global) symbols.
|
||||
.It Fl n
|
||||
Present results in numerical order.
|
||||
.It Fl o
|
||||
Display full path or library name of object on every line.
|
||||
.It Fl p
|
||||
Do not sort at all.
|
||||
.It Fl r
|
||||
Reverse order sort.
|
||||
.It Fl t
|
||||
Output in tabular format more suitable for other programs digestive system.
|
||||
.It Fl u
|
||||
Display undefined symbols only.
|
||||
.It Fl w
|
||||
Warn about non-object archive members.
|
||||
Normally, nm will silently ignore all archive members which are not
|
||||
object files.
|
||||
.It Fl W
|
||||
Include an extra column in the output with a ``W'' indicating weak symbols.
|
||||
.El
|
||||
.Pp
|
||||
Each symbol name is preceded by its value (a blank field if the symbol
|
||||
is undefined) and one of the following letters:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -compact -offset indent
|
||||
.It Fl
|
||||
debugger symbol table entries (see the
|
||||
.Fl a
|
||||
option)
|
||||
.It Li A
|
||||
absolute
|
||||
.It Li B
|
||||
bss segment symbol
|
||||
.It Li C
|
||||
common symbol
|
||||
.It Li D
|
||||
data segment symbol
|
||||
.It Li f
|
||||
file name
|
||||
.It Li I
|
||||
indirect reference symbol
|
||||
.It Li T
|
||||
text segment symbol
|
||||
.It Li U
|
||||
undefined
|
||||
.It Li W
|
||||
warn if next symbol is referenced
|
||||
.El
|
||||
.Pp
|
||||
If the symbol is local (non-external) the type letter is in lower case.
|
||||
The output is sorted alphabetically.
|
||||
.Sh KEYWORDS
|
||||
The following is a complete list of keywords and their meaning.
|
||||
The keyword is uppercase for external, lowercase for internal symbols.
|
||||
Only uppercase keywords are shown here.
|
||||
.Pp
|
||||
.Bl -tag -width sigignore -compact
|
||||
.It A
|
||||
Absolute Address
|
||||
.It B
|
||||
BSS Segment
|
||||
.It C
|
||||
Common Reference
|
||||
.It D
|
||||
Data Segment
|
||||
.It F
|
||||
Filename (external only)
|
||||
.It w
|
||||
Warning refs (internal only)
|
||||
.It I
|
||||
Alias definition
|
||||
.It T
|
||||
Text Segment
|
||||
.It U
|
||||
Undefined
|
||||
.It ?
|
||||
None of the above
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr ar 1 ,
|
||||
.Xr a.out 5 ,
|
||||
.Xr ar 5 ,
|
||||
.Xr stab 5
|
||||
.Sh HISTORY
|
||||
An
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
@ -1,155 +0,0 @@
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)nm.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt NM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm nm
|
||||
.Nd display name list (symbol table)
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl agnoprtuwW
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The symbol table (name list) of each object in
|
||||
.Ar file Ns (s)
|
||||
is displayed.
|
||||
If a library (archive) is given,
|
||||
.Nm
|
||||
displays a list for each
|
||||
object archive member.
|
||||
If
|
||||
.Ar file
|
||||
is not present,
|
||||
.Nm
|
||||
searches for the file
|
||||
.Pa a.out
|
||||
and if present, displays the symbol
|
||||
table for
|
||||
.Pa a.out .
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
Display symbol table entries inserted for use by debuggers.
|
||||
.It Fl g
|
||||
Restrict display to external (global) symbols.
|
||||
.It Fl n
|
||||
Present results in numerical order.
|
||||
.It Fl o
|
||||
Display full path or library name of object on every line.
|
||||
.It Fl p
|
||||
Do not sort at all.
|
||||
.It Fl r
|
||||
Reverse order sort.
|
||||
.It Fl t
|
||||
Output in tabular format more suitable for other programs digestive system.
|
||||
.It Fl u
|
||||
Display undefined symbols only.
|
||||
.It Fl w
|
||||
Warn about non-object archive members.
|
||||
Normally, nm will silently ignore all archive members which are not
|
||||
object files.
|
||||
.It Fl W
|
||||
Include an extra column in the output with a ``W'' indicating weak symbols.
|
||||
.El
|
||||
.Pp
|
||||
Each symbol name is preceded by its value (a blank field if the symbol
|
||||
is undefined) and one of the following letters:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -compact -offset indent
|
||||
.It Fl
|
||||
debugger symbol table entries (see the
|
||||
.Fl a
|
||||
option)
|
||||
.It Li A
|
||||
absolute
|
||||
.It Li B
|
||||
bss segment symbol
|
||||
.It Li C
|
||||
common symbol
|
||||
.It Li D
|
||||
data segment symbol
|
||||
.It Li f
|
||||
file name
|
||||
.It Li I
|
||||
indirect reference symbol
|
||||
.It Li T
|
||||
text segment symbol
|
||||
.It Li U
|
||||
undefined
|
||||
.It Li W
|
||||
warn if next symbol is referenced
|
||||
.El
|
||||
.Pp
|
||||
If the symbol is local (non-external) the type letter is in lower case.
|
||||
The output is sorted alphabetically.
|
||||
.Sh KEYWORDS
|
||||
The following is a complete list of keywords and their meaning.
|
||||
The keyword is uppercase for external, lowercase for internal symbols.
|
||||
Only uppercase keywords are shown here.
|
||||
.Pp
|
||||
.Bl -tag -width sigignore -compact
|
||||
.It A
|
||||
Absolute Address
|
||||
.It B
|
||||
BSS Segment
|
||||
.It C
|
||||
Common Reference
|
||||
.It D
|
||||
Data Segment
|
||||
.It F
|
||||
Filename (external only)
|
||||
.It w
|
||||
Warning refs (internal only)
|
||||
.It I
|
||||
Alias definition
|
||||
.It T
|
||||
Text Segment
|
||||
.It U
|
||||
Undefined
|
||||
.It ?
|
||||
None of the above
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr ar 1 ,
|
||||
.Xr a.out 5 ,
|
||||
.Xr ar 5 ,
|
||||
.Xr stab 5
|
||||
.Sh HISTORY
|
||||
An
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
657
usr.bin/nm/nm.c
657
usr.bin/nm/nm.c
@ -1,657 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Hans Huebner.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)nm.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <a.out.h>
|
||||
#include <ar.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <ranlib.h>
|
||||
#include <stab.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int ignore_bad_archive_entries = 1;
|
||||
int print_only_external_symbols;
|
||||
int print_only_undefined_symbols;
|
||||
int print_all_symbols;
|
||||
int print_file_each_line;
|
||||
int print_weak_symbols;
|
||||
int fcount;
|
||||
|
||||
int rev, table;
|
||||
const char *typestring(u_char);
|
||||
|
||||
/* some macros for symbol type (nlist.n_type) handling */
|
||||
#define IS_DEBUGGER_SYMBOL(x) ((x) & N_STAB)
|
||||
#define IS_EXTERNAL(x) ((x) & N_EXT)
|
||||
#define SYMBOL_TYPE(x) ((x) & (N_TYPE | N_STAB))
|
||||
#define SYMBOL_BIND(x) (((x) >> 4) & 0xf)
|
||||
|
||||
static void usage(void);
|
||||
int process_file(const char *);
|
||||
int show_archive(const char *, FILE *);
|
||||
int show_objfile(const char *, FILE *);
|
||||
void print_symbol(const char *, struct nlist *);
|
||||
char typeletter(u_char);
|
||||
int fname(const void *, const void *);
|
||||
int rname(const void *, const void *);
|
||||
int value(const void *, const void *);
|
||||
|
||||
int (*sfunc)(const void *, const void *) = fname;
|
||||
|
||||
/*
|
||||
* main()
|
||||
* parse command line, execute process_file() for each file
|
||||
* specified on the command line.
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch, errors;
|
||||
|
||||
while ((ch = getopt(argc, argv, "agnoprtuwW")) != -1) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
print_all_symbols = 1;
|
||||
break;
|
||||
case 'g':
|
||||
print_only_external_symbols = 1;
|
||||
break;
|
||||
case 'n':
|
||||
sfunc = value;
|
||||
break;
|
||||
case 'o':
|
||||
print_file_each_line = 1;
|
||||
break;
|
||||
case 'p':
|
||||
sfunc = NULL;
|
||||
break;
|
||||
case 'r':
|
||||
rev = 1;
|
||||
break;
|
||||
case 't':
|
||||
table = 1;
|
||||
break;
|
||||
case 'u':
|
||||
print_only_undefined_symbols = 1;
|
||||
break;
|
||||
case 'w':
|
||||
ignore_bad_archive_entries = 0;
|
||||
break;
|
||||
case 'W':
|
||||
print_weak_symbols = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
fcount = argc - optind;
|
||||
argv += optind;
|
||||
|
||||
if (rev && sfunc == fname)
|
||||
sfunc = rname;
|
||||
|
||||
if (!fcount)
|
||||
errors = process_file("a.out");
|
||||
else {
|
||||
errors = 0;
|
||||
do {
|
||||
errors |= process_file(*argv);
|
||||
} while (*++argv);
|
||||
}
|
||||
exit(errors);
|
||||
}
|
||||
|
||||
/*
|
||||
* process_file()
|
||||
* show symbols in the file given as an argument. Accepts archive and
|
||||
* object files as input.
|
||||
*/
|
||||
int
|
||||
process_file(const char *fn)
|
||||
{
|
||||
struct exec exec_head;
|
||||
FILE *fp;
|
||||
int retval;
|
||||
char magic[SARMAG];
|
||||
|
||||
if (!(fp = fopen(fn, "r"))) {
|
||||
warnx("cannot read %s", fn);
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (fcount > 1 && !table)
|
||||
(void)printf("\n%s:\n", fn);
|
||||
|
||||
/*
|
||||
* First check whether this is an object file - read an object
|
||||
* header, and skip back to the beginning.
|
||||
*/
|
||||
if (fread((char *)&exec_head, sizeof(exec_head), (size_t)1, fp) != 1) {
|
||||
warnx("%s: bad format", fn);
|
||||
(void)fclose(fp);
|
||||
return(1);
|
||||
}
|
||||
rewind(fp);
|
||||
|
||||
/* this could be an archive */
|
||||
if (N_BADMAG(exec_head)) {
|
||||
if (fread(magic, sizeof(magic), (size_t)1, fp) != 1 ||
|
||||
strncmp(magic, ARMAG, SARMAG)) {
|
||||
warnx("%s: not object file or archive", fn);
|
||||
(void)fclose(fp);
|
||||
return(1);
|
||||
}
|
||||
retval = show_archive(fn, fp);
|
||||
} else
|
||||
retval = show_objfile(fn, fp);
|
||||
(void)fclose(fp);
|
||||
return(retval);
|
||||
}
|
||||
|
||||
/* scat: concatenate strings, returning new concatenation point
|
||||
* and permitting overlap.
|
||||
*/
|
||||
static char
|
||||
*scat(char *dest, const char *src)
|
||||
{
|
||||
char *end;
|
||||
int l1 = strlen(dest), l2 = strlen(src);
|
||||
|
||||
memmove(dest + l1, src, l2);
|
||||
end = dest + l1 + l2;
|
||||
*end = 0;
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
/*
|
||||
* show_archive()
|
||||
* show symbols in the given archive file
|
||||
*/
|
||||
int
|
||||
show_archive(const char *fn, FILE *fp)
|
||||
{
|
||||
struct ar_hdr ar_head;
|
||||
struct exec exec_head;
|
||||
int i, rval;
|
||||
long last_ar_off;
|
||||
char *p, *name, *ar_name;
|
||||
int extra = strlen(fn) + 3;
|
||||
|
||||
if ((name = malloc(MAXNAMLEN + extra)) == NULL)
|
||||
err(1, NULL);
|
||||
ar_name = name + extra;
|
||||
|
||||
rval = 0;
|
||||
|
||||
/* while there are more entries in the archive */
|
||||
while (fread((char *)&ar_head, sizeof(ar_head), (size_t)1, fp) == 1) {
|
||||
/* bad archive entry - stop processing this archive */
|
||||
if (strncmp(ar_head.ar_fmag, ARFMAG, sizeof(ar_head.ar_fmag))) {
|
||||
warnx("%s: bad format archive header", fn);
|
||||
(void)free(name);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* remember start position of current archive object */
|
||||
last_ar_off = ftell(fp);
|
||||
|
||||
/* skip ranlib entries */
|
||||
if (!bcmp(ar_head.ar_name, RANLIBMAG, sizeof(RANLIBMAG) - 1))
|
||||
goto skip;
|
||||
|
||||
/* handle long names. If one is present, read it in at the
|
||||
* end of the "name" buffer.
|
||||
*/
|
||||
if (!bcmp(ar_head.ar_name, AR_EFMT1, sizeof(AR_EFMT1) - 1))
|
||||
{
|
||||
size_t len = atoi(ar_head.ar_name + sizeof(AR_EFMT1) - 1);
|
||||
|
||||
if (len <= 0 || len > MAXNAMLEN)
|
||||
{
|
||||
warnx("illegal length for format 1 long name");
|
||||
goto skip;
|
||||
}
|
||||
if (fread(ar_name, 1, len, fp) != len)
|
||||
{
|
||||
warnx("EOF reading format 1 long name");
|
||||
(void)free(name);
|
||||
return(1);
|
||||
}
|
||||
ar_name[len] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = ar_head.ar_name;
|
||||
for (i = 0; i < (int)sizeof(ar_head.ar_name) && p[i] && p[i] != ' '; i++)
|
||||
ar_name[i] = p[i];
|
||||
ar_name[i] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* construct a name of the form "archive.a:obj.o:" for the
|
||||
* current archive entry if the object name is to be printed
|
||||
* on each output line
|
||||
*/
|
||||
p = name;
|
||||
*p = 0;
|
||||
if (print_file_each_line && !table)
|
||||
{
|
||||
p = scat(p, fn);
|
||||
p = scat(p, ":");
|
||||
}
|
||||
p = scat(p, ar_name);
|
||||
|
||||
/* get and check current object's header */
|
||||
if (fread((char *)&exec_head, sizeof(exec_head), (size_t)1, fp) != 1) {
|
||||
warnx("%s: premature EOF", name);
|
||||
(void)free(name);
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (N_BADMAG(exec_head)) {
|
||||
if (!ignore_bad_archive_entries) {
|
||||
warnx("%s: bad format", name);
|
||||
rval = 1;
|
||||
}
|
||||
} else {
|
||||
(void)fseek(fp, -(long)sizeof(exec_head),
|
||||
SEEK_CUR);
|
||||
if (!print_file_each_line && !table)
|
||||
(void)printf("\n%s:\n", name);
|
||||
rval |= show_objfile(name, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* skip to next archive object - it starts at the next
|
||||
* even byte boundary
|
||||
*/
|
||||
#define even(x) (((x) + 1) & ~1)
|
||||
skip: if (fseek(fp, last_ar_off + even(atol(ar_head.ar_size)),
|
||||
SEEK_SET)) {
|
||||
warn("%s", fn);
|
||||
(void)free(name);
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
(void)free(name);
|
||||
return(rval);
|
||||
}
|
||||
|
||||
/*
|
||||
* show_objfile()
|
||||
* show symbols from the object file pointed to by fp. The current
|
||||
* file pointer for fp is expected to be at the beginning of an a.out
|
||||
* header.
|
||||
*/
|
||||
int
|
||||
show_objfile(const char *objname, FILE *fp)
|
||||
{
|
||||
struct nlist *names, *np;
|
||||
int i, nnames, nrawnames;
|
||||
struct exec head;
|
||||
int32_t stabsize;
|
||||
char *stab;
|
||||
|
||||
/* read a.out header */
|
||||
if (fread((char *)&head, sizeof(head), (size_t)1, fp) != 1) {
|
||||
warnx("%s: cannot read header", objname);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* skip back to the header - the N_-macros return values relative
|
||||
* to the beginning of the a.out header
|
||||
*/
|
||||
if (fseek(fp, -(long)sizeof(head), SEEK_CUR)) {
|
||||
warn("%s", objname);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* stop if this is no valid object file */
|
||||
if (N_BADMAG(head)) {
|
||||
warnx("%s: bad format", objname);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* stop if the object file contains no symbol table */
|
||||
if (!head.a_syms) {
|
||||
warnx("%s: no name list", objname);
|
||||
return(1);
|
||||
}
|
||||
|
||||
if (fseek(fp, (long)N_SYMOFF(head), SEEK_CUR)) {
|
||||
warn("%s", objname);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* get memory for the symbol table */
|
||||
if ((names = malloc((size_t)head.a_syms)) == NULL)
|
||||
err(1, NULL);
|
||||
nrawnames = head.a_syms / sizeof(*names);
|
||||
if (fread((char *)names, (size_t)head.a_syms, (size_t)1, fp) != 1) {
|
||||
warnx("%s: cannot read symbol table", objname);
|
||||
(void)free((char *)names);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Following the symbol table comes the string table. The first
|
||||
* 4-byte-integer gives the total size of the string table
|
||||
* _including_ the size specification itself.
|
||||
*/
|
||||
if (fread((char *)&stabsize, sizeof(stabsize), (size_t)1, fp) != 1) {
|
||||
warnx("%s: cannot read stab size", objname);
|
||||
(void)free((char *)names);
|
||||
return(1);
|
||||
}
|
||||
if ((stab = malloc((size_t)stabsize)) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
/*
|
||||
* read the string table offset by 4 - all indices into the string
|
||||
* table include the size specification.
|
||||
*/
|
||||
stabsize -= 4; /* we already have the size */
|
||||
if (fread(stab + 4, (size_t)stabsize, (size_t)1, fp) != 1) {
|
||||
warnx("%s: stab truncated..", objname);
|
||||
(void)free((char *)names);
|
||||
(void)free(stab);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* fix up the symbol table and filter out unwanted entries
|
||||
*
|
||||
* common symbols are characterized by a n_type of N_UNDF and a
|
||||
* non-zero n_value -- change n_type to N_COMM for all such
|
||||
* symbols to make life easier later.
|
||||
*
|
||||
* filter out all entries which we don't want to print anyway
|
||||
*/
|
||||
for (np = names, i = nnames = 0; i < nrawnames; np++, i++) {
|
||||
if (SYMBOL_TYPE(np->n_type) == N_UNDF && np->n_value)
|
||||
np->n_type = N_COMM | (np->n_type & N_EXT);
|
||||
if (!print_all_symbols && IS_DEBUGGER_SYMBOL(np->n_type))
|
||||
continue;
|
||||
if (print_only_external_symbols && !IS_EXTERNAL(np->n_type))
|
||||
continue;
|
||||
if (print_only_undefined_symbols &&
|
||||
SYMBOL_TYPE(np->n_type) != N_UNDF)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* make n_un.n_name a character pointer by adding the string
|
||||
* table's base to n_un.n_strx
|
||||
*
|
||||
* don't mess with zero offsets
|
||||
*/
|
||||
if (np->n_un.n_strx)
|
||||
np->n_un.n_name = stab + np->n_un.n_strx;
|
||||
else
|
||||
np->n_un.n_name = strdup("");
|
||||
names[nnames++] = *np;
|
||||
}
|
||||
|
||||
/* sort the symbol table if applicable */
|
||||
if (sfunc)
|
||||
qsort((char *)names, (size_t)nnames, sizeof(*names), sfunc);
|
||||
|
||||
/* print out symbols */
|
||||
for (np = names, i = 0; i < nnames; np++, i++)
|
||||
print_symbol(objname, np);
|
||||
|
||||
(void)free((char *)names);
|
||||
(void)free(stab);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* print_symbol()
|
||||
* show one symbol
|
||||
*/
|
||||
void
|
||||
print_symbol(const char *objname, struct nlist *sym)
|
||||
{
|
||||
if (table) {
|
||||
printf("%s|", objname);
|
||||
if (SYMBOL_TYPE(sym->n_type) != N_UNDF)
|
||||
(void)printf("%08lx", (u_long)sym->n_value);
|
||||
(void)printf("|");
|
||||
if (IS_DEBUGGER_SYMBOL(sym->n_type))
|
||||
(void)printf("-|%02x %04x %5s|", sym->n_other,
|
||||
sym->n_desc&0xffff, typestring(sym->n_type));
|
||||
else {
|
||||
putchar(typeletter(sym->n_type));
|
||||
if (print_weak_symbols && SYMBOL_BIND(sym->n_other)== 2)
|
||||
putchar('W');
|
||||
putchar('|');
|
||||
}
|
||||
|
||||
/* print the symbol's name */
|
||||
(void)printf("%s\n",sym->n_un.n_name);
|
||||
return;
|
||||
}
|
||||
if (print_file_each_line)
|
||||
(void)printf("%s:", objname);
|
||||
|
||||
/*
|
||||
* handle undefined-only format separately (no space is
|
||||
* left for symbol values, no type field is printed)
|
||||
*/
|
||||
if (print_only_undefined_symbols) {
|
||||
(void)puts(sym->n_un.n_name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print symbol's value */
|
||||
if (SYMBOL_TYPE(sym->n_type) == N_UNDF)
|
||||
(void)printf(" ");
|
||||
else
|
||||
(void)printf("%08lx", (u_long)sym->n_value);
|
||||
|
||||
/* print type information */
|
||||
if (IS_DEBUGGER_SYMBOL(sym->n_type))
|
||||
(void)printf(" - %02x %04x %5s ", sym->n_other,
|
||||
sym->n_desc&0xffff, typestring(sym->n_type));
|
||||
else {
|
||||
putchar(' ');
|
||||
putchar(typeletter(sym->n_type));
|
||||
if (print_weak_symbols) {
|
||||
if (SYMBOL_BIND(sym->n_other) == 2)
|
||||
putchar('W');
|
||||
else
|
||||
putchar(' ');
|
||||
}
|
||||
putchar(' ');
|
||||
}
|
||||
|
||||
/* print the symbol's name */
|
||||
(void)puts(sym->n_un.n_name);
|
||||
}
|
||||
|
||||
/*
|
||||
* typestring()
|
||||
* return the a description string for an STAB entry
|
||||
*/
|
||||
const char *
|
||||
typestring(u_char type)
|
||||
{
|
||||
switch(type) {
|
||||
case N_BCOMM:
|
||||
return("BCOMM");
|
||||
case N_ECOML:
|
||||
return("ECOML");
|
||||
case N_ECOMM:
|
||||
return("ECOMM");
|
||||
case N_ENTRY:
|
||||
return("ENTRY");
|
||||
case N_FNAME:
|
||||
return("FNAME");
|
||||
case N_FUN:
|
||||
return("FUN");
|
||||
case N_GSYM:
|
||||
return("GSYM");
|
||||
case N_LBRAC:
|
||||
return("LBRAC");
|
||||
case N_LCSYM:
|
||||
return("LCSYM");
|
||||
case N_LENG:
|
||||
return("LENG");
|
||||
case N_LSYM:
|
||||
return("LSYM");
|
||||
case N_PC:
|
||||
return("PC");
|
||||
case N_PSYM:
|
||||
return("PSYM");
|
||||
case N_RBRAC:
|
||||
return("RBRAC");
|
||||
case N_RSYM:
|
||||
return("RSYM");
|
||||
case N_SLINE:
|
||||
return("SLINE");
|
||||
case N_SO:
|
||||
return("SO");
|
||||
case N_SOL:
|
||||
return("SOL");
|
||||
case N_SSYM:
|
||||
return("SSYM");
|
||||
case N_STSYM:
|
||||
return("STSYM");
|
||||
}
|
||||
return("???");
|
||||
}
|
||||
|
||||
/*
|
||||
* typeletter()
|
||||
* return a description letter for the given basic type code of an
|
||||
* symbol table entry. The return value will be upper case for
|
||||
* external, lower case for internal symbols.
|
||||
*/
|
||||
char
|
||||
typeletter(u_char type)
|
||||
{
|
||||
switch(SYMBOL_TYPE(type)) {
|
||||
case N_ABS:
|
||||
return(IS_EXTERNAL(type) ? 'A' : 'a');
|
||||
case N_BSS:
|
||||
return(IS_EXTERNAL(type) ? 'B' : 'b');
|
||||
case N_COMM:
|
||||
return(IS_EXTERNAL(type) ? 'C' : 'c');
|
||||
case N_DATA:
|
||||
return(IS_EXTERNAL(type) ? 'D' : 'd');
|
||||
case N_FN:
|
||||
/* This one is overloaded. EXT = Filename, INT = warn refs */
|
||||
return(IS_EXTERNAL(type) ? 'F' : 'w');
|
||||
case N_INDR:
|
||||
return(IS_EXTERNAL(type) ? 'I' : 'i');
|
||||
case N_TEXT:
|
||||
return(IS_EXTERNAL(type) ? 'T' : 't');
|
||||
case N_UNDF:
|
||||
return(IS_EXTERNAL(type) ? 'U' : 'u');
|
||||
}
|
||||
return('?');
|
||||
}
|
||||
|
||||
int
|
||||
fname(const void *a0, const void *b0)
|
||||
{
|
||||
const struct nlist *a = a0, *b = b0;
|
||||
|
||||
return(strcmp(a->n_un.n_name, b->n_un.n_name));
|
||||
}
|
||||
|
||||
int
|
||||
rname(const void *a0, const void *b0)
|
||||
{
|
||||
const struct nlist *a = a0, *b = b0;
|
||||
|
||||
return(strcmp(b->n_un.n_name, a->n_un.n_name));
|
||||
}
|
||||
|
||||
int
|
||||
value(const void *a0, const void *b0)
|
||||
{
|
||||
const struct nlist *a = a0, *b = b0;
|
||||
|
||||
if (SYMBOL_TYPE(a->n_type) == N_UNDF)
|
||||
if (SYMBOL_TYPE(b->n_type) == N_UNDF)
|
||||
return(0);
|
||||
else
|
||||
return(-1);
|
||||
else if (SYMBOL_TYPE(b->n_type) == N_UNDF)
|
||||
return(1);
|
||||
if (rev) {
|
||||
if (a->n_value == b->n_value)
|
||||
return(rname(a0, b0));
|
||||
return(b->n_value > a->n_value ? 1 : -1);
|
||||
} else {
|
||||
if (a->n_value == b->n_value)
|
||||
return(fname(a0, b0));
|
||||
return(a->n_value > b->n_value ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "usage: nm [-agnoprtuwW] [file ...]\n");
|
||||
exit(1);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= size
|
||||
MAN= size.1aout
|
||||
BINDIR= /usr/libexec/aout
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,63 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1993, 1994
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)size.1 8.2 (Berkeley) 4/18/94
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd April 18, 1994
|
||||
.Dt SIZE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm size
|
||||
.Nd display object file segment sizes (text, data and bss)
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar object_file ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility displays the text, data and bss segment sizes of the specified
|
||||
.Ar object_file
|
||||
in bytes (in decimal), and the sum of the three segments (in
|
||||
decimal and hexadecimal).
|
||||
If no
|
||||
.Ar object_file
|
||||
is specified
|
||||
.Nm
|
||||
attempts to report on the file
|
||||
.Pa a.out .
|
||||
.Sh SEE ALSO
|
||||
.Xr a.out 5
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v6 .
|
@ -1,61 +0,0 @@
|
||||
.\" Copyright (c) 1990, 1993, 1994
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)size.1 8.2 (Berkeley) 4/18/94
|
||||
.\"
|
||||
.Dd April 18, 1994
|
||||
.Dt SIZE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm size
|
||||
.Nd display object file segment sizes (text, data and bss)
|
||||
.Sh SYNOPSIS
|
||||
.Nm size
|
||||
.Op Ar object_file ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Size
|
||||
displays the text, data and bss segment sizes of the specified
|
||||
.Ar object_file
|
||||
in bytes (in decimal), and the sum of the three segments (in
|
||||
decimal and hexadecimal).
|
||||
If no
|
||||
.Ar object_file
|
||||
is specified
|
||||
.Nm
|
||||
attempts to report on the file
|
||||
.Pa a.out .
|
||||
.Sh SEE ALSO
|
||||
.Xr a.out 5
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v6 .
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)size.c 8.2 (Berkeley) 12/9/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <err.h>
|
||||
#include <a.out.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int show(int, const char *);
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int ch, eval;
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
switch(ch) {
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
eval = 0;
|
||||
if (*argv)
|
||||
do {
|
||||
eval |= show(argc, *argv);
|
||||
} while (*++argv);
|
||||
else
|
||||
eval |= show(1, "a.out");
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
int
|
||||
show(count, name)
|
||||
int count;
|
||||
const char *name;
|
||||
{
|
||||
static int first = 1;
|
||||
struct exec head;
|
||||
u_long total;
|
||||
int fd;
|
||||
|
||||
if ((fd = open(name, O_RDONLY, 0)) < 0) {
|
||||
warn("%s", name);
|
||||
return (1);
|
||||
}
|
||||
if (read(fd, &head, sizeof(head)) != sizeof(head) || N_BADMAG(head)) {
|
||||
(void)close(fd);
|
||||
warnx("%s: not in a.out format", name);
|
||||
return (1);
|
||||
}
|
||||
(void)close(fd);
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
(void)printf("text\tdata\tbss\tdec\thex\n");
|
||||
}
|
||||
total = head.a_text + head.a_data + head.a_bss;
|
||||
(void)printf("%lu\t%lu\t%lu\t%lu\t%lx", (u_long)head.a_text,
|
||||
(u_long)head.a_data, (u_long)head.a_bss, total, total);
|
||||
if (count > 1)
|
||||
(void)printf("\t%s", name);
|
||||
(void)printf("\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: size [file ...]\n");
|
||||
exit(1);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= strings
|
||||
MAN= strings.1aout
|
||||
BINDIR= /usr/libexec/aout
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,100 +0,0 @@
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)strings.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt STRINGS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strings
|
||||
.Nd find printable strings in a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl afo
|
||||
.Op Fl n Ar number
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility
|
||||
displays the sequences of printable characters in each of the specified
|
||||
files, or in the standard input, by default.
|
||||
By default, a sequence must be at least four characters in length
|
||||
before being displayed.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl a
|
||||
By default,
|
||||
.Nm
|
||||
only searches the text and data segments of object files.
|
||||
The
|
||||
.Fl a
|
||||
option causes
|
||||
.Nm
|
||||
to search the entire object file.
|
||||
.It Fl f
|
||||
Each string is preceded by the name of the file
|
||||
in which it was found.
|
||||
.It Fl n
|
||||
Specifies the minimum number of characters in a sequence to be
|
||||
.Ar number ,
|
||||
instead of four.
|
||||
.It Fl o
|
||||
Each string is preceded by its decimal offset in the
|
||||
file.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility is useful for identifying random binaries, among other things.
|
||||
.Sh SEE ALSO
|
||||
.Xr hexdump 1
|
||||
.Sh BUGS
|
||||
The algorithm for identifying strings is extremely primitive.
|
||||
In particular, machine code instructions on certain architectures
|
||||
can resemble sequences of ASCII bytes, which
|
||||
will fool the algorithm.
|
||||
.Sh COMPATIBILITY
|
||||
Historic implementations of
|
||||
.Nm
|
||||
only search the initialized data portion of the object file.
|
||||
This was reasonable as strings were normally stored there.
|
||||
Given new compiler technology which installs strings in the
|
||||
text portion of the object file, the default behavior was
|
||||
changed.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
@ -1,97 +0,0 @@
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)strings.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt STRINGS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strings
|
||||
.Nd find printable strings in a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl afo
|
||||
.Op Fl n Ar number
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
.Nm Strings
|
||||
displays the sequences of printable characters in each of the specified
|
||||
files, or in the standard input, by default.
|
||||
By default, a sequence must be at least four characters in length
|
||||
before being displayed.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl a
|
||||
By default,
|
||||
.Nm
|
||||
only searches the text and data segments of object files.
|
||||
The
|
||||
.Fl a
|
||||
option causes
|
||||
.Nm
|
||||
to search the entire object file.
|
||||
.It Fl f
|
||||
Each string is preceded by the name of the file
|
||||
in which it was found.
|
||||
.It Fl n
|
||||
Specifies the minimum number of characters in a sequence to be
|
||||
.Ar number ,
|
||||
instead of four.
|
||||
.It Fl o
|
||||
Each string is preceded by its decimal offset in the
|
||||
file.
|
||||
.El
|
||||
.Pp
|
||||
.Nm Strings
|
||||
is useful for identifying random binaries, among other things.
|
||||
.Sh SEE ALSO
|
||||
.Xr hexdump 1
|
||||
.Sh BUGS
|
||||
The algorithm for identifying strings is extremely primitive.
|
||||
In particular, machine code instructions on certain architectures
|
||||
can resemble sequences of ASCII bytes, which
|
||||
will fool the algorithm.
|
||||
.Sh COMPATIBILITY
|
||||
Historic implementations of
|
||||
.Nm
|
||||
only search the initialized data portion of the object file.
|
||||
This was reasonable as strings were normally stored there.
|
||||
Given new compiler technology which installs strings in the
|
||||
text portion of the object file, the default behavior was
|
||||
changed.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
@ -1,221 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1980, 1987, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1980, 1987, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strings.c 8.2 (Berkeley) 1/28/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <a.out.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEF_LEN 4 /* default minimum string length */
|
||||
#define ISSTR(ch) (isalnum(ch) || ispunct(ch) || \
|
||||
(isspace(ch) && (!iscntrl(ch) || ch == '\t')) || \
|
||||
(isascii(ch) && isprint(ch)))
|
||||
|
||||
typedef struct exec EXEC; /* struct exec cast */
|
||||
|
||||
static long foff; /* offset in the file */
|
||||
static int hcnt, /* head count */
|
||||
head_len, /* length of header */
|
||||
read_len; /* length to read */
|
||||
static u_char hbfr[sizeof(EXEC)]; /* buffer for struct exec */
|
||||
|
||||
int getch(void);
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int ch, cnt;
|
||||
register u_char *C;
|
||||
EXEC *head;
|
||||
int exitcode, minlen;
|
||||
short asdata, oflg, fflg;
|
||||
u_char *bfr;
|
||||
const char *file, *p;
|
||||
|
||||
(void) setlocale(LC_CTYPE, "");
|
||||
|
||||
/*
|
||||
* for backward compatibility, allow '-' to specify 'a' flag; no
|
||||
* longer documented in the man page or usage string.
|
||||
*/
|
||||
asdata = exitcode = fflg = oflg = 0;
|
||||
minlen = -1;
|
||||
while ((ch = getopt(argc, argv, "-0123456789an:of")) != -1)
|
||||
switch (ch) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
/*
|
||||
* kludge: strings was originally designed to take
|
||||
* a number after a dash.
|
||||
*/
|
||||
if (minlen == -1) {
|
||||
p = argv[optind - 1];
|
||||
if (p[0] == '-' && p[1] == ch && !p[2])
|
||||
minlen = atoi(++p);
|
||||
else
|
||||
minlen = atoi(argv[optind] + 1);
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
case 'a':
|
||||
asdata = 1;
|
||||
break;
|
||||
case 'f':
|
||||
fflg = 1;
|
||||
break;
|
||||
case 'n':
|
||||
minlen = atoi(optarg);
|
||||
break;
|
||||
case 'o':
|
||||
oflg = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (minlen == -1)
|
||||
minlen = DEF_LEN;
|
||||
else if (minlen < 1)
|
||||
errx(1, "length less than 1");
|
||||
|
||||
if (!(bfr = malloc((u_int)minlen + 1)))
|
||||
errx(1, "malloc");
|
||||
bfr[minlen] = '\0';
|
||||
file = "stdin";
|
||||
do {
|
||||
if (*argv) {
|
||||
file = *argv++;
|
||||
if (!freopen(file, "r", stdin)) {
|
||||
warn("%s", file);
|
||||
exitcode = 1;
|
||||
goto nextfile;
|
||||
}
|
||||
}
|
||||
foff = 0;
|
||||
#define DO_EVERYTHING() {read_len = -1; head_len = 0; goto start;}
|
||||
read_len = -1;
|
||||
if (asdata)
|
||||
DO_EVERYTHING()
|
||||
else {
|
||||
head = (EXEC *)hbfr;
|
||||
if ((head_len =
|
||||
read(fileno(stdin), head, sizeof(EXEC))) == -1)
|
||||
DO_EVERYTHING()
|
||||
if (head_len == sizeof(EXEC) && !N_BADMAG(*head)) {
|
||||
foff = N_TXTOFF(*head);
|
||||
if (fseek(stdin, foff, SEEK_SET) == -1)
|
||||
DO_EVERYTHING()
|
||||
read_len = head->a_text + head->a_data;
|
||||
head_len = 0;
|
||||
}
|
||||
else
|
||||
hcnt = 0;
|
||||
}
|
||||
start:
|
||||
for (cnt = 0; (ch = getch()) != EOF;) {
|
||||
if (ISSTR(ch)) {
|
||||
if (!cnt)
|
||||
C = bfr;
|
||||
*C++ = ch;
|
||||
if (++cnt < minlen)
|
||||
continue;
|
||||
if (fflg)
|
||||
printf("%s:", file);
|
||||
if (oflg)
|
||||
printf("%07ld %s",
|
||||
foff - minlen, (char *)bfr);
|
||||
else
|
||||
printf("%s", bfr);
|
||||
while ((ch = getch()) != EOF && ISSTR(ch))
|
||||
putchar((char)ch);
|
||||
putchar('\n');
|
||||
}
|
||||
cnt = 0;
|
||||
}
|
||||
nextfile: ;
|
||||
} while (*argv);
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
/*
|
||||
* getch --
|
||||
* get next character from wherever
|
||||
*/
|
||||
int
|
||||
getch()
|
||||
{
|
||||
++foff;
|
||||
if (head_len) {
|
||||
if (hcnt < head_len)
|
||||
return((int)hbfr[hcnt++]);
|
||||
head_len = 0;
|
||||
}
|
||||
if (read_len == -1 || read_len-- > 0)
|
||||
return(getchar());
|
||||
return(EOF);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: strings [-afo] [-n length] [file ... ]\n");
|
||||
exit(1);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= strip
|
||||
MAN= strip.1aout
|
||||
BINDIR= /usr/libexec/aout
|
||||
CLEANFILES += maybe_stripped
|
||||
|
||||
all: maybe_stripped
|
||||
|
||||
maybe_stripped: strip
|
||||
cp -p strip maybe_stripped
|
||||
.if defined(STRIP)
|
||||
.if ${STRIP:M-s} != ""
|
||||
-strip maybe_stripped
|
||||
.endif
|
||||
.endif
|
||||
|
||||
realinstall:
|
||||
${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
|
||||
maybe_stripped ${DESTDIR}${BINDIR}/strip
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,74 +0,0 @@
|
||||
.\" Copyright (c) 1989, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)strip.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt STRIP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strip
|
||||
.Nd remove unnecessary information from executable files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl d
|
||||
.Op Fl x
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility
|
||||
deletes the relocation information and symbol table used by
|
||||
assemblers, loaders and debuggers.
|
||||
This significantly
|
||||
decreases the size of the installed binaries and saves disk space.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d
|
||||
Delete only debugging and empty symbols.
|
||||
.It Fl x
|
||||
Delete only debugging, compiler identification, and local symbols.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility exits 0 on success and 1 if an error occurred.
|
||||
.Sh SEE ALSO
|
||||
.Xr cc 1 ,
|
||||
.Xr ld 1 ,
|
||||
.Xr stab 5
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
@ -1,73 +0,0 @@
|
||||
.\" Copyright (c) 1989, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
.\"
|
||||
.\" @(#)strip.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt STRIP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strip
|
||||
.Nd remove unnecessary information from executable files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl d
|
||||
.Op Fl x
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility
|
||||
deletes the relocation information and symbol table used by
|
||||
assemblers, loaders and debuggers.
|
||||
This significantly
|
||||
decreases the size of the installed binaries and saves disk space.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d
|
||||
Delete only debugging and empty symbols.
|
||||
.It Fl x
|
||||
Delete only debugging, compiler identification, and local symbols.
|
||||
.El
|
||||
.Pp
|
||||
.Nm Strip
|
||||
exits 0 on success and 1 if an error occurred.
|
||||
.Sh SEE ALSO
|
||||
.Xr cc 1 ,
|
||||
.Xr ld 1 ,
|
||||
.Xr stab 5
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
@ -1,266 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strip.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <a.out.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct exec EXEC;
|
||||
typedef struct nlist NLIST;
|
||||
|
||||
#define strx n_un.n_strx
|
||||
|
||||
void s_stab(const char *, int, EXEC *);
|
||||
void s_sym(const char *, int, EXEC *);
|
||||
static void usage(void);
|
||||
|
||||
int xflag = 0;
|
||||
int err_val = 0;
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int fd, nb;
|
||||
EXEC head;
|
||||
void (*sfcn)(const char *, int, EXEC *);
|
||||
int ch;
|
||||
char *fn;
|
||||
|
||||
sfcn = s_sym;
|
||||
while ((ch = getopt(argc, argv, "dx")) != -1)
|
||||
switch(ch) {
|
||||
case 'x':
|
||||
xflag = 1;
|
||||
/*FALLTHROUGH*/
|
||||
case 'd':
|
||||
sfcn = s_stab;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
while ((fn = *argv++) != NULL) {
|
||||
if ((fd = open(fn, O_RDWR)) < 0 ||
|
||||
(nb = read(fd, &head, sizeof(EXEC))) == -1) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
if (fd >= 0 && close(fd)) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (nb != sizeof(EXEC) || N_BADMAG(head)) {
|
||||
warnx("%s: %s", fn, strerror(EFTYPE));
|
||||
err_val = 1;
|
||||
if (close(fd)) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
sfcn(fn, fd, &head);
|
||||
if (close(fd)) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
}
|
||||
}
|
||||
exit(err_val);
|
||||
}
|
||||
|
||||
void
|
||||
s_sym(fn, fd, ep)
|
||||
const char *fn;
|
||||
int fd;
|
||||
register EXEC *ep;
|
||||
{
|
||||
register off_t fsize;
|
||||
|
||||
/* If no symbols or data/text relocation info, quit. */
|
||||
if (!ep->a_syms && !ep->a_trsize && !ep->a_drsize)
|
||||
return;
|
||||
|
||||
/*
|
||||
* New file size is the header plus text and data segments.
|
||||
*/
|
||||
fsize = N_DATOFF(*ep) + ep->a_data;
|
||||
|
||||
/* Set symbol size and relocation info values to 0. */
|
||||
ep->a_syms = ep->a_trsize = ep->a_drsize = 0;
|
||||
|
||||
/* Rewrite the header and truncate the file. */
|
||||
if (lseek(fd, (off_t)0, SEEK_SET) == -1 ||
|
||||
write(fd, ep, sizeof(EXEC)) != sizeof(EXEC) ||
|
||||
ftruncate(fd, fsize)) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
s_stab(fn, fd, ep)
|
||||
const char *fn;
|
||||
int fd;
|
||||
EXEC *ep;
|
||||
{
|
||||
register int cnt, len;
|
||||
register char *nstr, *nstrbase, *p, *strbase;
|
||||
register NLIST *sym, *nsym;
|
||||
struct stat sb;
|
||||
NLIST *symbase;
|
||||
|
||||
/* Quit if no symbols. */
|
||||
if (ep->a_syms == 0)
|
||||
return;
|
||||
|
||||
/* Stat the file. */
|
||||
if (fstat(fd, &sb) < 0) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check size. */
|
||||
if (sb.st_size > SIZE_T_MAX) {
|
||||
warnx("%s: %s", fn, strerror(EFBIG));
|
||||
err_val = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Map the file. */
|
||||
if ((ep = (EXEC *)mmap(NULL, (size_t)sb.st_size,
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0)) == (EXEC *)MAP_FAILED) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize old and new symbol pointers. They both point to the
|
||||
* beginning of the symbol table in memory, since we're deleting
|
||||
* entries.
|
||||
*/
|
||||
sym = nsym = symbase = (NLIST *)((char *)ep + N_SYMOFF(*ep));
|
||||
|
||||
/*
|
||||
* Allocate space for the new string table, initialize old and
|
||||
* new string pointers. Handle the extra long at the beginning
|
||||
* of the string table.
|
||||
*/
|
||||
strbase = (char *)ep + N_STROFF(*ep);
|
||||
if ((nstrbase = malloc((size_t)*(u_long *)strbase)) == NULL) {
|
||||
warn(NULL);
|
||||
err_val = 1;
|
||||
munmap((caddr_t)ep, sb.st_size);
|
||||
return;
|
||||
}
|
||||
nstr = nstrbase + sizeof(u_long);
|
||||
|
||||
/*
|
||||
* Read through the symbol table. For each non-debugging symbol,
|
||||
* copy it and save its string in the new string table. Keep
|
||||
* track of the number of symbols.
|
||||
*/
|
||||
for (cnt = ep->a_syms / sizeof(NLIST); cnt--; ++sym)
|
||||
if (!(sym->n_type & N_STAB) && sym->strx) {
|
||||
*nsym = *sym;
|
||||
nsym->strx = nstr - nstrbase;
|
||||
p = strbase + sym->strx;
|
||||
if (xflag &&
|
||||
(!(sym->n_type & N_EXT) ||
|
||||
(sym->n_type & ~N_EXT) == N_FN ||
|
||||
strcmp(p, "gcc_compiled.") == 0 ||
|
||||
strcmp(p, "gcc2_compiled.") == 0 ||
|
||||
strcmp(p, "___gnu_compiled_c") == 0))
|
||||
continue;
|
||||
len = strlen(p) + 1;
|
||||
bcopy(p, nstr, len);
|
||||
nstr += len;
|
||||
++nsym;
|
||||
}
|
||||
|
||||
/* Fill in new symbol table size. */
|
||||
ep->a_syms = (nsym - symbase) * sizeof(NLIST);
|
||||
|
||||
/* Fill in the new size of the string table. */
|
||||
*(u_long *)nstrbase = len = nstr - nstrbase;
|
||||
|
||||
/*
|
||||
* Copy the new string table into place. Nsym should be pointing
|
||||
* at the address past the last symbol entry.
|
||||
*/
|
||||
bcopy(nstrbase, (void *)nsym, len);
|
||||
|
||||
/* Truncate to the current length. */
|
||||
if (ftruncate(fd, (char *)nsym + len - (char *)ep)) {
|
||||
warn("%s", fn);
|
||||
err_val = 1;
|
||||
}
|
||||
munmap((caddr_t)ep, (size_t)sb.st_size);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: strip [-dx] file ...\n");
|
||||
exit(1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user