From nobody@FreeBSD.org  Sat Feb 16 17:50:31 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 44F76B06
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Feb 2013 17:50:31 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 212FC6DE
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Feb 2013 17:50:31 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r1GHoU4t018084
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Feb 2013 17:50:30 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r1GHoUDv018083;
	Sat, 16 Feb 2013 17:50:30 GMT
	(envelope-from nobody)
Message-Id: <201302161750.r1GHoUDv018083@red.freebsd.org>
Date: Sat, 16 Feb 2013 17:50:30 GMT
From: Fernando <fapesteguia@opensistemas.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] Add example to qsort.3
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         176197
>Category:       docs
>Synopsis:       [PATCH] Add example to qsort.3
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    keramida
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 16 18:00:00 UTC 2013
>Closed-Date:    Mon Feb 25 19:10:38 UTC 2013
>Last-Modified:  Mon Feb 25 19:10:38 UTC 2013
>Originator:     Fernando
>Release:        9.0-RELEASE
>Organization:
Open Sistemas
>Environment:
FreeBSD hammer 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
qsort(3) lacks an example in the man page. If we want to have the best documentation available, we need examples in some man pages.
>How-To-Repeat:
man qsort

It doesn't show an example of use
>Fix:
Apply the attached patch.

Patch attached with submission follows:

--- lib/libc/stdlib/qsort.3	2012-01-03 04:26:05.000000000 +0100
+++ /home/fernape/Programming/FreeBSD/qsort_man/qsort.3	2013-02-16 18:42:44.000000000 +0100
@@ -211,6 +211,52 @@
 did not permit the comparison routine itself to call
 .Fn qsort 3 .
 This is no longer true.
+.Sh EXAMPLES
+Sort an array of integers.
+.Bd -literal
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Custom comparison function
+ */
+static int
+str_compare(const void *p1, const void *p2)
+{
+
+	/* Cast and dereference */
+	if (*(int *)p1 < *(int *)p2)
+		return (-1);
+
+	if (*(int *)p1 > *(int *)p2)
+		return (1);
+
+	return (0);
+
+}
+
+/*
+ * Sort an array of integers
+ */
+int
+main(int argc, char **argv)
+{
+	int i;
+	int int_array[] = {4, 5, 9, 3, 1, 7, 2, 8, 6};
+	const int array_size = sizeof(int_array) / sizeof(int);
+
+	/* Sort array */
+	qsort(&int_array, array_size, sizeof(int), str_compare);
+
+	/* Print out sorted array */
+	for (i = 0; i < array_size; i++) {
+		printf("%d\n", int_array[i]);
+	}
+
+	exit(EXIT_SUCCESS);
+}
+.Ed
 .Sh ERRORS
 The
 .Fn heapsort


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-doc->keramida 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Tue Feb 19 22:53:54 UTC 2013 
Responsible-Changed-Why:  
I'll take care of this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=176197 
State-Changed-From-To: open->patched 
State-Changed-By: keramida 
State-Changed-When: Tue Feb 19 23:20:29 UTC 2013 
State-Changed-Why:  
Fixed in /head with revision 246917. 

I made a few tiny changes to the sample program, 
like rename str_compare to int_compare (since it 
compares int values not strings), and replacing 
the p1/p2 casted duplicates inside the function 
with: 

int *left = (int *)p1; 
int *right = (int *)p2; 

