Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/usr.bin/patch



On Sun, Aug 10, 2008 at 10:36:23PM +0000, Greg Troxel wrote:
> 
> Module Name:  src
> Committed By: gdt
> Date:         Sun Aug 10 22:36:23 UTC 2008
> 
> Modified Files:
>       src/usr.bin/patch: patch.c
> 
> Log Message:
> Add error checking to use of fputs in creating output file in
> temprorary directory.  Previously, fputs was used without checking the
> return value, leading to silent truncation when the temporary
> filesystem was full (such as can easily happen when migrating to
> tmpfs).

You probably don't want to (or need to) check the return code from fputs().
Better is to to close the file with the sequence:

        fflush(outfile);
        err = ferror(outfile);
        fclose(outfile);
        if (err != 0)
                ...

Since the 'error bit' is sticky, and the write error might not happen
until the last buffer is written to disk during fclose().
It also simplifies the logic somewhat.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index