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.3 (Berkeley) 03/12/91"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 #include <fcntl.h> 17 #include <dirent.h> 18 #include <ranlib.h> 19 #include <ar.h> 20 #include <time.h> 21 #include <unistd.h> 22 #include <stdio.h> 23 #include <string.h> 24 #include <archive.h> 25 26 extern CHDR chdr; /* converted header */ 27 extern char *archive; /* archive name */ 28 29 touch() 30 { 31 int afd; 32 33 afd = open_archive(O_RDWR); 34 35 if (!get_arobj(afd) || 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 45 settime(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 } 59