#include #include #include #include #include #include #define AUDIO_FILENO (STDERR_FILENO + 1) int main(void) { fd_set fds; int res, fd; char audiobuf[4096]; if ((fd = open("/tmp/c-audio.raw", O_WRONLY | O_TRUNC | O_CREAT, 660)) < 0) exit(0); for (;;) { FD_ZERO(&fds); FD_SET(AUDIO_FILENO, &fds); if ((res = select(AUDIO_FILENO + 1, &fds, NULL, NULL, NULL)) < 0) { fprintf(stderr, "Error in select: %s\n", strerror(errno)); break; } if (FD_ISSET(AUDIO_FILENO, &fds)) { res = read(AUDIO_FILENO, audiobuf, sizeof(audiobuf)); if (res > 0) { write(fd, audiobuf, res); } } } if (fd > 0) close(fd); exit(0); }