prettyness police
[unix-history] / usr / src / usr.bin / ar / contents.c
CommitLineData
d7a7b86b 1/*-
4e6c9859
KB
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
d7a7b86b
KB
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
706c0358 12static char sccsid[] = "@(#)contents.c 8.2 (Berkeley) %G%";
d7a7b86b
KB
13#endif /* not lint */
14
15#include <sys/param.h>
16#include <sys/stat.h>
17#include <sys/time.h>
706c0358 18
d7a7b86b 19#include <ar.h>
706c0358
JSP
20#include <dirent.h>
21#include <fcntl.h>
40b136c0
KB
22#include <stdio.h>
23#include <string.h>
706c0358
JSP
24#include <tzfile.h>
25#include <unistd.h>
26
d7a7b86b 27#include "archive.h"
40b136c0 28#include "extern.h"
d7a7b86b 29
d7a7b86b
KB
30/*
31 * contents --
32 * Handles t[v] option - opens the archive and then reads headers,
44c5e2d6 33 * skipping member contents.
d7a7b86b 34 */
706c0358 35int
d7a7b86b 36contents(argv)
706c0358 37 char **argv;
d7a7b86b 38{
706c0358 39 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);
21684c31 52 (void)printf("%s %6d/%-6d %8qd ",
af52bb8a
KB
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);
706c0358 67 return (1);
40b136c0 68 }
706c0358 69 return (0);
d7a7b86b 70}