3 * Utility routines used by the MOIRA extraction programs.
5 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include <moira_site.h>
21 /* Julian day of the UNIX epoch (January 1, 1970) */
22 #define UNIX_EPOCH 2440588
24 extern void sqlglm(char buf[], int *, int *);
26 void fix_file(char *targetfile)
28 char oldfile[64], filename[64];
30 sprintf(oldfile, "%s.old", targetfile);
31 sprintf(filename, "%s~", targetfile);
32 if (rename(targetfile, oldfile) == 0)
34 if (rename(filename, targetfile) < 0)
36 rename(oldfile, targetfile);
37 perror("Unable to install new file (rename failed)\n");
38 fprintf(stderr, "Filename = %s\n", targetfile);
44 if (rename(filename, targetfile) < 0)
46 perror("Unable to rename old file\n");
47 fprintf(stderr, "Filename = %s\n", targetfile);
55 char *dequote(char *s)
74 time_t unixtime(char *timestring)
78 t = strtol(timestring, ×tring, 10) - UNIX_EPOCH;
79 t = t * 24 + strtol(timestring, ×tring, 10);
80 t = t * 60 + strtol(timestring, ×tring, 10);
81 t = t * 60 + strtol(timestring, ×tring, 10);
86 void db_error(int code)
90 int bufsize = 256, len = 0;
94 com_err(whoami, 0, "build cancelled by user");
98 com_err(whoami, MR_DBMS_ERR, " code %d\n", code);
99 sqlglm(buf, &bufsize, &len);
101 com_err(whoami, 0, "SQL error text = %s", buf);
102 critical_alert("DCM", "%s build encountered DATABASE ERROR %d\n%s",