[BACK]Return to timestamp.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/timestamp.h, Revision 1.5

1.1       espie       1: #ifndef TIMESTAMP_H
                      2: #define TIMESTAMP_H
                      3:
                      4: /*     $OpenPackages$ */
1.5     ! espie       5: /*     $OpenBSD$ */
1.1       espie       6:
                      7: /*
                      8:  * Copyright (c) 2001 Marc Espie.
                      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.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
                     20:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
                     21:  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
                     22:  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
                     23:  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                     24:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
                     25:  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     26:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     27:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     28:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
                     29:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     30:  */
                     31:
                     32: /* This module handles time stamps on files in a relatively high-level way.
                     33:  * Most of the interface is achieved through inlineable code.
                     34:  *
                     35:  * TIMESTAMP:                  opaque data type to store a date.
                     36:  * ts_set_out_of_date(t):      set up t so that it is out-of-date.
                     37:  * b = is_out_of_date(t):      check whether t is out-of-date.
                     38:  * ts_set_from_stat(s, t):     grab date out of stat(2) buffer.
1.4       espie      39:  * b = is_strictly_before(t1, t2):
1.1       espie      40:  *                             check whether t1 is before t2.
                     41:  * stamp = timestamp2time_t(t):        extract time_t from timestamp.
                     42:  * ts_set_from_time_t(d, t):   create timestamp from time_t.
                     43:  * ts_set_from_now(n):         grab current date.
                     44:  */
                     45:
1.3       espie      46: /* sysresult = set_times(name):        set modification times on a file.
1.1       espie      47:  *                             system call results.
                     48:  */
                     49:
                     50: #define Init_Timestamp()       ts_set_from_now(now)
                     51:
                     52: #ifndef TIMESTAMP_TYPE
                     53: #include "timestamp_t.h"
                     54: #endif
                     55: #ifdef USE_TIMESPEC
                     56: #define ts_set_out_of_date(t)  (t).tv_sec = INT_MIN, (t).tv_nsec = 0
                     57: #define is_out_of_date(t)      ((t).tv_sec == INT_MIN && (t).tv_nsec == 0)
                     58: #define ts_set_from_stat(s, t) \
                     59: do { \
                     60:        (t).tv_sec = (s).st_mtime; \
                     61:        (t).tv_nsec = (s).st_mtimensec; \
                     62:        if (is_out_of_date(t)) \
                     63:                (t).tv_nsec++; \
                     64: } while (0)
                     65: #define is_strictly_before(t1, t2)     timespeccmp(&(t1), &(t2), <)
                     66: #define ts_set_from_time_t(d, t) \
                     67: do { \
                     68:        (t).tv_sec = d; \
                     69:        (t).tv_nsec = 0; \
                     70:        if (is_out_of_date(t)) \
                     71:                (t).tv_nsec++; \
                     72: } while (0)
                     73: #define ts_set_from_now(n) \
                     74: do { \
                     75:        struct timeval tv; \
                     76:        gettimeofday(&tv, NULL); \
                     77:        TIMEVAL_TO_TIMESPEC(&(tv), &n); \
                     78: } while (0)
                     79: #define timestamp2time_t(t)    ((t).tv_sec)
                     80: #else
                     81: #define is_out_of_date(t)      ((t) == INT_MIN)
                     82: #define ts_set_out_of_date(t)  (t) = INT_MIN
                     83: #define ts_set_from_stat(s, t) \
                     84: do { \
                     85:        (t) = (s).st_mtime; \
                     86:        if (is_out_of_date(t)) \
                     87:                (t)++; \
                     88: } while (0)
                     89: #define is_strictly_before(t1, t2)     ((t1) < (t2))
                     90: #define ts_set_from_time_t(d, t) \
                     91: do { \
                     92:        (t) = d; \
                     93:        if (is_out_of_date(t)) \
                     94:                (t)++; \
                     95: } while (0)
                     96: #define ts_set_from_now(n) time(&(n))
                     97: #define timestamp2time_t(t)    (t)
                     98: #endif
                     99:
                    100: extern int set_times(const char *);
                    101:
                    102: extern TIMESTAMP now;          /* The time at the start of this whole
                    103:                                 * process */
1.2       espie     104: extern char *time_to_string(TIMESTAMP t);
                    105:
1.1       espie     106:
                    107: #endif