From: busybox Dominique Martinet
> Sent: 16 November 2022 02:53
> 
> From: Dominique Martinet <[email protected]>
> 
> sed would currently not error if write failed when modifying a file.
....
> diff --git a/editors/sed.c b/editors/sed.c
> index 32a4b61f6d4c..31ade17477ca 100644
> --- a/editors/sed.c
> +++ b/editors/sed.c
> @@ -1639,7 +1639,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
>  fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid);
> 
>  process_files();
> -fclose(G.nonstdout);
> +if (fclose(G.nonstdout)) {
> +xfunc_error_retval = 4;  /* It's what gnu sed exits with... */
> +bb_simple_error_msg_and_die(bb_msg_write_error);
> +}
>  G.nonstdout = stdout;

Does that report an error if there is nothing currently buffered?
I think the best sequence is:

        fflush(G.nonstdout);
        if (ferror(G.nonstdout)) {
                xfunc_error_retval = 4;  /* It's what gnu sed exits with... */
                bb_simple_error_msg_and_die(bb_msg_write_error);
        }
        fclose(G.nonstdout);
        G.nonstdout = stdout;

        David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to