Re: Order of files with 'cp'

From: Brian Candler <B.Candler_at_pobox.com>
Date: Sun, 20 Nov 2005 20:56:05 +0000
On Sun, Nov 20, 2005 at 09:34:16PM +0200, Giorgos Keramidas wrote:
> qsort() can be 'stable' enough for our purposes if the comparison
> function uses something like this:
> 
>     int
>     compare_int32_t(void *pa, void *pb)
>     {
>         int32_t a, b;
> 
>         assert(pa != NULL && pb != NULL);
>         a = *((int32_t *)pa);
>         b = *((int32_t *)pb);
> 
>         if (a < b && pa != pb)
>             return 1;
>         if (a > b && pa != pb)
>             return -1;
>         return 0;
>     }

Care to explain??

For one thing, I don't think qsort() will ever call its comparison function
with two equal pointers, as that would be a point(er)less thing to do.
Therefore, I can't see why you are testing for pa != pb, since this
condition will always be true. (Also, a < b could never be true if pa == pb).

Secondly, mastercmp() doesn't compare integers, it compares FTS structures.
The comparison function just compares whether one item is a directory and
the other a file. How would you have mastercmp() work instead?

Regards,

Brian.
Received on Sun Nov 20 2005 - 19:56:10 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:48 UTC