and then using *left/*right in the comparisons. 

Many thanks for the original idea & patch though :-) 


http://www.freebsd.org/cgi/query-pr.cgi?pr=176197 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/176197: commit references a PR
Date: Tue, 19 Feb 2013 23:57:54 +0000 (UTC)

 Author: keramida (doc committer)
 Date: Tue Feb 19 23:57:39 2013
 New Revision: 247014
 URL: http://svnweb.freebsd.org/changeset/base/247014
 
 Log:
   Add a sample program that shows how a custom comparison function and
   qsort(3) can work together to sort an array of integers.
   
   PR:             docs/176197
   Submitted by:   Fernando, fapesteguia at opensistemas.com
   Approved by:    gjb (mentor)
   MFC after:      1 week
 
 Modified:
   head/lib/libc/stdlib/qsort.3
 
 Modified: head/lib/libc/stdlib/qsort.3
 ==============================================================================
 --- head/lib/libc/stdlib/qsort.3	Tue Feb 19 23:46:51 2013	(r247013)
 +++ head/lib/libc/stdlib/qsort.3	Tue Feb 19 23:57:39 2013	(r247014)
 @@ -32,7 +32,7 @@
  .\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
  .\" $FreeBSD$
  .\"
 -.Dd September 30, 2003
 +.Dd February 20, 2013
  .Dt QSORT 3
  .Os
  .Sh NAME
 @@ -211,6 +211,52 @@ Previous versions of
  did not permit the comparison routine itself to call
  .Fn qsort 3 .
  This is no longer true.
 +.Sh EXAMPLES
 +A sample program that sorts an array of
 +.Vt int
 +values in place using
 +.Fn qsort ,
 +and then prints the sorted array to standard output is:
 +.Bd -literal
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
 +/*
 + * Custom comparison function that can compare 'int' values through pointers
 + * passed by qsort(3).
 + */
 +static int
 +int_compare(const void *p1, const void *p2)
 +{
 +        int *left = (int *)p1;
 +        int *right = (int *)p2;
 +
 +        if (*left < *right)
 +                return (-1);
 +        else if (*left > *right)
 +                return (1);
 +        else
 +                return (0);
 +}
 +
 +/*
 + * Sort an array of 'int' values and print it to standard output.
 + */
 +int
 +main(void)
 +{
 +       int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
 +       const int array_size = sizeof(int_array) / sizeof(int_array[0]);
 +       int k;
 +
 +       qsort(&int_array, array_size, sizeof(int), int_compare);
 +       for (k = 0; k < array_size; k++)
 +                printf(" %d", int_array[k]);
 +        printf("\\n");
 +        exit(EXIT_SUCCESS);
 +}
 +.Ed
  .Sh ERRORS
  The
  .Fn heapsort
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= <fernando.apesteguia@gmail.com>
To: bug-followup@FreeBSD.org, fapesteguia@opensistemas.com
Cc:  
Subject: Re: docs/176197: [PATCH] Add example to qsort.3
Date: Wed, 20 Feb 2013 07:52:26 +0100

 Thanks Giorgios for the commit.
 
 I agree with the changes. They improve readability of the code.
 
 I plan to submit more examples for some man pages. In fact I did it
 before this PR, but I forgot to put [PATCH] at the beginning of the
 subject.
 The one I'm talking about is:
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=173448
 
 Could you have a look at it?
 
 Cheers.

From: Christoph Mallon <christoph.mallon@gmx.de>
To: bug-followup@FreeBSD.org, Fernando <fapesteguia@opensistemas.com>, 
 Giorgos Keramidas <keramida@FreeBSD.org>
