make archive routine naming consistent
[unix-history] / usr / src / usr.bin / ar / contents.c
CommitLineData
d7a7b86b
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * 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
ce478bb7 12static char sccsid[] = "@(#)contents.c 5.6 (Berkeley) %G%";
d7a7b86b
KB
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>
d7a7b86b 22#include <ar.h>
40b136c0
KB
23#include <stdio.h>
24#include <string.h>
d7a7b86b 25#include "archive.h"
40b136c0 26#include "extern.h"
d7a7b86b
KB
27
28extern CHDR chdr; /* converted header */
29extern char *archive; /* archive name */
30
31/*
32 * contents --
33 * Handles t[v] option - opens the archive and then reads headers,
44c5e2d6 34 * skipping member contents.
d7a7b86b
KB
35 */
36contents(argv)
37 register char **argv;
38{
39 register int afd, all;
d7a7b86b 40 struct tm *tp;
af52bb8a 41 char *file, buf[25];
d7a7b86b
KB
42
43 afd = open_archive(O_RDONLY);
44
ce478bb7 45 for (all = !*argv; get_arobj(afd);) {
af52bb8a
KB
46 if (all)
47 file = chdr.name;
40b136c0
KB
48 else if (!(file = files(argv)))
49 goto next;
af52bb8a
KB
50 if (options & AR_V) {
51 (void)strmode(chdr.mode, buf);
52 (void)printf("%s %6d/%-6d %8ld ",
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;
ce478bb7 61next: skip_arobj(afd);
d7a7b86b 62 }
d7a7b86b 63 close_archive(afd);
40b136c0
KB
64
65 if (*argv) {
66 orphans(argv);
67 return(1);
68 }
69 return(0);
d7a7b86b 70}