diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-01-16 19:01:00 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-01-16 19:01:00 +1300 |
commit | 2722474ec2b7653afe8b45e91cb4795ffac7e9c9 (patch) | |
tree | 0f369f248b52a8cbe7d1d49e6ab7383047bbc665 /crypt.c | |
parent | Merge branch 'release/v1.1.0' (diff) | |
parent | Bump VERSION (diff) | |
download | crypt-1.2.0.tar.gz (sig) crypt-1.2.0.zip |
Merge branch 'release/v1.2.0'v1.2.0
* release/v1.2.0:
Reorder functions
Fix and extend GCC options
Add braces around single-statement if blocks
Adjust indentation of switch block
Use consistent layout for function braces
Diffstat (limited to 'crypt.c')
-rw-r--r-- | crypt.c | 40 |
1 files changed, 22 insertions, 18 deletions
@@ -7,14 +7,14 @@ int main (int argc, char **argv) while ((opt = getopt(argc, argv, "h")) != -1) { switch (opt) { - case 'h': /* Help */ - usage(stdout, EXIT_SUCCESS); - break; - case '?': /* Unknown option */ - usage(stderr, EXIT_FAILURE); - break; - default: /* Shouldn't happen */ - abort(); + case 'h': /* Help */ + usage(stdout, EXIT_SUCCESS); + break; + case '?': /* Unknown option */ + usage(stderr, EXIT_FAILURE); + break; + default: /* Shouldn't happen */ + abort(); } } @@ -22,8 +22,9 @@ int main (int argc, char **argv) * If we don't have three arguments left after processing the options, * exit with usage information and error status */ - if (argc != 3) + if (argc != 3) { usage(stderr, EXIT_FAILURE); + } key = argv[1]; salt = argv[2]; @@ -32,25 +33,28 @@ int main (int argc, char **argv) * Create the hash, but exit immediately with the system error string * if it returns a null pointer (error condition) */ - if (!(hash = crypt(key, salt))) + if (!(hash = crypt(key, salt))) { error(strerror(errno)); + } puts(hash); exit(EXIT_SUCCESS); } /* - * Show usage to given stream, and exit with given code + * Exit with error error message */ -void usage(FILE *stream, int status) { - fputs("USAGE: crypt [-h | KEY SALT]\n", stream); - exit(status); +void error(char *message) +{ + fprintf(stderr, "%s\n", message); + exit(EXIT_FAILURE); } /* - * Exit with error error message + * Show usage to given stream, and exit with given code */ -void error(char *message) { - fprintf(stderr, "%s\n", message); - exit(EXIT_FAILURE); +void usage(FILE *stream, int status) +{ + fputs("USAGE: crypt [-h | KEY SALT]\n", stream); + exit(status); } |