-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
52 lines (45 loc) · 1.36 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <signal.h>
#include <unistd.h>
#include "simple_aes.h"
/* print how to use the program to stderr */
void print_usage(void) {
fprintf(stderr,
"Usage: "
"./simple_aes <FILE> [KEY]\n"
"FILE: the file to encrypt.\n"
"KEY: the key to use; if not specified, "
"attempt to read key from stdin.\n"
"If no key is found, create a random key and print "
"it to stdout once finished.");
}
/* handle different signals we receive */
void interrupt_handler(int signo) {
if (signo == SIGINT) {
fprintf(stderr, "Interrupt signal received\n");
exit(EXIT_FAILURE);
}
}
int main(int argc, char ** argv) {
/* make sure we have at least 2 arguments, and not more than 3 */
if (argc < 2 || argc > 3) {
fprintf(stderr, "Invalid options!\n");
print_usage();
return EXIT_FAILURE;
}
/* register signal handler for SIGINT */
if (signal(SIGINT, interrupt_handler) == SIG_ERR) {
fprintf(stderr, "Can't register signal handler, aborting...\n");
return EXIT_FAILURE;
}
/* placeholder 'functionality' */
printf("%s\n", argv[0]);
printf("%s\n", argv[1]);
if (argc == 3) printf("%s\n", argv[2]);
while (1) {
sleep(1);
}
return EXIT_SUCCESS;
}