From owner-freebsd-current@FreeBSD.ORG Sun Nov 20 20:56:10 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 43A3716A41F; Sun, 20 Nov 2005 20:56:10 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from orb.pobox.com (orb.pobox.com [207.8.226.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id DD15B43D46; Sun, 20 Nov 2005 20:56:09 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from orb (localhost [127.0.0.1]) by orb.pobox.com (Postfix) with ESMTP id 0E84F5AD; Sun, 20 Nov 2005 15:56:31 -0500 (EST) Received: from mappit.local.linnet.org (212-74-113-67.static.dsl.as9105.com [212.74.113.67]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by orb.sasl.smtp.pobox.com (Postfix) with ESMTP id C75348A; Sun, 20 Nov 2005 15:56:28 -0500 (EST) Received: from brian by mappit.local.linnet.org with local (Exim 4.54 (FreeBSD)) id 1EdwEH-00059w-Al; Sun, 20 Nov 2005 20:56:05 +0000 Date: Sun, 20 Nov 2005 20:56:05 +0000 From: Brian Candler To: Giorgos Keramidas Message-ID: <20051120205605.GB19791@uk.tiscali.com> References: <20051116161540.GB4383@uk.tiscali.com> <437F7E22.5050800@freebsd.org> <20051120193416.GB1599@flame.pc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051120193416.GB1599@flame.pc> User-Agent: Mutt/1.4.2.1i Cc: Tim Kientzle , freebsd-current@freebsd.org 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 20:56:10 -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.