comparison src/sound.c @ 655:6ba20a0089d8

[gaim-migrate @ 665] added another check to can_play_esd (or whatever) to make sure /dev/dsp is available committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 10 Aug 2000 05:02:01 +0000
parents eaab8abda2c0
children c9b66c710283
comparison
equal deleted inserted replaced
654:ea811c6dd3e0 655:6ba20a0089d8
46 #include "sounds/BuddyArrive.h" 46 #include "sounds/BuddyArrive.h"
47 #include "sounds/BuddyLeave.h" 47 #include "sounds/BuddyLeave.h"
48 #include "sounds/Send.h" 48 #include "sounds/Send.h"
49 #include "sounds/Receive.h" 49 #include "sounds/Receive.h"
50 50
51 51 static int check_dev(char *dev)
52 static void play_audio(char *data, int size)
53 {
54 int fd;
55
56 fd = open("/dev/audio", O_WRONLY | O_EXCL);
57 if (fd < 0)
58 return;
59 write(fd, data, size);
60 close(fd);
61 }
62
63 static int can_play_audio()
64 { 52 {
65 struct stat stat_buf; 53 struct stat stat_buf;
66 uid_t user = getuid(); 54 uid_t user = getuid();
67 gid_t group = getgid(); 55 gid_t group = getgid();
68 if (stat("/dev/audio", &stat_buf)) 56 if (stat(dev, &stat_buf))
69 return 0; 57 return 0;
70 if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR) 58 if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR)
71 return 1; 59 return 1;
72 if (group == stat_buf.st_gid && stat_buf.st_mode & S_IWGRP) 60 if (group == stat_buf.st_gid && stat_buf.st_mode & S_IWGRP)
73 return 1; 61 return 1;
74 if (stat_buf.st_mode & S_IWOTH) 62 if (stat_buf.st_mode & S_IWOTH)
75 return 1; 63 return 1;
76 return 0; 64 return 0;
65 }
66
67
68 static void play_audio(char *data, int size)
69 {
70 int fd;
71
72 fd = open("/dev/audio", O_WRONLY | O_EXCL);
73 if (fd < 0)
74 return;
75 write(fd, data, size);
76 close(fd);
77 }
78
79 static int can_play_audio()
80 {
81 return check_dev("/dev/audio");
77 } 82 }
78 83
79 84
80 #ifdef ESD_SOUND 85 #ifdef ESD_SOUND
81 /* 86 /*
133 } 138 }
134 139
135 static int can_play_esd() 140 static int can_play_esd()
136 { 141 {
137 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; 142 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO;
143
144 if (!check_dev("/dev/dsp")) return 0;
138 145
139 esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); 146 esd_fd = esd_play_stream(format, 8012, NULL, "gaim");
140 147
141 if (esd_fd < 0) { 148 if (esd_fd < 0) {
142 return 0; 149 return 0;