From: Ben <software-QW8DL1zPdzBaa/9Udqfwiw@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [patch] qsort.3: document qsort_r
Date: Thu, 29 Dec 2011 20:50:25 +0000 [thread overview]
Message-ID: <1325191825.10184.6.camel@tinky> (raw)
[-- Attachment #1: Type: text/plain, Size: 2410 bytes --]
Following a discussion on comp.lang.c, I noticed that glibc's qsort_r is
not documented in the man pages. Following the model of strtok_r (and
the FIXME in qsort.3) I include a patch that adds qsort_r to the man
page for qsort (inline and as an attachment):
--- qsort.3.orig 2011-12-29 16:12:51.000000000 +0000
+++ qsort.3 2011-12-29 15:30:33.000000000 +0000
@@ -28,19 +28,32 @@
.\" Modified 1993-03-29, David Metcalfe
.\" Modified 1993-07-24, Rik Faith (faith-+5Oa3zvhR2o3uPMLIKxrzw@public.gmane.org)
.\" 2006-01-15, mtk, Added example program.
+.\" Modified 2011-12-29, Ben Bacarisse (software-QW8DL1zPdzBaa/9Udqfwiw@public.gmane.org), qsort_r
.\"
-.\" FIXME glibc 2.8 added qsort_r(), which needs to be documented.
-.\"
-.TH QSORT 3 2009-09-15 "" "Linux Programmer's Manual"
+.TH QSORT 3 2011-12-29 "" "Linux Programmer's Manual"
.SH NAME
-qsort \- sorts an array
+qsort, qsort_r \- sorts an array
.SH SYNOPSIS
.nf
.B #include <stdlib.h>
.sp
.BI "void qsort(void *" base ", size_t " nmemb ", size_t " size ,
-.BI " int(*" compar ")(const void *, const void *));"
+.BI " int (*" compar ")(const void *, const void *));"
+.sp
+.BI "void qsort_r(void *" base ", size_t " nmemb ", size_t " size ,
+.BI " int (*" compar ")(const void *, const void *, void
*),"
+.BI " void *" data ");"
.fi
+.sp
+.in -4n
+Feature Test Macro Requirements for glibc (see
+.BR feature_test_macros (7)):
+.in
+.sp
+.ad l
+.BR qsort_r ():
+_GNU_SOURCE
+.ad b
.SH DESCRIPTION
The
.BR qsort ()
@@ -58,12 +71,29 @@
less than, equal to, or greater than the second.
If two members compare
as equal, their order in the sorted array is undefined.
+
+.BR qsort_r ()
+permits a pointer to an arbitrary piece of data to be passed to the
+comparisson function.
+The \fIdata\fP argument to
+.BR qsort_r ()
+is passed as the third argument in every call to \fIcompar\fP.
.SH "RETURN VALUE"
The
.BR qsort ()
-function returns no value.
+and
+.BR qsort_r ()
+functions return no value.
.SH "CONFORMING TO"
+.TP
+.BR qsort ()
SVr4, 4.3BSD, C89, C99.
+.TP
+.BR qsort_r ()
+is a GNU extension. Note that the argument order and the type of the
+comparison function are different to that used by BSD's
+.BR qsort_r ()
+function.
.SH NOTES
Library routines suitable for use as the
.I compar
--
Ben.
[-- Attachment #2: qsort_r.patch --]
[-- Type: text/x-patch, Size: 2070 bytes --]
--- qsort.3.orig 2011-12-29 16:12:51.000000000 +0000
+++ qsort.3 2011-12-29 15:30:33.000000000 +0000
@@ -28,19 +28,32 @@
.\" Modified 1993-03-29, David Metcalfe
.\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
.\" 2006-01-15, mtk, Added example program.
+.\" Modified 2011-12-29, Ben Bacarisse (software@bsb.me.uk), qsort_r
.\"
-.\" FIXME glibc 2.8 added qsort_r(), which needs to be documented.
-.\"
-.TH QSORT 3 2009-09-15 "" "Linux Programmer's Manual"
+.TH QSORT 3 2011-12-29 "" "Linux Programmer's Manual"
.SH NAME
-qsort \- sorts an array
+qsort, qsort_r \- sorts an array
.SH SYNOPSIS
.nf
.B #include <stdlib.h>
.sp
.BI "void qsort(void *" base ", size_t " nmemb ", size_t " size ,
-.BI " int(*" compar ")(const void *, const void *));"
+.BI " int (*" compar ")(const void *, const void *));"
+.sp
+.BI "void qsort_r(void *" base ", size_t " nmemb ", size_t " size ,
+.BI " int (*" compar ")(const void *, const void *, void *),"
+.BI " void *" data ");"
.fi
+.sp
+.in -4n
+Feature Test Macro Requirements for glibc (see
+.BR feature_test_macros (7)):
+.in
+.sp
+.ad l
+.BR qsort_r ():
+_GNU_SOURCE
+.ad b
.SH DESCRIPTION
The
.BR qsort ()
@@ -58,12 +71,29 @@
less than, equal to, or greater than the second.
If two members compare
as equal, their order in the sorted array is undefined.
+
+.BR qsort_r ()
+permits a pointer to an arbitrary piece of data to be passed to the
+comparisson function.
+The \fIdata\fP argument to
+.BR qsort_r ()
+is passed as the third argument in every call to \fIcompar\fP.
.SH "RETURN VALUE"
The
.BR qsort ()
-function returns no value.
+and
+.BR qsort_r ()
+functions return no value.
.SH "CONFORMING TO"
+.TP
+.BR qsort ()
SVr4, 4.3BSD, C89, C99.
+.TP
+.BR qsort_r ()
+is a GNU extension. Note that the argument order and the type of the
+comparison function are different to that used by BSD's
+.BR qsort_r ()
+function.
.SH NOTES
Library routines suitable for use as the
.I compar
next reply other threads:[~2011-12-29 20:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-29 20:50 Ben [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-01-03 12:11 [patch] qsort.3: document qsort_r Mark R Bannister
[not found] ` <55128.1325592712-/K+B3afwL8Jt0JrxVvvTASp2UmYkHbXO@public.gmane.org>
2012-03-05 19:00 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkhgUnrHnxhOhjL8+tH=Msq_+ASgqvzWAwHc5+TpqOzx7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-05 21:55 ` Ben
[not found] ` <1330984528.3439.13.camel-P4ps6/jurk3DOqzlkpFKJg@public.gmane.org>
2012-03-07 21:40 ` Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1325191825.10184.6.camel@tinky \
--to=software-qw8dl1zpdzbaa/9udqfwiw@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).