Message ID | 20180814112435.22166-7-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
Series | lib: minor code clean up | expand |
On 2018-08-14 04:24 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > However unlikely, we should add a sanity check on the return from > fileno just in case it failed. Fix a typo in a comment and remove > an empty line. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/lib/src/fwts_interactive.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/src/lib/src/fwts_interactive.c b/src/lib/src/fwts_interactive.c > index 5a8e873e..d1aa70fe 100644 > --- a/src/lib/src/fwts_interactive.c > +++ b/src/lib/src/fwts_interactive.c > @@ -33,9 +33,11 @@ static int fwts_getchar(int *ch) > { > struct termios oldterm; > struct termios newterm; > - int fd = fileno(stdin); > + const int fd = fileno(stdin); > > *ch = -1; > + if (fd < 0) > + return FWTS_ERROR; > > if (tcgetattr(fd, &oldterm) < 0) > return FWTS_ERROR; > @@ -76,7 +78,7 @@ int fwts_printf(fwts_framework *fw, const char *fmt, ...) > } > > /* > - * fwts_press_entrer() > + * fwts_press_enter() > * prompt and wait for enter key > */ > int fwts_press_enter(fwts_framework *fw) > @@ -111,7 +113,6 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options) > fflush(stdout); > > for (;;) { > - > if (fwts_getchar(&ch) == FWTS_ERROR) { > fwts_log_error(fw, "fwts_getchar() failed."); > break; > @@ -124,4 +125,3 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options) > > return ch; > } > - > Acked-by: Alex Hung <alex.hung@canonical.com>
On 08/14/2018 07:24 PM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > However unlikely, we should add a sanity check on the return from > fileno just in case it failed. Fix a typo in a comment and remove > an empty line. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/lib/src/fwts_interactive.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/src/lib/src/fwts_interactive.c b/src/lib/src/fwts_interactive.c > index 5a8e873e..d1aa70fe 100644 > --- a/src/lib/src/fwts_interactive.c > +++ b/src/lib/src/fwts_interactive.c > @@ -33,9 +33,11 @@ static int fwts_getchar(int *ch) > { > struct termios oldterm; > struct termios newterm; > - int fd = fileno(stdin); > + const int fd = fileno(stdin); > > *ch = -1; > + if (fd < 0) > + return FWTS_ERROR; > > if (tcgetattr(fd, &oldterm) < 0) > return FWTS_ERROR; > @@ -76,7 +78,7 @@ int fwts_printf(fwts_framework *fw, const char *fmt, ...) > } > > /* > - * fwts_press_entrer() > + * fwts_press_enter() > * prompt and wait for enter key > */ > int fwts_press_enter(fwts_framework *fw) > @@ -111,7 +113,6 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options) > fflush(stdout); > > for (;;) { > - > if (fwts_getchar(&ch) == FWTS_ERROR) { > fwts_log_error(fw, "fwts_getchar() failed."); > break; > @@ -124,4 +125,3 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options) > > return ch; > } > - Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff --git a/src/lib/src/fwts_interactive.c b/src/lib/src/fwts_interactive.c index 5a8e873e..d1aa70fe 100644 --- a/src/lib/src/fwts_interactive.c +++ b/src/lib/src/fwts_interactive.c @@ -33,9 +33,11 @@ static int fwts_getchar(int *ch) { struct termios oldterm; struct termios newterm; - int fd = fileno(stdin); + const int fd = fileno(stdin); *ch = -1; + if (fd < 0) + return FWTS_ERROR; if (tcgetattr(fd, &oldterm) < 0) return FWTS_ERROR; @@ -76,7 +78,7 @@ int fwts_printf(fwts_framework *fw, const char *fmt, ...) } /* - * fwts_press_entrer() + * fwts_press_enter() * prompt and wait for enter key */ int fwts_press_enter(fwts_framework *fw) @@ -111,7 +113,6 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options) fflush(stdout); for (;;) { - if (fwts_getchar(&ch) == FWTS_ERROR) { fwts_log_error(fw, "fwts_getchar() failed."); break; @@ -124,4 +125,3 @@ int fwts_get_reply(fwts_framework *fw, const char *message, const char *options) return ch; } -