Annotation of src/usr.bin/ranlib/touch.c, Revision 1.6
1.6 ! deraadt 1: /* $OpenBSD: touch.c,v 1.5 2003/06/03 02:56:14 millert Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: /*-
4: * Copyright (c) 1990 The Regents of the University of California.
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Hugh Smith at The University of Guelph.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
1.5 millert 18: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 19: * may be used to endorse or promote products derived from this software
20: * without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32: * SUCH DAMAGE.
33: */
34:
35: #ifndef lint
36: /*static char sccsid[] = "from: @(#)touch.c 5.3 (Berkeley) 3/12/91";*/
1.6 ! deraadt 37: static char rcsid[] = "$OpenBSD: touch.c,v 1.5 2003/06/03 02:56:14 millert Exp $";
1.1 deraadt 38: #endif /* not lint */
39:
40: #include <sys/types.h>
41: #include <fcntl.h>
42: #include <dirent.h>
43: #include <ranlib.h>
44: #include <ar.h>
45: #include <time.h>
46: #include <unistd.h>
47: #include <stdio.h>
48: #include <string.h>
49: #include <archive.h>
1.3 espie 50: #include "extern.h"
1.1 deraadt 51:
52: extern CHDR chdr; /* converted header */
53:
1.3 espie 54: int
1.6 ! deraadt 55: touch(void)
1.1 deraadt 56: {
57: int afd;
58:
59: afd = open_archive(O_RDWR);
60:
61: if (!get_arobj(afd) ||
62: strncmp(RANLIBMAG, chdr.name, sizeof(RANLIBMAG) - 1)) {
63: (void)fprintf(stderr,
64: "ranlib: %s: no symbol table.\n", archive);
65: return(1);
66: }
67: settime(afd);
68: close_archive(afd);
69: return(0);
70: }
71:
1.3 espie 72: void
1.6 ! deraadt 73: settime(int afd)
1.1 deraadt 74: {
75: struct ar_hdr *hdr;
76: off_t size;
77: char buf[50];
78:
79: size = SARMAG + sizeof(hdr->ar_name);
80: if (lseek(afd, size, SEEK_SET) == (off_t)-1)
81: error(archive);
1.4 deraadt 82: (void)snprintf(buf, sizeof buf,
83: "%-12ld", (long int)time((time_t *)NULL) + RANLIBSKEW);
1.1 deraadt 84: if (write(afd, buf, sizeof(hdr->ar_date)) != sizeof(hdr->ar_date))
85: error(archive);
86: }