[BACK]Return to touch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ranlib

Annotation of src/usr.bin/ranlib/touch.c, Revision 1.9

1.9     ! deraadt     1: /*     $OpenBSD: touch.c,v 1.8 2013/04/02 04:58:54 deraadt 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: #include <sys/types.h>
                     36: #include <fcntl.h>
                     37: #include <dirent.h>
                     38: #include <ranlib.h>
                     39: #include <ar.h>
                     40: #include <time.h>
                     41: #include <unistd.h>
                     42: #include <stdio.h>
                     43: #include <string.h>
                     44: #include <archive.h>
1.3       espie      45: #include "extern.h"
1.1       deraadt    46:
                     47: extern CHDR chdr;                      /* converted header */
                     48:
1.3       espie      49: int
1.6       deraadt    50: touch(void)
1.1       deraadt    51: {
                     52:        int afd;
                     53:
                     54:        afd = open_archive(O_RDWR);
                     55:
                     56:        if (!get_arobj(afd) ||
                     57:            strncmp(RANLIBMAG, chdr.name, sizeof(RANLIBMAG) - 1)) {
                     58:                (void)fprintf(stderr,
                     59:                    "ranlib: %s: no symbol table.\n", archive);
                     60:                return(1);
                     61:        }
                     62:        settime(afd);
                     63:        close_archive(afd);
                     64:        return(0);
                     65: }
                     66:
1.3       espie      67: void
1.6       deraadt    68: settime(int afd)
1.1       deraadt    69: {
                     70:        struct ar_hdr *hdr;
                     71:        off_t size;
                     72:        char buf[50];
                     73:
                     74:        size = SARMAG + sizeof(hdr->ar_name);
                     75:        if (lseek(afd, size, SEEK_SET) == (off_t)-1)
                     76:                error(archive);
1.4       deraadt    77:        (void)snprintf(buf, sizeof buf,
1.9     ! deraadt    78:            "%-12lld", (long long)time(NULL) + RANLIBSKEW);
1.1       deraadt    79:        if (write(afd, buf, sizeof(hdr->ar_date)) != sizeof(hdr->ar_date))
                     80:                error(archive);
                     81: }