aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorEric Faurot <eric@faurot.net>2017-08-03 17:16:55 +0200
committerEric Faurot <eric@faurot.net>2017-08-03 17:16:55 +0200
commit1040bcaf3138fa0688ef556b6241c19040849a0a (patch)
tree9ba83afefcc2fec47677b4317d6ff2f6d9d18e20 /contrib
parentadd recallocarray() to compat layer (diff)
downloadOpenSMTPD-1040bcaf3138fa0688ef556b6241c19040849a0a.tar.xz
OpenSMTPD-1040bcaf3138fa0688ef556b6241c19040849a0a.zip
replace fgetln() calls with getline()
Diffstat (limited to 'contrib')
-rw-r--r--contrib/libexec/encrypt/encrypt.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/contrib/libexec/encrypt/encrypt.c b/contrib/libexec/encrypt/encrypt.c
index c2639914..80275921 100644
--- a/contrib/libexec/encrypt/encrypt.c
+++ b/contrib/libexec/encrypt/encrypt.c
@@ -37,8 +37,9 @@ static void print_passwd(const char *);
int
main(int argc, char *argv[])
{
- char *buf, *lbuf;
- size_t len;
+ char *line;
+ size_t linesz;
+ ssize_t linelen;
if (argc > 2) {
fprintf(stderr, "usage: encrypt <string>\n");
@@ -50,22 +51,14 @@ main(int argc, char *argv[])
return (0);
}
- lbuf = NULL;
- while ((buf = fgetln(stdin, &len))) {
- if (buf[len - 1] == '\n')
- buf[len - 1] = '\0';
- else {
- if ((lbuf = malloc(len + 1)) == NULL) {
- fprintf(stderr, "memory exhausted");
- return (1);
- }
- memcpy(lbuf, buf, len);
- lbuf[len] = '\0';
- buf = lbuf;
- }
- print_passwd(buf);
+ line = NULL;
+ linesz = 0;
+ while ((linelen = getline(&line, &linesz, stdin)) != -1) {
+ if (line[linelen - 1] == '\n')
+ line[linelen - 1] = '\0';
+ print_passwd(line);
}
- free(lbuf);
+ free(line);
return (0);
}