xref: /csrg-svn/usr.bin/ranlib/touch.c (revision 62197)
146016Sbostic /*-
2*62197Sbostic  * Copyright (c) 1990, 1993
3*62197Sbostic  *	The Regents of the University of California.  All rights reserved.
446016Sbostic  *
546016Sbostic  * This code is derived from software contributed to Berkeley by
646016Sbostic  * Hugh Smith at The University of Guelph.
746016Sbostic  *
846016Sbostic  * %sccs.include.redist.c%
946016Sbostic  */
1046016Sbostic 
1146016Sbostic #ifndef lint
12*62197Sbostic static char sccsid[] = "@(#)touch.c	8.1 (Berkeley) 06/06/93";
1346016Sbostic #endif /* not lint */
1446016Sbostic 
1546016Sbostic #include <sys/types.h>
1646016Sbostic #include <fcntl.h>
1746016Sbostic #include <dirent.h>
1846016Sbostic #include <ranlib.h>
1946016Sbostic #include <ar.h>
2046698Sbostic #include <time.h>
2146698Sbostic #include <unistd.h>
2246016Sbostic #include <stdio.h>
2346698Sbostic #include <string.h>
2446016Sbostic #include <archive.h>
2546016Sbostic 
2646016Sbostic extern CHDR chdr;			/* converted header */
2746016Sbostic extern char *archive;			/* archive name */
2846016Sbostic 
touch()2946016Sbostic touch()
3046016Sbostic {
3146016Sbostic 	int afd;
3246016Sbostic 
3346016Sbostic 	afd = open_archive(O_RDWR);
3446016Sbostic 
3547241Sbostic 	if (!get_arobj(afd) ||
3646016Sbostic 	    strncmp(RANLIBMAG, chdr.name, sizeof(RANLIBMAG) - 1)) {
3746016Sbostic 		(void)fprintf(stderr,
3846016Sbostic 		    "ranlib: %s: no symbol table.\n", archive);
3946016Sbostic 		return(1);
4046016Sbostic 	}
4146016Sbostic 	settime(afd);
4246016Sbostic 	return(0);
4346016Sbostic }
4446016Sbostic 
settime(afd)4546016Sbostic settime(afd)
4646016Sbostic 	int afd;
4746016Sbostic {
4846016Sbostic 	struct ar_hdr *hdr;
4946016Sbostic 	off_t size;
5046016Sbostic 	char buf[50];
5146016Sbostic 
5246016Sbostic 	size = SARMAG + sizeof(hdr->ar_name);
5346016Sbostic 	if (lseek(afd, size, SEEK_SET) == (off_t)-1)
5446016Sbostic 		error(archive);
5546016Sbostic 	(void)sprintf(buf, "%-12ld", time((time_t *)NULL) + RANLIBSKEW);
5646016Sbostic 	if (write(afd, buf, sizeof(hdr->ar_date)) != sizeof(hdr->ar_date))
5746016Sbostic 		error(archive);
5846016Sbostic }
59