From: Mark R Bannister <mark-/K+B3afwL8Jt0JrxVvvTASp2UmYkHbXO@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [patch] qsort.3: add qsort_r() function
Date: Mon, 24 Oct 2011 16:03:07 +0100 [thread overview]
Message-ID: <44083.1319468587@proseconsulting.co.uk> (raw)
[-- Attachment #1: Type: text/plain, Size: 2208 bytes --]
Please find attached a patch for the qsort.3 man page from 3.35 to add the
qsort_r() function. I've also copied it inline below.
Best regards,
Mark.
--- qsort.3.old 2011-10-04 07:34:44.000000000 +0100
+++ qsort.3 2011-10-24 16:00:44.000000000 +0100
@@ -28,18 +28,22 @@
.\" 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-10-24, Mark R. Bannister (cambridge-Rn4VEauK+AKRv+LV9MX5uv+2+P5yyue3@public.gmane.orgt)
+.\" to add 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-10-24 "" "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 *));"
+.sp
+.BI "void qsort_r(void *" base ", size_t " nmemb ", size_t " size ,
+.BI " int(*" compar ")(const void *, const void *, void *),"
+.BI " void *" arg ");"
.fi
.SH DESCRIPTION
The
@@ -58,16 +62,34 @@
less than, equal to, or greater than the second.
If two members compare
as equal, their order in the sorted array is undefined.
+.PP
+The
+.BR qsort_r ()
+function is identical to
+.BR qsort ()
+except that the comparison function
+.I compar
+takes a third argument. A pointer is passed to the comparison function via
+.IR arg .
+In this way, the comparison function does not need to use global variables to
+pass through arbitrary arguments, and is therefore re-entrant and safe to
+use in threads.
.SH "RETURN VALUE"
The
.BR qsort ()
-function returns no value.
+and
+.BR qsort_r ()
+functions return no value.
.SH "CONFORMING TO"
-SVr4, 4.3BSD, C89, C99.
+The
+.BR qsort ()
+function conforms to SVr4, 4.3BSD, C89, C99.
.SH NOTES
Library routines suitable for use as the
.I compar
-argument include
+argument to
+.BR qsort ()
+include
.BR alphasort (3)
and
.BR versionsort (3).
[-- Attachment #2: qsort.3.patch --]
[-- Type: application/octet-stream, Size: 1923 bytes --]
--- qsort.3.old 2011-10-04 07:34:44.000000000 +0100
+++ qsort.3 2011-10-24 16:00:44.000000000 +0100
@@ -28,18 +28,22 @@
.\" 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-10-24, Mark R. Bannister (cambridge@users.sourceforge.net)
+.\" to add 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-10-24 "" "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 *));"
+.sp
+.BI "void qsort_r(void *" base ", size_t " nmemb ", size_t " size ,
+.BI " int(*" compar ")(const void *, const void *, void *),"
+.BI " void *" arg ");"
.fi
.SH DESCRIPTION
The
@@ -58,16 +62,34 @@
less than, equal to, or greater than the second.
If two members compare
as equal, their order in the sorted array is undefined.
+.PP
+The
+.BR qsort_r ()
+function is identical to
+.BR qsort ()
+except that the comparison function
+.I compar
+takes a third argument. A pointer is passed to the comparison function via
+.IR arg .
+In this way, the comparison function does not need to use global variables to
+pass through arbitrary arguments, and is therefore re-entrant and safe to
+use in threads.
.SH "RETURN VALUE"
The
.BR qsort ()
-function returns no value.
+and
+.BR qsort_r ()
+functions return no value.
.SH "CONFORMING TO"
-SVr4, 4.3BSD, C89, C99.
+The
+.BR qsort ()
+function conforms to SVr4, 4.3BSD, C89, C99.
.SH NOTES
Library routines suitable for use as the
.I compar
-argument include
+argument to
+.BR qsort ()
+include
.BR alphasort (3)
and
.BR versionsort (3).
reply other threads:[~2011-10-24 15:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=44083.1319468587@proseconsulting.co.uk \
--to=mark-/k+b3afwl8jt0jrxvvvtasp2umykhbxo@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.