]> andersk Git - moira.git/blob - gen/util.c
Oracle and Solaris/POSIX changes
[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 extern void sqlglm(char buf[], int *, int *);
18
19 fix_file(targetfile)
20 char *targetfile;
21 {
22     char oldfile[64], filename[64];
23
24     sprintf(oldfile, "%s.old", targetfile);
25     sprintf(filename, "%s~", targetfile);
26     if (rename(targetfile, oldfile) == 0) {
27         if (rename(filename, targetfile) < 0) {
28             rename(oldfile, targetfile);
29             perror("Unable to install new file (rename failed)\n");
30             fprintf(stderr, "Filename = %s\n", targetfile);
31             exit(MR_CCONFIG);
32         }
33     } else {
34         if (rename(filename, targetfile) < 0) {
35             perror("Unable to rename old file\n");
36             fprintf(stderr, "Filename = %s\n", targetfile);
37             exit(MR_CCONFIG);
38         }
39     }
40     unlink(oldfile);
41 }
42
43
44 char *dequote(s)
45 register char *s;
46 {
47     char *last = s;
48
49     while (*s) {
50         if (*s == '"')
51           *s = '\'';
52         else if (*s != ' ')
53           last = s;
54         s++;
55     }
56     if (*last == ' ')
57       *last = '\0';
58     else
59       *(++last) = '\0';
60     return(s);
61 }
62
63
64
65 db_error(code)
66 int code;
67 {
68     extern char *whoami;
69     char buf[256];
70     int bufsize=256, len=0;
71
72     com_err(whoami, MR_DBMS_ERR, " code %d\n", code);
73     sqlglm(buf, &bufsize, &len);
74     buf[len]=0;
75     com_err(whoami, 0, "SQL error text = %s", buf);
76     critical_alert("DCM", "%s build encountered DATABASE ERROR %d\n%s",
77                    whoami, code, buf);
78     exit(MR_DBMS_ERR);
79 }
This page took 0.040818 seconds and 5 git commands to generate.