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