@@ -346,7 +346,7 @@ static int write_wav_header(snd_pcm_t *pcm)
sizeof(file->wav_header) ||
write(file->fd, header2, sizeof(header2)) != sizeof(header2)) {
int err = errno;
- SYSERR("Write error.\n");
+ SYSERR("%s write header failed, file data may be corrupt", file->fname);
return -err;
}
return 0;
@@ -381,27 +381,29 @@ static void fixup_wav_header(snd_pcm_t *pcm)
-static void snd_pcm_file_write_bytes(snd_pcm_t *pcm, size_t bytes)
+/* return error code in case write failed */
+static int snd_pcm_file_write_bytes(snd_pcm_t *pcm, size_t bytes)
{
snd_pcm_file_t *file = pcm->private_data;
+ snd_pcm_sframes_t err = 0;
assert(bytes <= file->wbuf_used_bytes);
if (file->format == SND_PCM_FILE_FORMAT_WAV &&
!file->wav_header.fmt) {
- if (write_wav_header(pcm) < 0)
- return;
+ err = write_wav_header(pcm);
+ if (err < 0)
+ return err;
}
while (bytes > 0) {
- snd_pcm_sframes_t err;
size_t n = bytes;
size_t cont = file->wbuf_size_bytes - file->file_ptr_bytes;
if (n > cont)
n = cont;
err = write(file->fd, file->wbuf + file->file_ptr_bytes, n);
if (err < 0) {
- SYSERR("write failed");
- break;
+ SYSERR("%s write failed, file data may be corrupt", file->fname);
+ return err;
}
bytes -= err;
file->wbuf_used_bytes -= err;
@@ -412,15 +414,17 @@ static void snd_pcm_file_write_bytes(snd_pcm_t *pcm, size_t bytes)
if ((snd_pcm_uframes_t)err != n)
break;
}
+ return 0;
}
-static void snd_pcm_file_add_frames(snd_pcm_t *pcm,
- const snd_pcm_channel_area_t *areas,
- snd_pcm_uframes_t offset,
- snd_pcm_uframes_t frames)
+static int snd_pcm_file_add_frames(snd_pcm_t *pcm,
+ const snd_pcm_channel_area_t *areas,
+ snd_pcm_uframes_t offset,
+ snd_pcm_uframes_t frames)
{
snd_pcm_file_t *file = pcm->private_data;
while (frames > 0) {
+ int err = 0;
snd_pcm_uframes_t n = frames;
snd_pcm_uframes_t cont = file->wbuf_size - file->appl_ptr;
snd_pcm_uframes_t avail = file->wbuf_size - snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes);
@@ -437,10 +441,14 @@ static void snd_pcm_file_add_frames(snd_pcm_t *pcm,
if (file->appl_ptr == file->wbuf_size)
file->appl_ptr = 0;
file->wbuf_used_bytes += snd_pcm_frames_to_bytes(pcm, n);
- if (file->wbuf_used_bytes > file->buffer_bytes)
- snd_pcm_file_write_bytes(pcm, file->wbuf_used_bytes - file->buffer_bytes);
+ if (file->wbuf_used_bytes > file->buffer_bytes) {
+ err = snd_pcm_file_write_bytes(pcm, file->wbuf_used_bytes - file->buffer_bytes);
+ if (err < 0)
+ return err;
+ }
assert(file->wbuf_used_bytes < file->wbuf_size_bytes);
}
+ return 0;
}
static int snd_pcm_file_close(snd_pcm_t *pcm)