1*46016Sbostic /*- 2*46016Sbostic * Copyright (c) 1990 The Regents of the University of California. 3*46016Sbostic * All rights reserved. 4*46016Sbostic * 5*46016Sbostic * This code is derived from software contributed to Berkeley by 6*46016Sbostic * Hugh Smith at The University of Guelph. 7*46016Sbostic * 8*46016Sbostic * %sccs.include.redist.c% 9*46016Sbostic */ 10*46016Sbostic 11*46016Sbostic #ifndef lint 12*46016Sbostic static char sccsid[] = "@(#)touch.c 5.1 (Berkeley) 01/18/91"; 13*46016Sbostic #endif /* not lint */ 14*46016Sbostic 15*46016Sbostic #include <sys/types.h> 16*46016Sbostic #include <fcntl.h> 17*46016Sbostic #include <unistd.h> 18*46016Sbostic #include <dirent.h> 19*46016Sbostic #include <ranlib.h> 20*46016Sbostic #include <ar.h> 21*46016Sbostic #include <stdio.h> 22*46016Sbostic #include <archive.h> 23*46016Sbostic #include <time.h> 24*46016Sbostic 25*46016Sbostic extern CHDR chdr; /* converted header */ 26*46016Sbostic extern char *archive; /* archive name */ 27*46016Sbostic 28*46016Sbostic touch() 29*46016Sbostic { 30*46016Sbostic int afd; 31*46016Sbostic 32*46016Sbostic afd = open_archive(O_RDWR); 33*46016Sbostic 34*46016Sbostic if (!get_header(afd) || 35*46016Sbostic strncmp(RANLIBMAG, chdr.name, sizeof(RANLIBMAG) - 1)) { 36*46016Sbostic (void)fprintf(stderr, 37*46016Sbostic "ranlib: %s: no symbol table.\n", archive); 38*46016Sbostic return(1); 39*46016Sbostic } 40*46016Sbostic settime(afd); 41*46016Sbostic return(0); 42*46016Sbostic } 43*46016Sbostic 44*46016Sbostic settime(afd) 45*46016Sbostic int afd; 46*46016Sbostic { 47*46016Sbostic struct ar_hdr *hdr; 48*46016Sbostic off_t size; 49*46016Sbostic char buf[50]; 50*46016Sbostic 51*46016Sbostic size = SARMAG + sizeof(hdr->ar_name); 52*46016Sbostic if (lseek(afd, size, SEEK_SET) == (off_t)-1) 53*46016Sbostic error(archive); 54*46016Sbostic (void)sprintf(buf, "%-12ld", time((time_t *)NULL) + RANLIBSKEW); 55*46016Sbostic if (write(afd, buf, sizeof(hdr->ar_date)) != sizeof(hdr->ar_date)) 56*46016Sbostic error(archive); 57*46016Sbostic } 58