aboutsummaryrefslogtreecommitdiff
path: root/crypt.c
blob: 22f82bd4a4807f789ce9d8766b8a2dff0d0a3d89 (plain) (blame)
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
#include "crypt.h"

/*
 * Main function
 */
int main (int argc, char **argv)
{
    /* The hash we will produce, hopefully */
    char *hash = NULL;

    /* Option character */
    int opt;

    /* Iterate through any options */
    while ((opt = getopt(argc, argv, "h")) != -1) {
        switch (opt) {
            case 'h':
                usage(stdout, EXIT_SUCCESS);
                break;
            case '?':
                usage(stderr, EXIT_FAILURE);
                break;
            default:
                abort();
        }
    }

    /* If we don't have three arguments left now, bail */
    if (argc != 3)
        usage(stderr, EXIT_FAILURE);

    /* All seems well, build the hash and print it */
    hash = crypt(argv[1], argv[2]);
    puts(hash);
    exit(EXIT_SUCCESS);
}

/*
 * Show usage to given stream, and exit with given code
 */
void usage(FILE *stream, int status) {
    fputs("USAGE: crypt [-h | KEY SALT]\n", stream);
    exit(status);
}