6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
8 * This program dumps the SMS database to a series of output files
9 * which can be later read back into SMS in the event of a crash.
12 * Revision 1.2 1987-07-13 03:52:53 wesommer
13 * Modified to pass lint, do better backups.
15 Revision 1.1 87/07/11 19:51:05 wesommer
22 static char *rcsid_dump_db_c = "$Header$";
29 /* putc without the line buffer hair */
31 #define putc1(x, p) (--(p)->_cnt >= 0 ?\
32 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
33 _flsbuf((unsigned char)(x), p))
47 fprintf(stderr, "Usage: smsbackup prefix\n");
57 for (i=0; i<' '; i++) act[i]=2;
72 (void) sprintf(buf, "%d", n);
78 punt("can't write backup file");
85 register char *ibp = str;
86 register int c; /* PCC doesn't put chars in registers.. */
87 for (; c = *ibp; ibp++) {
88 c = toascii(c); /* punt 8th bit */
92 if (putc1('\\', f) < 0) wpunt();
95 if (putc1(c, f) < 0) wpunt();
99 if (putc1('\\', f) < 0) wpunt();
100 t = ((c>>6)&7) + '0';
101 if (putc1(t,f) < 0) wpunt();
102 t = ((c>>3)&7) + '0';
103 if (putc1(t,f) < 0) wpunt();
105 if (putc1(t,f) < 0) wpunt();
106 fprintf(stderr, "control character \\%03o\n", c);
110 punt("Can't get here");
118 if (fflush(stream) == EOF)
119 punt("Unable to fflush");
120 if (fsync(fileno(stream)) != 0)
121 punt("Unable to fsync");
122 (void) fclose(stream);
125 FILE *open_file(prefix, suffix)
126 char *prefix, *suffix;
132 (void) strcpy(name, prefix);
133 (void) strcat(name, suffix);
135 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
141 fprintf(stderr, "fdopen of ");
144 fprintf(stderr, "Working on %s\n", name);
152 * c-continued-statement-offset: 4
154 * c-argdecl-indent: 4