From: Takashi Iwai <tiwai@suse.de>
To: Daniel Baluta <daniel.baluta@nxp.com>
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
Subject: Re: [PATCH] aplay: Introduce and use xwrite helper
Date: Fri, 07 Apr 2017 20:41:08 +0200 [thread overview]
Message-ID: <s5h37dk83i3.wl-tiwai@suse.de> (raw)
In-Reply-To: <1491579340-29277-1-git-send-email-daniel.baluta@nxp.com>
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@nxp.com>
> ---
> 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
prev parent reply other threads:[~2017-04-07 18:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-07 15:35 [PATCH] aplay: Introduce and use xwrite helper Daniel Baluta
2017-04-07 18:41 ` Takashi Iwai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=s5h37dk83i3.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=mihai.serban@nxp.com \
--cc=o-takashi@sakamocchi.jp \
--cc=shengjiu.wang@nxp.com \
--cc=viorel.suman@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox