commit: f4479ed7ac4a976ecb48bdd2f50a3cd53b69bc94
parent c1708108ad428dc66d95e2abac07ca3848ee21fb
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 9 Oct 2022 03:31:18 +0200
Don't call perror on getline EOF
Diffstat:
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/common.c b/common.c
@@ -7,6 +7,7 @@
#include "common.h"
+#include <errno.h> // errno
#include <stdio.h> // fclose, fopen, fprintf, perror, getline, fileno
#include <string.h> // explicit_bzero
#include <termios.h> // tcgetattr, tcsetattr
@@ -94,14 +95,15 @@ skeud_getpass(char **password)
goto getpass_end;
}
- got = getline(password, &len, tty);
+ errno = 0;
+ got = getline(password, &len, tty);
fprintf(tty, "\n");
if(got < 0)
{
t.c_lflag &= ECHO;
tcsetattr(tty_fd, TCSANOW, &t);
- perror("getline");
+ if(errno != 0) perror("getline");
goto getpass_end;
}
(*password)[got] = 0;
diff --git a/login.c b/login.c
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
ssize_t got = getline(&username, &len, stdin);
if(got < 0)
{
- perror("getline");
+ if(errno != 0) perror("getline");
return 1;
}