From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH] aplay: Introduce and use xwrite helper Date: Fri, 07 Apr 2017 20:41:08 +0200 Message-ID: References: <1491579340-29277-1-git-send-email-daniel.baluta@nxp.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 72FA626686A for ; Fri, 7 Apr 2017 20:41:09 +0200 (CEST) In-Reply-To: <1491579340-29277-1-git-send-email-daniel.baluta@nxp.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Daniel Baluta Cc: alsa-devel@alsa-project.org, shengjiu.wang@nxp.com, o-takashi@sakamocchi.jp, broonie@kernel.org, viorel.suman@nxp.com, mihai.serban@nxp.com List-Id: alsa-devel@alsa-project.org 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 > --- > 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