vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, tech@ readers. display.c contains function anykey(). This function useses read(2) system call to read user input. Let see how read(2) return value is check for errors: display.c: .... size_t len; .... len = read(STDIN_FILENO, &ch, 1); if (len == -1 && errno == EINTR) continue; .... Pay attention that len is tested against -1. len is declared as size_t. size_t is unsigned data type. Also from read(2) one can see that read(2) returns not size_t, but ssize_t (two `s'). ssize_t is signed data type. (~)[1]% grep __size_t /usr/include/machine/_types.h typedef unsigned long __size_t; (~)[2]% grep __ssize_t /usr/include/machine/_types.h typedef long __ssize_t; Problem: len is declared as unsigned, but is tested against -1. This is incorrect. Following diff declares len as ssize_t (with two `s'). It also sorts headers as style(9) says. Occasionaly i added sever blank lines for clarity. --- display.c.original Fri Jul 27 12:27:08 2007 +++ display.c Fri Jul 27 13:35:45 2007 @@ -47,22 +47,23 @@ #include <sys/types.h> #include <sys/sched.h> + +#include <ctype.h> #include <curses.h> +#include <err.h> #include <errno.h> #include <stdio.h> -#include <ctype.h> -#include <err.h> -#include <signal.h> #include <stdlib.h> +#include <signal.h> #include <string.h> #include <unistd.h> -#include "screen.h" /* interface to screen package */ -#include "layout.h" /* defines for screen position layout */ +#include "boolean.h" #include "display.h" +#include "layout.h" /* defines for screen position layout */ #include "top.h" -#include "boolean.h" #include "machine.h" /* we should eliminate this!!! */ +#include "screen.h" /* interface to screen package */ #include "utils.h" #ifdef DEBUG @@ -505,7 +506,7 @@ } void -u_endscreen(int hi) +u_endscreen(void) { if (smart_terminal) { clrtobot(); @@ -827,19 +828,22 @@ anykey(void) { int ch; - size_t len; + ssize_t len; standoutp(); addstrp("Hit any key to continue: "); standendp(); + if (smart_terminal) refresh(); else fflush(stdout); + while (1) { len = read(STDIN_FILENO, &ch, 1); if (len == -1 && errno == EINTR) continue; + if (len == 0) exit(1); break; |