Skip to contentSkip to conversation

qsort.3: add qsort_r() function

PATCH New Mark R Bannister 1 participant 1 message Oct 24, 2011 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qsort.3: add qsort_r() function

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 renamed from qsort.3.old +29 -7
@@ -28,18 +28,22 @@
 .\" Modified 1993-03-29, David Metcalfe
 .\" Modified 1993-07-24, Rik Faith ([email protected])
 .\" 2006-01-15, mtk, Added example program.
+.\" Modified 2011-10-24, Mark R. Bannister ([email protected])
+.\"				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).
qsort.3 renamed from qsort.3.old +29 -7
@@ -28,18 +28,22 @@
 .\" Modified 1993-03-29, David Metcalfe
 .\" Modified 1993-07-24, Rik Faith ([email protected])
 .\" 2006-01-15, mtk, Added example program.
+.\" Modified 2011-10-24, Mark R. Bannister ([email protected])
+.\"				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).