xref: /original-bsd/usr.bin/ar/contents.c (revision e58c8952)
1 /*-
2  * Copyright (c) 1990, 1993, 1994
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.3 (Berkeley) 04/02/94";
13 #endif /* not lint */
14 
15 #include <sys/param.h>
16 #include <sys/stat.h>
17 #include <sys/time.h>
18 
19 #include <ar.h>
20 #include <dirent.h>
21 #include <fcntl.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <tzfile.h>
25 #include <unistd.h>
26 
27 #include "archive.h"
28 #include "extern.h"
29 
30 /*
31  * contents --
32  *	Handles t[v] option - opens the archive and then reads headers,
33  *	skipping member contents.
34  */
35 int
36 contents(argv)
37 	char **argv;
38 {
39 	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