]> andersk Git - moira.git/blame - gen/util.c
make sure new usernames don't conflict with filesys aliases
[moira.git] / gen / util.c
CommitLineData
dfb56d6b 1/* $Header$
2 *
2ce085d2 3 * Utility routines used by the MOIRA extraction programs.
0a5ff702 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>.
dfb56d6b 8 */
9
10
0a5ff702 11#include <mit-copyright.h>
dfb56d6b 12#include <stdio.h>
13#include <sys/time.h>
2ce085d2 14#include <moira.h>
15#include <moira_site.h>
dfb56d6b 16
9c04b191 17extern void sqlglm(char buf[], int *, int *);
dfb56d6b 18
70c18c18 19fix_file(targetfile)
20char *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);
2ce085d2 31 exit(MR_CCONFIG);
70c18c18 32 }
33 } else {
34 if (rename(filename, targetfile) < 0) {
35 perror("Unable to rename old file\n");
36 fprintf(stderr, "Filename = %s\n", targetfile);
2ce085d2 37 exit(MR_CCONFIG);
70c18c18 38 }
39 }
40 unlink(oldfile);
41}
42
43
44char *dequote(s)
45register 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 }
1889bd72 56 if (*last == ' ')
57 *last = '\0';
58 else
59 *(++last) = '\0';
4d6f76b9 60 return(s);
70c18c18 61}
fff24f1c 62
63
64
65db_error(code)
66int code;
67{
b272e93d 68 extern char *whoami;
9c04b191 69 char buf[256];
70 int bufsize=256, len=0;
b272e93d 71
9c04b191 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);
fff24f1c 79}
This page took 0.092608 seconds and 5 git commands to generate.