add -N and -M
[unix-history] / usr / src / usr.bin / ranlib / touch.c
CommitLineData
d2ce791e
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
f10e4796 12static char sccsid[] = "@(#)touch.c 5.3 (Berkeley) %G%";
d2ce791e
KB
13#endif /* not lint */
14
15#include <sys/types.h>
16#include <fcntl.h>
d2ce791e
KB
17#include <dirent.h>
18#include <ranlib.h>
19#include <ar.h>
d6db39e0
KB
20#include <time.h>
21#include <unistd.h>
d2ce791e 22#include <stdio.h>
d6db39e0 23#include <string.h>
d2ce791e 24#include <archive.h>
d2ce791e
KB
25
26extern CHDR chdr; /* converted header */
27extern char *archive; /* archive name */
28
29touch()
30{
31 int afd;
32
33 afd = open_archive(O_RDWR);
34
f10e4796 35 if (!get_arobj(afd) ||
d2ce791e
KB
36 strncmp(RANLIBMAG, chdr.name, sizeof(RANLIBMAG) - 1)) {
37 (void)fprintf(stderr,
38 "ranlib: %s: no symbol table.\n", archive);
39 return(1);
40 }
41 settime(afd);
42 return(0);
43}
44
45settime(afd)
46 int afd;
47{
48 struct ar_hdr *hdr;
49 off_t size;
50 char buf[50];
51
52 size = SARMAG + sizeof(hdr->ar_name);
53 if (lseek(afd, size, SEEK_SET) == (off_t)-1)
54 error(archive);
55 (void)sprintf(buf, "%-12ld", time((time_t *)NULL) + RANLIBSKEW);
56 if (write(afd, buf, sizeof(hdr->ar_date)) != sizeof(hdr->ar_date))
57 error(archive);
58}