]>
Commit | Line | Data |
---|---|---|
4217b4b6 MF |
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 | |
5 | ||
6 | --- | |
7 | beep.c | 15 +++++++++------ | |
8 | 1 file changed, 9 insertions(+), 6 deletions(-) | |
9 | ||
10 | diff --git a/beep.c b/beep.c | |
11 | index 452fc08..14fac3e 100644 | |
12 | --- a/beep.c | |
13 | +++ b/beep.c | |
14 | @@ -98,11 +98,11 @@ char *console_device = NULL; | |
15 | ||
16 | ||
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) | |
21 | - : freq) < 0) { | |
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); | |
24 | + | |
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 */ | |
28 | perror("ioctl"); | |
29 | } | |
30 | } else { | |
31 | @@ -113,7 +113,10 @@ void do_beep(int freq) { | |
32 | e.code = SND_TONE; | |
33 | e.value = freq; | |
34 | ||
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 */ | |
38 | + perror("write"); | |
39 | + } | |
40 | } | |
41 | } | |
42 | ||
43 | -- | |
44 | 2.7.5 |