]> andersk Git - moira.git/blob - gen/util.c
added db_error() routine
[moira.git] / gen / util.c
1 /* $Header$
2  *
3  * Utility routines used by the MOIRA extraction programs.
4  *
5  *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
6  *  For copying and distribution information, please see the file
7  *  <mit-copyright.h>.
8  */
9
10
11 #include <mit-copyright.h>
12 #include <stdio.h>
13 #include <sys/time.h>
14 #include <moira.h>
15 #include <moira_site.h>
16
17
18 fix_file(targetfile)
19 char *targetfile;
20 {
21     char oldfile[64], filename[64];
22
23     sprintf(oldfile, "%s.old", targetfile);
24     sprintf(filename, "%s~", targetfile);
25     if (rename(targetfile, oldfile) == 0) {
26         if (rename(filename, targetfile) < 0) {
27             rename(oldfile, targetfile);
28             perror("Unable to install new file (rename failed)\n");
29             fprintf(stderr, "Filename = %s\n", targetfile);
30             exit(MR_CCONFIG);
31         }
32     } else {
33         if (rename(filename, targetfile) < 0) {
34             perror("Unable to rename old file\n");
35             fprintf(stderr, "Filename = %s\n", targetfile);
36             exit(MR_CCONFIG);
37         }
38     }
39     unlink(oldfile);
40 }
41
42
43 char *dequote(s)
44 register char *s;
45 {
46     char *last = s;
47
48     while (*s) {
49         if (*s == '"')
50           *s = '\'';
51         else if (*s != ' ')
52           last = s;
53         s++;
54     }
55     if (*last == ' ')
56       *last = '\0';
57     else
58       *(++last) = '\0';
59     return(s);
60 }
61
62
63
64 db_error(code)
65 int code;
66 {
67     com_err(whoami, MR_INGRES_ERR, " code %d\n", code);
68     if (code == -49900 || code == -37000 || code == 17700)
69       exit(MR_DEADLOCK);
70     critical_alert("DCM", "%s build encountered DATABASE ERROR %d",
71                    whoami, code);
72     exit(MR_INGRES_ERR);
73 }
This page took 0.038879 seconds and 5 git commands to generate.