Pádraig Brady <[email protected]> writes:

> On 25/12/2025 12:07, Pádraig Brady wrote:
>> On 25/12/2025 06:42, Collin Funk wrote:
>>> So, based on my interpretation, when this ftruncate fails the output
>>> file, if it exists, should not be modified, since it occurs before the
>>> copy.
>>>
>>> This v2 patch also checks for that behavior. I will leave it a bit for
>>> review.
>> +1
>
> Actually the | operator doesn't guaranteed order, so
> this will have to be done in independent steps:
>
>   int exit_status = dd_copy () | synchronize_output ();

Oh, nice catch. From C23 § 6.5.15:

    Unlike the bitwise | operator, the || operator guarantees
    left-to-right evaluation; if the second operand is evaluated, there
    is a sequence point between the evaluations of the first and second
    operands. If the first operand compares unequal to 0, the second
    operand is not evaluated

I pushed it with:

    int copy_status = dd_copy ();
    int sync_status = synchronize_output ();
    int exit_status = copy_status | sync_status;

which probably looks better anyways [1].

Collin

[1] 
https://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commit;h=b12593d1249b3369a177bc84c93f54239b965e4a

Reply via email to