summaryrefslogtreecommitdiffstats
path: root/usr.bin/ar
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-07-06 06:54:14 +0000
committerbde <bde@FreeBSD.org>1997-07-06 06:54:14 +0000
commit4d7f45e2595cdda6921d9ed62f7ce9ba08453d13 (patch)
tree8a1e564deb1b54debb4947f8ee448223b4ef4fb3 /usr.bin/ar
parente9b5b21c359ab94dbe38c62aa507bd29c30d295c (diff)
downloadFreeBSD-src-4d7f45e2595cdda6921d9ed62f7ce9ba08453d13.zip
FreeBSD-src-4d7f45e2595cdda6921d9ed62f7ce9ba08453d13.tar.gz
Finish importing Lite2's src/usr.bin, except for ex, diff, grep, mail,
pascal and vmstat.sparc. All changed files on the vendor branch should already have been imported.
Diffstat (limited to 'usr.bin/ar')
-rw-r--r--usr.bin/ar/ar.1281
-rw-r--r--usr.bin/ar/ar.5.5146
-rw-r--r--usr.bin/ar/archive.c7
-rw-r--r--usr.bin/ar/misc.c7
-rw-r--r--usr.bin/ar/replace.c6
5 files changed, 330 insertions, 117 deletions
diff --git a/usr.bin/ar/ar.1 b/usr.bin/ar/ar.1
index 026aed6..fd5ce4f 100644
--- a/usr.bin/ar/ar.1
+++ b/usr.bin/ar/ar.1
@@ -32,119 +32,157 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ar.1 8.1 (Berkeley) 6/29/93
+.\" @(#)ar.1 8.4 (Berkeley) 4/28/95
.\"
-.TH AR 1 "June 29, 1993"
-.AT 3
-.SH NAME
-ar \- create and maintain library archives
-.SH SYNOPSIS
-.nf
-.ft B
-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 ...]
-.fi
-.ft R
-.SH DESCRIPTION
+.Dd "April 28, 1995"
+.Dt AR 1
+.Os
+.Sh NAME
+.Nm ar
+.Nd create and maintain library archives
+.Sh SYNOPSIS
+.Nm ar
+.Fl d
+.Op Fl \Tv
+.Ar archive file ...
+.Nm ar
+.Fl m
+.Op Fl \Tv
+.Ar archive file ...
+.Nm ar
+.Fl m
+.Op Fl abiTv
+.Ar position archive file ...
+.Nm ar
+.Fl p
+.Op Fl \Tv
+.Ar archive
+.Op Ar file ...
+.Nm ar
+.Fl q
+.Op Fl cTv
+.Ar archive file ...
+.Nm ar
+.Fl r
+.Op Fl cuTv
+.Ar archive file ...
+.Nm ar
+.Fl r
+.Op Fl abciuTv
+.Ar position archive file ...
+.Nm ar
+.Fl t
+.Op Fl \Tv
+.Ar archive
+.Op Ar file ...
+.Nm ar
+.Fl x
+.Op Fl ouTv
+.Ar archive
+.Op Ar file ...
+.Sh DESCRIPTION
The
-.I ar
+.Nm ar
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
+.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
+.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
-.B first
+.Em first
file with a matching name will be selected.
-.PP
+.Pp
The normal use of
-.I ar
+.Nm ar
is for the creation and maintenance of libraries suitable for use with
the loader (see
-.IR ld (1)),
+.Xr ld 1 ),
although it is not restricted to this purpose.
The options are as follows:
-.TP
-\-a
-A positioning modifier used with the options \-r and \-m.
+.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
-.B after
+.Em after
the archive member
-.IR position ,
+.Ar position ,
which must be specified.
-.TP
-\-b
-A positioning modifier used with the options \-r and \-m.
+.It Fl b
+A positioning modifier used with the options
+.Fl r
+and
+.Fl m .
The files are entered or moved
-.B before
+.Em before
the archive member
-.IR position ,
+.Ar position ,
which must be specified.
-.TP
-\-c
+.It Fl c
Whenever an archive is created, an informational message to that effect
is written to standard error.
-If the \-c option is specified,
-.I ar
+If the
+.Fl c
+option is specified,
+.Nm ar
creates the archive silently.
-.TP
-\-d
+.It Fl d
Delete the specified archive files.
-.TP
-\-i
-Identical to the \-b option.
-.TP
-\-m
+.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 \-a, \-b or \-i is specified, the files are moved
-before or after the
-.I position
+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.
-.TP
-\-o
+.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.
-.TP
-\-p
+.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.
-.TP
-\-q
+.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 \-r option, when creating a large archive
+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.
-.TP
-\-r
+.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 \-a, \-b
-or \-i is specified.
-.TP
-\-T
+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
@@ -155,103 +193,128 @@ characters can subsequently be confused.
A warning message is printed to the standard error output if any file
names are truncated.
(See
-.IR ar (5)
+.Xr ar 5
for more information.)
-.TP
-\-t
+.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.
-.TP
-\-u
+.It Fl u
Update files.
-When used with the \-r option, files in the archive will be replaced
+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 \-x option, files in the archive will be extracted
+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.
-.TP
-\-v
+.It Fl v
Provide verbose output.
-When used with the \-d, \-m, \-q or \-x options,
-.I ar
+When used with the
+.Fl d ,
+.Fl m ,
+.Fl q
+or
+.Fl x
+options,
+.Nm ar
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 \-r option,
-.I ar
+When used with the
+.Fl r
+option,
+.Nm ar
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.
-.IP
-When used with the \-p option,
+.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.
-.IP
-When used with the \-t option,
-.I ar
+.Pp
+When used with the
+.Fl t
+option,
+.Nm ar
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
-.IR strmode (3)),
+.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
-.IR date (1)
+.Xr date 1
format ``%b %e %H:%M %Y''), and the name of the file.
-.TP
-\-x
+.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.
-.IP
+.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 \-o option).
+(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.
-.PP
+.El
+.Pp
The
-.I ar
+.Nm ar
utility exits 0 on success, and >0 if an error occurs.
-.SH ENVIRONMENT
-.TP
-TMPDIR
+.Sh ENVIRONMENT
+.Bl -tag -width indent -compact
+.It Ev TMPDIR
The pathname of the directory to use when creating temporary files.
-.SH FILES
-.TP 14
-/tmp
+.El
+.Sh FILES
+.Bl -tag -width indent -compact
+.It Pa /tmp
default temporary file directory
-.TP 14
-ar.XXXXXX
+.It Pa ar.XXXXXX
temporary file names
-.SH COMPATIBILITY
+.El
+.Sh COMPATIBILITY
By default,
-.I ar
+.Nm ar
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
-.I ar
+.Nm ar
is backward compatible with previous versions of
-.I ar
-in that it can read and write (using the \-T option) historic archives.
-The \-T option is provided for compatibility only, and will be deleted
+.Nm ar
+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
-.IR ar (5)
+.Xr ar 5
for more information.
.SH STANDARDS
The
-.I ar
-utility is expected to offer a superset of the POSIX 1003.2 functionality.
-.SH "SEE ALSO"
-ld(1), ranlib(1), strmode(3), ar(5)
+.Nm ar
+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
diff --git a/usr.bin/ar/ar.5.5 b/usr.bin/ar/ar.5.5
new file mode 100644
index 0000000..2ab5b2d
--- /dev/null
+++ b/usr.bin/ar/ar.5.5
@@ -0,0 +1,146 @@
+.\" 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.2 (Berkeley) 6/1/94
+.\"
+.Dd June 1, 1994
+.Dt AR 5
+.Os
+.Sh NAME
+.Nm ar
+.Nd archive (library) file format
+.Sh SYNOPSIS
+.Fd #include <ar.h>
+.Sh DESCRIPTION
+The archive command
+.Nm ar
+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 ar
+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 ar
+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 .
+.ne 1i
+.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 4.4BSD.
+.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.
diff --git a/usr.bin/ar/archive.c b/usr.bin/ar/archive.c
index 10897d9..9dd6b20 100644
--- a/usr.bin/ar/archive.c
+++ b/usr.bin/ar/archive.c
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)archive.c 8.3 (Berkeley) 4/2/94";
+static char sccsid[] = "@(#)archive.c 8.4 (Berkeley) 4/27/95";
#endif /* not lint */
#include <sys/param.h>
@@ -221,7 +221,7 @@ put_arobj(cfp, sb)
if (options & AR_TR) {
if (lname > OLDARMAXNAME) {
(void)fflush(stdout);
- warnx("warning: %s truncated to %.*s\n",
+ warnx("warning: %s truncated to %.*s",
name, OLDARMAXNAME, name);
(void)fflush(stderr);
}
@@ -299,7 +299,8 @@ copy_ar(cfp, size)
error(cfp->rname);
}
- if (cfp->flags & RPAD && size & 1 && (nr = read(from, buf, 1)) != 1) {
+ if (cfp->flags & RPAD && (size + chdr.lname) & 1 &&
+ (nr = read(from, buf, 1)) != 1) {
if (nr == 0)
badfmt();
error(cfp->rname);
diff --git a/usr.bin/ar/misc.c b/usr.bin/ar/misc.c
index d182fa9..f9c0d14 100644
--- a/usr.bin/ar/misc.c
+++ b/usr.bin/ar/misc.c
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
+static char sccsid[] = "@(#)misc.c 8.4 (Berkeley) 4/27/95";
#endif /* not lint */
#include <sys/param.h>
@@ -136,7 +136,8 @@ void
badfmt()
{
- errx(1, "%s: %s", archive, strerror(EFTYPE));
+ errno = EFTYPE;
+ err(1, "%s", archive);
}
void
@@ -144,5 +145,5 @@ error(name)
char *name;
{
- errx(1, "%s", name);
+ err(1, "%s", name);
}
diff --git a/usr.bin/ar/replace.c b/usr.bin/ar/replace.c
index cc12781..4500b90 100644
--- a/usr.bin/ar/replace.c
+++ b/usr.bin/ar/replace.c
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)replace.c 8.3 (Berkeley) 4/2/94";
+static char sccsid[] = "@(#)replace.c 8.4 (Berkeley) 4/27/95";
#endif /* not lint */
#include <sys/param.h>
@@ -102,8 +102,10 @@ replace(argv)
goto useold;
}
(void)fstat(sfd, &sb);
- if (options & AR_U && sb.st_mtime <= chdr.date)
+ if (options & AR_U && sb.st_mtime <= chdr.date) {
+ (void)close(sfd);
goto useold;
+ }
if (options & AR_V)
(void)printf("r - %s\n", file);
OpenPOWER on IntegriCloud