Cc:  
Subject: Re: docs/176197: [PATCH] Add example to qsort.3
Date: Wed, 20 Feb 2013 11:00:33 +0100

 This is a multi-part message in MIME format.
 --------------090601060300070604060504
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 7bit
 
 Hi,
 
 please have a look at the attached patch, which contains some small improvements for the qsort exmaple.
 
 	Christoph
 
 --------------090601060300070604060504
 Content-Type: text/plain; charset=UTF-8;
  name="0001-stdlib-Improve-qsort-3-example.patch"
 Content-Transfer-Encoding: base64
 Content-Disposition: attachment;
  filename="0001-stdlib-Improve-qsort-3-example.patch"
 
 RnJvbSA2NzQ2YmFkMWE2YTBhNzJjNTg1ODA5ZTVhYWQzNjFiOTQ2NzAzNWY4IE1vbiBTZXAg
 MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBDaHJpc3RvcGggTWFsbG9uIDxjaHJpc3RvcGgubWFs
 bG9uQGdteC5kZT4KRGF0ZTogV2VkLCAyMCBGZWIgMjAxMyAwOTo1Mjo1NiArMDEwMApTdWJq
 ZWN0OiBbUEFUQ0hdIHN0ZGxpYjogSW1wcm92ZSBxc29ydCgzKSBleGFtcGxlLgoKLSBSZW1v
 dmUgdW51c2VkICNpbmNsdWRlLgotIERvIG5vdCBjYXN0IGF3YXkgY29uc3QuCi0gVXNlIHRo
 ZSBjYW5vbmljYWwgaWRpb20gdG8gY29tcGFyZSB0d28gbnVtYmVycy4KLSBVc2UgcHJvcGVy
 IHR5cGUgZm9yIHNpemVzLCBpLmUuIHNpemVfdCBpbnN0ZWFkIG9mIGludC4KLSBDb3JyZWN0
 IGluZGVudGF0aW9uLgotIFNpbXBsaWZ5IHByaW50ZigiXG4iKSB0byBwdXRzKCIiKS4KLSBV
 c2UgcmV0dXJuIGluc3RlYWQgb2YgZXhpdCgpIGluIG1haW4oKS4KLS0tCiBsaWIvbGliYy9z
 dGRsaWIvcXNvcnQuMyB8IDIyICsrKysrKysrLS0tLS0tLS0tLS0tLS0KIDEgZmlsZSBjaGFu
 Z2VkLCA4IGluc2VydGlvbnMoKyksIDE0IGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL2xp
 Yi9saWJjL3N0ZGxpYi9xc29ydC4zIGIvbGliL2xpYmMvc3RkbGliL3Fzb3J0LjMKaW5kZXgg
 ODNkOTE0MC4uOTViNDI0OCAxMDA2NDQKLS0tIGEvbGliL2xpYmMvc3RkbGliL3Fzb3J0LjMK
 KysrIGIvbGliL2xpYmMvc3RkbGliL3Fzb3J0LjMKQEAgLTIyMCw3ICsyMjAsNiBAQCBhbmQg
 dGhlbiBwcmludHMgdGhlIHNvcnRlZCBhcnJheSB0byBzdGFuZGFyZCBvdXRwdXQgaXM6CiAu
 QmQgLWxpdGVyYWwKICNpbmNsdWRlIDxzdGRpby5oPgogI2luY2x1ZGUgPHN0ZGxpYi5oPgot
 I2luY2x1ZGUgPHN0cmluZy5oPgogCiAvKgogICogQ3VzdG9tIGNvbXBhcmlzb24gZnVuY3Rp
 b24gdGhhdCBjYW4gY29tcGFyZSAnaW50JyB2YWx1ZXMgdGhyb3VnaCBwb2ludGVycwpAQCAt
 MjI5LDE1ICsyMjgsMTAgQEAgYW5kIHRoZW4gcHJpbnRzIHRoZSBzb3J0ZWQgYXJyYXkgdG8g
 c3RhbmRhcmQgb3V0cHV0IGlzOgogc3RhdGljIGludAogaW50X2NvbXBhcmUoY29uc3Qgdm9p
 ZCAqcDEsIGNvbnN0IHZvaWQgKnAyKQogewotICAgICAgICBpbnQgKmxlZnQgPSAoaW50ICop
 cDE7Ci0gICAgICAgIGludCAqcmlnaHQgPSAoaW50ICopcDI7CisgICAgICAgIGludCBsZWZ0
 ICA9ICooY29uc3QgaW50ICopcDE7CisgICAgICAgIGludCByaWdodCA9ICooY29uc3QgaW50
 ICopcDI7CiAKLSAgICAgICAgaWYgKCpsZWZ0IDwgKnJpZ2h0KQotICAgICAgICAgICAgICAg
 IHJldHVybiAoLTEpOwotICAgICAgICBlbHNlIGlmICgqbGVmdCA+ICpyaWdodCkKLSAgICAg
 ICAgICAgICAgICByZXR1cm4gKDEpOwotICAgICAgICBlbHNlCi0gICAgICAgICAgICAgICAg
 cmV0dXJuICgwKTsKKyAgICAgICAgcmV0dXJuICgobGVmdCA+IHJpZ2h0KSAtIChsZWZ0IDwg
 cmlnaHQpKTsKIH0KIAogLyoKQEAgLTI0NywxNCArMjQxLDE0IEBAIGludAogbWFpbih2b2lk
 KQogewogICAgICAgIGludCBpbnRfYXJyYXlbXSA9IHsgNCwgNSwgOSwgMywgMCwgMSwgNywg
 MiwgOCwgNiB9OwotICAgICAgIGNvbnN0IGludCBhcnJheV9zaXplID0gc2l6ZW9mKGludF9h
 cnJheSkgLyBzaXplb2YoaW50X2FycmF5WzBdKTsKLSAgICAgICBpbnQgazsKKyAgICAgICBj
 b25zdCBzaXplX3QgYXJyYXlfc2l6ZSA9IHNpemVvZihpbnRfYXJyYXkpIC8gc2l6ZW9mKGlu
 dF9hcnJheVswXSk7CisgICAgICAgc2l6ZV90IGs7CiAKLSAgICAgICBxc29ydCgmaW50X2Fy
 cmF5LCBhcnJheV9zaXplLCBzaXplb2YoaW50KSwgaW50X2NvbXBhcmUpOworICAgICAgIHFz
 b3J0KCZpbnRfYXJyYXksIGFycmF5X3NpemUsIHNpemVvZihpbnRfYXJyYXlbMF0pLCBpbnRf
 Y29tcGFyZSk7CiAgICAgICAgZm9yIChrID0gMDsgayA8IGFycmF5X3NpemU7IGsrKykKICAg
 ICAgICAgICAgICAgICBwcmludGYoIiAlZCIsIGludF9hcnJheVtrXSk7Ci0gICAgICAgIHBy
 aW50ZigiXFxuIik7Ci0gICAgICAgIGV4aXQoRVhJVF9TVUNDRVNTKTsKKyAgICAgICBwdXRz
 KCIiKTsKKyAgICAgICByZXR1cm4gKEVYSVRfU1VDQ0VTUyk7CiB9CiAuRWQKIC5TaCBFUlJP
 UlMKLS0gCjEuOC4xLjMKCg==
 --------------090601060300070604060504--

