xref: /original-bsd/usr.bin/ar/contents.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Hugh Smith at The University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)contents.c	8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14 
15 #include <sys/param.h>
16 #include <sys/stat.h>
17 #include <sys/time.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <tzfile.h>
21 #include <dirent.h>
22 #include <ar.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include "archive.h"
26 #include "extern.h"
27 
28 extern CHDR chdr;			/* converted header */
29 extern char *archive;			/* archive name */
30 
31 /*
32  * contents --
33  *	Handles t[v] option - opens the archive and then reads headers,
34  *	skipping member contents.
35  */
36 contents(argv)
37 	register char **argv;
38 {
39 	register int afd, all;
40 	struct tm *tp;
41 	char *file, buf[25];
42 
43 	afd = open_archive(O_RDONLY);
44 
45 	for (all = !*argv; get_arobj(afd);) {
46 		if (all)
47 			file = chdr.name;
48 		else if (!(file = files(argv)))
49 			goto next;
50 		if (options & AR_V) {
51 			(void)strmode(chdr.mode, buf);
52 			(void)printf("%s %6d/%-6d %8qd ",
53 			    buf + 1, chdr.uid, chdr.gid, chdr.size);
54 			tp = localtime(&chdr.date);
55 			(void)strftime(buf, sizeof(buf), "%b %e %H:%M %Y", tp);
56 			(void)printf("%s %s\n", buf, file);
57 		} else
58 			(void)printf("%s\n", file);
59 		if (!all && !*argv)
60 			break;
61 next:		skip_arobj(afd);
62 	}
63 	close_archive(afd);
64 
65 	if (*argv) {
66 		orphans(argv);
67 		return(1);
68 	}
69 	return(0);
70 }
71