]> andersk Git - moira.git/blob - gen/moddiff.pc
add a cast from unsigned char * to char * for Irix n32 cc
[moira.git] / gen / moddiff.pc
1 /* $Id$
2  *
3  * Copyright (C) 1990-1998 by the Massachusetts Institute of Technology.
4  * For copying and distribution information, please see the file
5  * <mit-copyright.h>.
6  */
7
8 #include <mit-copyright.h>
9 #include <moira.h>
10
11 #include <sys/types.h>
12
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include "util.h"
17
18 EXEC SQL INCLUDE sqlca;
19
20 /* Julian day of the UNIX epoch (January 1, 1970) */
21 #define UNIX_EPOCH 2440588
22
23 /****************************************************************/
24 /**  Return the difference between the modtime & table modtime **/
25 /**  in flag variable.  Return 0 if success, else errno.       **/
26 /****************************************************************/
27
28 int ModDiff(int *flag, char *tbl, time_t ModTime)
29 {
30   time_t filetimeno;
31   EXEC SQL BEGIN DECLARE SECTION;
32   char filetime[48], *tbl_name, *unixtime_fmt = UNIXTIME_FMT;
33   EXEC SQL END DECLARE SECTION;
34
35   *flag = 0;
36   tbl_name = tbl;
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;
41   if (sqlca.sqlcode)
42     {
43       fprintf(stderr, "Moddiff Query failed: %ld\n", sqlca.sqlcode);
44       return MR_DATE;
45     }
46
47   *flag = (int) (unixtime(filetime) - ModTime);
48   return 0;
49 }
50
51 time_t unixtime(char *timestring)
52 {
53   time_t t;
54
55   t = strtol(timestring, &timestring, 10) - UNIX_EPOCH;
56   t = t * 24 + strtol(timestring, &timestring, 10);
57   t = t * 60 + strtol(timestring, &timestring, 10);
58   t = t * 60 + strtol(timestring, &timestring, 10);
59
60   return t;
61 }
This page took 0.039461 seconds and 5 git commands to generate.