From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= <fernando.apesteguia@gmail.com>
To: bug-followup@FreeBSD.org, fapesteguia@opensistemas.com
Cc:  
Subject: Re: docs/176197: [PATCH] Add example to qsort.3
Date: Wed, 20 Feb 2013 12:12:25 +0100

 I would apply the patch especially because the cast away of constness
 in the pointers.
 Though it is a common idiom, I would rather keep the two if statements
 instead of the single return line. As this is an example I think it is
 clearer that way.
 
 Cheers.

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/176197: commit references a PR
Date: Sat, 23 Feb 2013 12:32:04 +0000 (UTC)

 Author: keramida (doc committer)
 Date: Sat Feb 23 12:31:52 2013
 New Revision: 247189
 URL: http://svnweb.freebsd.org/changeset/base/247189
 
 Log:
   Now that qsort(3) has a sample comparison function, point to that
   example from bsearch(3) too, so that we don't have to duplicate
   the example code in both places.
   
   PR:		docs/176197
   Reviewed by:	stefanf
   Approved by:	remko (mentor), gjb (mentor)
   MFC after:	1 week
 
 Modified:
   head/lib/libc/stdlib/bsearch.3
 
 Modified: head/lib/libc/stdlib/bsearch.3
 ==============================================================================
 --- head/lib/libc/stdlib/bsearch.3	Sat Feb 23 12:00:51 2013	(r247188)
 +++ head/lib/libc/stdlib/bsearch.3	Sat Feb 23 12:31:52 2013	(r247189)
 @@ -32,7 +32,7 @@
  .\"     @(#)bsearch.3	8.3 (Berkeley) 4/19/94
  .\" $FreeBSD$
  .\"
 -.Dd April 19, 1994
 +.Dd February 22, 2013
  .Dt BSEARCH 3
  .Os
  .Sh NAME
 @@ -71,6 +71,12 @@ less than, equal to, or greater than zer
  .Fa key
  object is found, respectively, to be less than, to match, or be
  greater than the array member.
 +See the
 +.Fa int_compare
 +sample function in
 +.Xr qsort 3
 +for a comparison function that is also compatible with
 +.Fn bsearch .
  .Sh RETURN VALUES
  The
  .Fn bsearch
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/176197: commit references a PR
Date: Mon, 25 Feb 2013 19:09:51 +0000 (UTC)

 Author: keramida (doc committer)
 Date: Mon Feb 25 19:09:41 2013
 New Revision: 247277
 URL: http://svnweb.freebsd.org/changeset/base/247277
 
 Log:
   MFH r247014, r247050 and r247051.
   
   Add a sample program that shows how a custom comparison function and
   qsort(3) can work together to sort an array of integers.
   
   PR:             docs/176197
   Submitted by:   Fernando, fapesteguia at opensistemas.com
   		Christoph Mallon, christoph.mallon at gmx.de
   Approved by:    gjb (mentor), remko (mentor)
 
 Modified:
   stable/7/lib/libc/stdlib/qsort.3
 Directory Properties:
   stable/7/lib/libc/   (props changed)
 
 Modified: stable/7/lib/libc/stdlib/qsort.3
 ==============================================================================
 --- stable/7/lib/libc/stdlib/qsort.3	Mon Feb 25 19:09:13 2013	(r247276)
 +++ stable/7/lib/libc/stdlib/qsort.3	Mon Feb 25 19:09:41 2013	(r247277)
 @@ -32,7 +32,7 @@
  .\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
  .\" $FreeBSD$
  .\"
 -.Dd September 30, 2003
 +.Dd February 20, 2013
  .Dt QSORT 3
  .Os
  .Sh NAME
 @@ -205,6 +205,46 @@ functions
  return no value.
  .Pp
  .Rv -std heapsort mergesort
 +.Sh EXAMPLES
 +A sample program that sorts an array of
 +.Vt int
 +values in place using
 +.Fn qsort ,
 +and then prints the sorted array to standard output is:
 +.Bd -literal
 +#include <stdio.h>
 +#include <stdlib.h>
 +
 +/*
 + * Custom comparison function that can compare 'int' values through pointers
 + * passed by qsort(3).
 + */
 +static int
 +int_compare(const void *p1, const void *p2)
 +{
 +        int left = *(const int *)p1;
 +        int right = *(const int *)p2;
 +
 +        return ((left > right) - (left < right));
 +}
 +
 +/*
 + * Sort an array of 'int' values and print it to standard output.
 + */
 +int
 +main(void)
 +{
 +       int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
 +       const size_t array_size = sizeof(int_array) / sizeof(int_array[0]);
 +       size_t k;
 +
 +       qsort(&int_array, array_size, sizeof(int_array[0]), int_compare);
 +       for (k = 0; k < array_size; k++)
 +                printf(" %d", int_array[k]);
 +        puts("");
 +        return (EXIT_SUCCESS);
 +}
 +.Ed
  .Sh COMPATIBILITY
  Previous versions of
  .Fn qsort
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/176197: commit references a PR
Date: Mon, 25 Feb 2013 19:08:55 +0000 (UTC)

 Author: keramida (doc committer)
 Date: Mon Feb 25 19:08:46 2013
 New Revision: 247275
 URL: http://svnweb.freebsd.org/changeset/base/247275
 
 Log:
   MFH r247014, r247050 and r247051.
   
   Add a sample program that shows how a custom comparison function and
   qsort(3) can work together to sort an array of integers.
   
   PR:             docs/176197
   Submitted by:   Fernando, fapesteguia at opensistemas.com
   		Christoph Mallon, christoph.mallon at gmx.de
   Approved by:    gjb (mentor), remko (mentor)
 
 Modified:
   stable/9/lib/libc/stdlib/qsort.3
 Directory Properties:
   stable/9/lib/libc/   (props changed)
 
 Modified: stable/9/lib/libc/stdlib/qsort.3
 ==============================================================================
 --- stable/9/lib/libc/stdlib/qsort.3	Mon Feb 25 19:05:40 2013	(r247274)
 +++ stable/9/lib/libc/stdlib/qsort.3	Mon Feb 25 19:08:46 2013	(r247275)
 @@ -32,7 +32,7 @@
  .\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
  .\" $FreeBSD$
  .\"
 -.Dd September 30, 2003
 +.Dd February 20, 2013
  .Dt QSORT 3
  .Os
  .Sh NAME
 @@ -205,6 +205,46 @@ functions
  return no value.
  .Pp
  .Rv -std heapsort mergesort
 +.Sh EXAMPLES
 +A sample program that sorts an array of
 +.Vt int
 +values in place using
 +.Fn qsort ,
 +and then prints the sorted array to standard output is:
 +.Bd -literal
 +#include <stdio.h>
 +#include <stdlib.h>
 +
 +/*
 + * Custom comparison function that can compare 'int' values through pointers
 + * passed by qsort(3).
 + */
 +static int
 +int_compare(const void *p1, const void *p2)
 +{
 +        int left = *(const int *)p1;
 +        int right = *(const int *)p2;
 +
 +        return ((left > right) - (left < right));
 +}
 +
 +/*
 + * Sort an array of 'int' values and print it to standard output.
 + */
 +int
 +main(void)
 +{
 +       int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
 +       const size_t array_size = sizeof(int_array) / sizeof(int_array[0]);
 +       size_t k;
 +
 +       qsort(&int_array, array_size, sizeof(int_array[0]), int_compare);
 +       for (k = 0; k < array_size; k++)
 +                printf(" %d", int_array[k]);
 +        puts("");
 +        return (EXIT_SUCCESS);
 +}
 +.Ed
  .Sh COMPATIBILITY
  Previous versions of
  .Fn qsort
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/176197: commit references a PR
Date: Mon, 25 Feb 2013 19:09:31 +0000 (UTC)

 Author: keramida (doc committer)
 Date: Mon Feb 25 19:09:13 2013
 New Revision: 247276
 URL: http://svnweb.freebsd.org/changeset/base/247276
 
 Log:
   MFH r247014, r247050 and r247051.
   
   Add a sample program that shows how a custom comparison function and
   qsort(3) can work together to sort an array of integers.
   
   PR:             docs/176197
   Submitted by:   Fernando, fapesteguia at opensistemas.com
   		Christoph Mallon, christoph.mallon at gmx.de
   Approved by:    gjb (mentor), remko (mentor)
 
 Modified:
   stable/8/lib/libc/stdlib/qsort.3
 Directory Properties:
   stable/8/lib/libc/   (props changed)
 
 Modified: stable/8/lib/libc/stdlib/qsort.3
 ==============================================================================
 --- stable/8/lib/libc/stdlib/qsort.3	Mon Feb 25 19:08:46 2013	(r247275)
 +++ stable/8/lib/libc/stdlib/qsort.3	Mon Feb 25 19:09:13 2013	(r247276)
 @@ -32,7 +32,7 @@
  .\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
  .\" $FreeBSD$
  .\"
 -.Dd September 30, 2003
 +.Dd February 20, 2013
  .Dt QSORT 3
  .Os
  .Sh NAME
 @@ -205,6 +205,46 @@ functions
  return no value.
  .Pp
  .Rv -std heapsort mergesort
 +.Sh EXAMPLES
 +A sample program that sorts an array of
 +.Vt int
 +values in place using
 +.Fn qsort ,
 +and then prints the sorted array to standard output is:
 +.Bd -literal
 +#include <stdio.h>
 +#include <stdlib.h>
 +
 +/*
 + * Custom comparison function that can compare 'int' values through pointers
 + * passed by qsort(3).
 + */
 +static int
 +int_compare(const void *p1, const void *p2)
 +{
 +        int left = *(const int *)p1;
 +        int right = *(const int *)p2;
 +
 +        return ((left > right) - (left < right));
 +}
 +
 +/*
 + * Sort an array of 'int' values and print it to standard output.
 + */
 +int
 +main(void)
 +{
 +       int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
 +       const size_t array_size = sizeof(int_array) / sizeof(int_array[0]);
 +       size_t k;
 +
 +       qsort(&int_array, array_size, sizeof(int_array[0]), int_compare);
 +       for (k = 0; k < array_size; k++)
 +                printf(" %d", int_array[k]);
 +        puts("");
 +        return (EXIT_SUCCESS);
 +}
 +.Ed
  .Sh COMPATIBILITY
  Previous versions of
  .Fn qsort
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: keramida 
State-Changed-When: Mon Feb 25 19:10:11 UTC 2013 
State-Changed-Why:  
Merged to stable/9 stable/8 and stable/7 branches.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=176197 
>Unformatted:
