From 4972b017b63f3ce324bfa65a1b46a2a173baf463 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Tue, 13 Jun 2000 05:22:52 +0000 Subject: * Some timestamp fixes from Paul Eggert. * Fix compilation on Linux; use libintl.h and not gettext.h when using the system gettext. --- file.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index daaea69..b583db9 100644 --- a/file.c +++ b/file.c @@ -475,8 +475,8 @@ snap_deps () { /* Mark this file as phony and nonexistent. */ f2->phony = 1; - f2->last_mtime = (FILE_TIMESTAMP) -1; - f2->mtime_before_update = (FILE_TIMESTAMP) -1; + f2->last_mtime = NONEXISTENT_MTIME; + f2->mtime_before_update = NONEXISTENT_MTIME; } for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev) @@ -564,35 +564,73 @@ set_command_state (file, state) d->file->command_state = state; } +/* Convert an external file timestamp to internal form. */ + +FILE_TIMESTAMP +file_timestamp_cons (fname, s, ns) + char const *fname; + time_t s; + int ns; +{ + int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0); + FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS; + FILE_TIMESTAMP ts = product + offset; + + if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX) + && product <= ts && ts <= ORDINARY_MTIME_MAX)) + { + char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; + ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX; + file_timestamp_sprintf (buf, ts); + error (NILF, _("%s: Timestamp out of range; substituting %s"), + fname ? fname : _("Current time"), buf); + } + + return ts; +} + /* Get and print file timestamps. */ FILE_TIMESTAMP file_timestamp_now () { + time_t s; + int ns; + /* Don't bother with high-resolution clocks if file timestamps have only one-second resolution. The code below should work, but it's not worth the hassle of debugging it on hosts where it fails. */ - if (1 < FILE_TIMESTAMPS_PER_S) + if (FILE_TIMESTAMP_HI_RES) { #if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME { struct timespec timespec; if (clock_gettime (CLOCK_REALTIME, ×pec) == 0) - return FILE_TIMESTAMP_FROM_S_AND_NS (timespec.tv_sec, - timespec.tv_nsec); + { + s = timespec.tv_sec; + ns = timespec.tv_nsec; + goto got_time; + } } #endif #if HAVE_GETTIMEOFDAY { struct timeval timeval; if (gettimeofday (&timeval, 0) == 0) - return FILE_TIMESTAMP_FROM_S_AND_NS (timeval.tv_sec, - timeval.tv_usec * 1000); + { + s = timeval.tv_sec; + ns = timeval.tv_usec * 1000; + goto got_time; + } } #endif } - return FILE_TIMESTAMP_FROM_S_AND_NS (time ((time_t *) 0), 0); + s = time ((time_t *) 0); + ns = 0; + + got_time: + return file_timestamp_cons (0, s, ns); } void @@ -666,10 +704,12 @@ print_file (f) printf (" %s", dep_name (d)); putchar ('\n'); } - if (f->last_mtime == 0) + if (f->last_mtime == UNKNOWN_MTIME) puts (_("# Modification time never checked.")); - else if (f->last_mtime == (FILE_TIMESTAMP) -1) + else if (f->last_mtime == NONEXISTENT_MTIME) puts (_("# File does not exist.")); + else if (f->last_mtime == OLD_MTIME) + puts (_("# File is very old.")); else { char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; -- cgit v1.2.3