]> andersk Git - moira.git/blob - gen/moddiff.pc
second code style cleanup: void/void * usage, proper #includes. try to
[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], *ft = filetime, *tbl_name;
33   EXEC SQL END DECLARE SECTION;
34
35   *flag = 0;
36   tbl_name = tbl;
37   /* Get modtime as seconds, minutes, hours, and Julian day */
38   EXEC SQL SELECT TO_CHAR(modtime, 'SS MI HH24 J')
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   filetimeno = strtol(ft, &ft, 10);
48   filetimeno = filetimeno * 60 + strtol(ft, &ft, 10);
49   filetimeno = filetimeno * 60 + strtol(ft, &ft, 10);
50   filetimeno = filetimeno * 24 + (strtol(ft, NULL, 10) - UNIX_EPOCH);
51
52   *flag = (int) (filetimeno - ModTime);
53   return 0;
54 }
This page took 0.731516 seconds and 5 git commands to generate.