6 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
10 * This program dumps the SMS database to a series of output files
11 * which can be later read back into SMS in the event of a crash.
16 static char *rcsid_dump_db_c = "$Header$";
23 #include <mit-copyright.h>
24 EXEC SQL INCLUDE sqlca;
27 /* putc without the line buffer hair */
29 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
30 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
31 _flsbuf((unsigned char)(x), p))
35 EXEC SQL BEGIN DECLARE SECTION;
37 EXEC SQL END DECLARE SECTION;
39 int main(int argc, char **argv)
46 fprintf(stderr, "Usage: %s prefix\n", argv[0]);
51 EXEC SQL CONNECT :db IDENTIFIED BY :db;
59 int dump_int(FILE *f, int n)
62 sprintf(buf, "%d", n);
68 punt("can't write backup file");
71 int dump_str(FILE *f, char *str)
76 for (ibp = str; c = (unsigned char) *ibp; ibp++)
78 if (c < 32 || c > 126 || c == SEP_CHAR || c == '\\')
80 if (putc1('\\', f) < 0)
82 t = ((c >> 6) & 7) + '0';
85 t = ((c >> 3) & 7) + '0';
100 int safe_close(FILE *stream)
102 if (fflush(stream) == EOF)
103 punt("Unable to fflush");
104 if (fsync(fileno(stream)) != 0)
105 punt("Unable to fsync");
109 FILE *open_file(char *prefix, char *suffix)
115 strcpy(name, prefix);
116 strcat(name, suffix);
118 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
124 fprintf(stderr, "fdopen of ");
127 fprintf(stderr, "Working on %s\n", name);
133 * Trim whitespace off both ends of a string.
135 char *strtrim(char *save)
142 /* skip to end of string */