From owner-freebsd-current@FreeBSD.ORG Sun Nov 20 19:49:09 2005 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6A40D16A41F; Sun, 20 Nov 2005 19:49:09 +0000 (GMT) (envelope-from keramida@hellug.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 80C9C43D5D; Sun, 20 Nov 2005 19:49:07 +0000 (GMT) (envelope-from keramida@hellug.gr) Received: from flame.pc (patr530b-0118.otenet.gr [62.103.226.118]) (authenticated bits=0) by igloo.linux.gr (8.13.5/8.13.5/Debian-3) with ESMTP id jAKJmev6007741; Sun, 20 Nov 2005 21:48:42 +0200 Received: by flame.pc (Postfix, from userid 1001) id CFC9E11763; Sun, 20 Nov 2005 21:34:16 +0200 (EET) Date: Sun, 20 Nov 2005 21:34:16 +0200 From: Giorgos Keramidas To: Tim Kientzle Message-ID: <20051120193416.GB1599@flame.pc> References: <20051116161540.GB4383@uk.tiscali.com> <437F7E22.5050800@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <437F7E22.5050800@freebsd.org> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.399, required 5, autolearn=not spam, ALL_TRUSTED -1.80, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@linux.gr X-Mailman-Approved-At: Sun, 20 Nov 2005 20:06:09 +0000 Cc: freebsd-current@freebsd.org, Brian Candler Subject: Re: Order of files with 'cp' X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Nov 2005 19:49:09 -0000 On 2005-11-19 11:33, Tim Kientzle 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?