From: Philip Homburg Date: Mon, 25 Feb 2008 12:13:30 +0000 (+0000) Subject: Added O_REOPEN, better error handling. X-Git-Tag: v3.1.4~244 X-Git-Url: http://zhaoyanbai.com/repos/icons/static/man.3.ps?a=commitdiff_plain;h=822fcd368df7e20ecd2bc427aa54109d73a9d3f4;p=minix.git Added O_REOPEN, better error handling. --- diff --git a/commands/ibm/playwave.c b/commands/ibm/playwave.c index b369fd741..13c81e2c8 100755 --- a/commands/ibm/playwave.c +++ b/commands/ibm/playwave.c @@ -69,7 +69,7 @@ void usage() void main ( int argc, char *argv[] ) { - int i, audio, file; + int i, r, audio, file; char *buffer, *file_name; unsigned int sign; unsigned int fragment_size; @@ -92,9 +92,9 @@ void main ( int argc, char *argv[] ) else file_name = argv[1]; /* Open DSP */ - if ((audio = open("/dev/audio", O_RDWR)) < 0) + if ((audio = open("/dev/audio", O_RDWR | O_REOPEN)) < 0) { - printf("Cannot open /dev/audio\n"); + printf("Cannot open /dev/audio: %s\n", strerror(errno)); exit(-1); } @@ -196,6 +196,19 @@ void main ( int argc, char *argv[] ) } /* Copy data to DSP */ - write(audio, buffer, fragment_size); + r= write(audio, buffer, fragment_size); + if (r != fragment_size) + { + if (r < 0) + { + fprintf(stderr, "playwave: write to audio device failed: %s\n", + strerror(errno)); + } + else + { + fprintf(stderr, "playwave: partial write %d instead of %d\n", + r, fragment_size); + } + } } }