/* $Id$ * * Copyright (C) 1990-1998 by the Massachusetts Institute of Technology. * For copying and distribution information, please see the file * . */ #include #include #include #include #include #include "util.h" EXEC SQL INCLUDE sqlca; /* Julian day of the UNIX epoch (January 1, 1970) */ #define UNIX_EPOCH 2440588 /****************************************************************/ /** Return the difference between the modtime & table modtime **/ /** in flag variable. Return 0 if success, else errno. **/ /****************************************************************/ int ModDiff(int *flag, char *tbl, time_t ModTime) { time_t filetimeno; EXEC SQL BEGIN DECLARE SECTION; char filetime[48], *tbl_name, *unixtime_fmt = UNIXTIME_FMT; EXEC SQL END DECLARE SECTION; *flag = 0; tbl_name = tbl; /* Get modtime as Julian day, hours, minutes, and seconds */ EXEC SQL SELECT TO_CHAR(modtime, :unixtime_fmt) INTO :filetime FROM tblstats WHERE table_name = :tbl_name; if (sqlca.sqlcode) { fprintf(stderr, "Moddiff Query failed: %ld\n", sqlca.sqlcode); return MR_DATE; } *flag = (int) (unixtime(filetime) - ModTime); return 0; } time_t unixtime(char *timestring) { time_t t; t = strtol(timestring, ×tring, 10) - UNIX_EPOCH; t = t * 24 + strtol(timestring, ×tring, 10); t = t * 60 + strtol(timestring, ×tring, 10); t = t * 60 + strtol(timestring, ×tring, 10); return t; }