Date: Sun, 20 Nov 2005 21:34:16 +0200 From: Giorgos Keramidas <keramida@hellug.gr> To: Tim Kientzle <kientzle@freebsd.org> Cc: freebsd-current@freebsd.org, Brian Candler <B.Candler@pobox.com> Subject: Re: Order of files with 'cp' Message-ID: <20051120193416.GB1599@flame.pc> In-Reply-To: <437F7E22.5050800@freebsd.org> References: <20051116161540.GB4383@uk.tiscali.com> <437F7E22.5050800@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-11-19 11:33, Tim Kientzle <kientzle@freebsd.org> wrote:
> Brian Candler wrote:
> >I've noticed on FreeBSD-5.4 and -6.0 that the order in which 'cp'
> >copies multiple files does not match the order they're given on the
> >command line.
> ...
> >I've had a look through the code, and it seems that cp calls
> >fts_open() with the list of files in argv; fts_open then does a
> >qsort() on the arguments, using the comparison function mastercmp()
> >provided by cp:
>
> My suggestion: Have 'cp' call fts_open once for each command-line
> argument, instead of giving fts_open the entire argv list to muck
> with.
>
> Requires faking up an argv array for each single item, but that will
> be a lot easier than trying to fix fts.
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;
}
Perhaps we can use that, instead of calling fts_open() once for each
command-line argument?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051120193416.GB1599>
