1 From d3aee6c489852108c91dc22abcacff364e9429f2 Mon Sep 17 00:00:00 2001
2 From: Chris Wong <chrisyco@gmail.com>
3 Date: Wed, 23 Nov 2011 11:34:55 +1300
4 Subject: [PATCH] Add more error detection
7 beep.c | 15 +++++++++------
8 1 file changed, 9 insertions(+), 6 deletions(-)
10 diff --git a/beep.c b/beep.c
11 index 452fc08..14fac3e 100644
14 @@ -98,11 +98,11 @@ char *console_device = NULL;
17 void do_beep(int freq) {
18 - if (console_type == BEEP_TYPE_CONSOLE) {
19 - if(ioctl(console_fd, KIOCSOUND, freq != 0
20 - ? (int)(CLOCK_TICK_RATE/freq)
22 - printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
23 + int period = (freq != 0 ? (int)(CLOCK_TICK_RATE/freq) : freq);
25 + if(console_type == BEEP_TYPE_CONSOLE) {
26 + if(ioctl(console_fd, KIOCSOUND, period) < 0) {
27 + putchar('\a'); /* Output the only beep we can, in an effort to fall back on usefulness */
31 @@ -113,7 +113,10 @@ void do_beep(int freq) {
35 - write(console_fd, &e, sizeof(struct input_event));
36 + if(write(console_fd, &e, sizeof(struct input_event)) < 0) {
37 + putchar('\a'); /* See above */