fold header.c into archive.c
[unix-history] / usr / src / usr.bin / ar / ar.5.5
CommitLineData
d883e586
KB
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\" @(#)ar.5.5 6.2 (Berkeley) %G%
6e5bb952 7.\"
6592a7dc 8.TH AR 5 ""
6e5bb952
KM
9.AT 3
10.SH NAME
11ar \- archive (library) file format
12.SH SYNOPSIS
13.B #include <ar.h>
14.SH DESCRIPTION
6e5bb952
KM
15.PP
16The archive command
d883e586 17.IR ar
f4258d08 18combines several files into one.
d883e586
KB
19Archives are mainly used as libraries of object files intended to be
20loaded using the link-editor
21.IR ld (1).
6e5bb952 22.PP
d883e586 23A file created with
6e5bb952 24.I ar
d883e586
KB
25begins with the ``magic'' string "!<arch>\en".
26The rest of the archive is made up of objects, each of which is composed
27of a header for a file, a possible file name, and the file contents.
28The header is portable between machine architectures, and, if the file
29contents are printable, the archive is itself printable.
30.PP
31The header is made up of six variable length ASCII fields, followed by a
32two character trailer.
33The fields are the object name (16 characters), the file last modification
34time (12 characters), the user and group id's (each 6 characters), the file
35mode (8 characters) and the file size (10 characters).
36All numeric fields are in decimal, except for the file mode which is in
37octal.
38.PP
39The modification time is the file st_mtime field, i.e., CUT seconds since
40the epoch.
41The user and group id's are the file st_uid and st_gid fields.
42The file mode is the file st_mode field.
43The file size is the file st_size field.
44The two-byte trailer is the string "\`\en".
45.PP
46Only the name field has any provision for overflow.
47If any file name is more than 16 characters in length or contains an
48embedded space, the string "#1/" followed by the ASCII length of the
49name is written in the name field.
50The file size (stored in the archive header) is incremented by the length
51of the name.
52The name is then written immediately following the archive header.
53.PP
54Any unused characters in any of these fields are written as space
55characters.
56If any fields are their particular maximum number of characters in
57length, there will be no separation between the fields.
58.PP
59Objects in the archive are always an even number of bytes long; files
60which are an odd number of bytes long are padded with a newline (``\en'')
61character, although the size in the header does not reflect this.
6e5bb952 62.SH "SEE ALSO"
d883e586
KB
63ar(1), stat(2)
64.SH HISTORY
65There have been at least four
66.I ar
67formats.
68The first was denoted by the leading ``magic'' number 0177555 (stored as
69type int).
70These archives were almost certainly created on a 16-bit machine, and
71contain headers made up of five fields.
72The fields are the object name (8 characters), the file last modification
73time (type long), the user id (type char), the file mode (type char) and
74the file size (type unsigned int).
75Files were padded to an even number of bytes.
76.PP
77The second was denoted by the leading ``magic'' number 0177545 (stored as
78type int).
79These archives may have been created on either 16 or 32-bit machines, and
80contain headers made up of six fields.
81The fields are the object name (14 characters), the file last modification
82time (type long), the user and group id's (each type char), the file mode
83(type int) and the file size (type long).
84Files were padded to an even number of bytes.
85For more information on converting from this format see
86.IR arcv (8).
87.PP
88The current archive format (without support for long character names and
89names with embedded spaces) was introduced in 4.0BSD.
90The headers were the same as the current format, with the exception that
91names longer than 16 characters were truncated, and names with embedded
92spaces (and often trailing spaces) were not supported.
93It was extended for these reasons in 4.4BSD, as described above.
94.SH COMPATIBILITY
95No archive format is currently specified by any standard.
96System V has historically distributed archives in a different format from
97all of the above.