On Fri, 07 Apr 2017 17:35:40 +0200, Daniel Baluta wrote: > > Write can return less then requested bytes, but we treat this as > an error thus ending up with confusing error messages. > > Fix this by introducing xwrite helper, which makes sure all bytes > are written or an error is returned. > > With this patch an usecase where disk is filled by recording will > print: > $ /mnt/msc/audio.wav: No space left on device > > instead of random messages like: > > $/mnt/msc/audio.wav: No such file or directory > > Signed-off-by: Daniel Baluta <daniel.baluta@xxxxxxx> > --- > This is a follow up of: > > http://mailman.alsa-project.org/pipermail/alsa-devel/2017-April/119632.html > > where I tried to fix the error message instead of write :). > > aplay/aplay.c | 55 +++++++++++++++++++++++++++++++++++++------------------ > 1 file changed, 37 insertions(+), 18 deletions(-) > > diff --git a/aplay/aplay.c b/aplay/aplay.c > index ee480f2..74d3d37 100644 > --- a/aplay/aplay.c > +++ b/aplay/aplay.c > @@ -429,6 +429,25 @@ enum { > OPT_FATAL_ERRORS, > }; > > +/* > + * make sure we write all bytes or return an error > + */ > +static ssize_t xwrite(int fd, const void *buf, size_t count) > +{ > + ssize_t written; > + size_t offset = 0; > + > + while (offset < count) { > + written = write(fd, buf + offset, count - offset); > + if (written <= 0) > + return written; > + > + offset += written; > + }; > + > + return written; This will return a partial written size. Return "offset" instead. thanks, Takashi _______________________________________________ Alsa-devel mailing list Alsa-devel@xxxxxxxxxxxxxxxx http://mailman.alsa-project.org/mailman/listinfo/alsa-devel