3 * Copyright (C) 1990-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
11 #include <sys/types.h>
18 EXEC SQL INCLUDE sqlca;
20 /* Julian day of the UNIX epoch (January 1, 1970) */
21 #define UNIX_EPOCH 2440588
23 /****************************************************************/
24 /** Return the difference between the modtime & table modtime **/
25 /** in flag variable. Return 0 if success, else errno. **/
26 /****************************************************************/
28 int ModDiff(int *flag, char *tbl, time_t ModTime)
31 EXEC SQL BEGIN DECLARE SECTION;
32 char filetime[48], *tbl_name, *unixtime_fmt = UNIXTIME_FMT;
33 EXEC SQL END DECLARE SECTION;
37 /* Get modtime as Julian day, hours, minutes, and seconds */
38 EXEC SQL SELECT TO_CHAR(modtime, :unixtime_fmt)
39 INTO :filetime FROM tblstats
40 WHERE table_name = :tbl_name;
43 fprintf(stderr, "Moddiff Query failed: %ld\n", sqlca.sqlcode);
47 *flag = (int) (unixtime(filetime) - ModTime);
51 time_t unixtime(char *timestring)
55 t = strtol(timestring, ×tring, 10) - UNIX_EPOCH;
56 t = t * 24 + strtol(timestring, ×tring, 10);
57 t = t * 60 + strtol(timestring, ×tring, 10);
58 t = t * 60 + strtol(timestring, ×tring, 10);