aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rw-r--r--crypt.c28
2 files changed, 21 insertions, 9 deletions
diff --git a/VERSION b/VERSION
index 227cea2..7ec1d6d 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0.0
+2.1.0
diff --git a/crypt.c b/crypt.c
index 4c9f0fb..48c8bd2 100644
--- a/crypt.c
+++ b/crypt.c
@@ -1,17 +1,18 @@
#define _XOPEN_SOURCE
+#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* strerror(3) */
#include <unistd.h> /* crypt(3) */
-void error(char *);
+void error(const char *);
void usage(FILE *, int);
-int main (int argc, char **argv)
+int main(int argc, char **argv)
{
- char *hash, *key, *salt;
- int opt;
+ const char *hash, *key, *salt;
+ int opt, printed;
while ((opt = getopt(argc, argv, "h")) != -1) {
switch (opt) {
@@ -44,15 +45,26 @@ int main (int argc, char **argv)
if (!(hash = crypt(key, salt))) {
error(strerror(errno));
}
+ assert(strlen(hash) > 0);
+
+ /*
+ * Print the hash, and ensure we printed all of it
+ */
+ if ((printed = printf("%s\n", hash)) < 0) {
+ error(strerror(errno));
+ }
+ assert(printed > 0);
+ if ((unsigned) printed < strlen(hash) + 1) { /* +1 for newline */
+ error("Incomplete print");
+ }
- puts(hash);
exit(EXIT_SUCCESS);
}
/*
- * Exit with error error message
+ * Exit with error message and status
*/
-void error(char *message)
+void error(const char *message)
{
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
@@ -61,7 +73,7 @@ void error(char *message)
/*
* Show usage to given stream, and exit with given code
*/
-void usage(FILE *stream, int status)
+void usage(FILE *stream, const int status)
{
fputs("USAGE: crypt [-h | KEY SALT]\n", stream);
exit(status);