forked from mbmcmullen27/effective-c
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdmalloc.c
38 lines (32 loc) · 756 Bytes
/
dmalloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
dmalloc -l logfile -i 100 low
gcc -DDMALLOC dmalloc.c -ocaesar -ldmalloc
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef DMALLOC
#include "dmalloc.h"
#endif
void usage(char *msg) {
fprintf(stderr, "%s", msg);
free(msg);
return;
}
int main(int argc, char *argv[]) {
if (argc != 3 && argc != 4) {
/* the error message won't be more than 80 chars */
char *errmsg = (char *)malloc(80);
printf("%c", errmsg[90]);
sprintf(
errmsg,
"Sorry %s, \nUsage: caesar secret_file keys_file [output_file]\n",
getenv("USER")
);
usage(errmsg);
free(errmsg);
exit(EXIT_FAILURE);
}
// ...
exit(EXIT_SUCCESS);
}