summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortedu <>2019-01-21 20:43:27 +0000
committertedu <>2019-01-21 20:43:27 +0000
commit84065841685e5f7ac2060a36b85d414fc68882f8 (patch)
treec20ab127dc9ca8177f8a993af01eb188cddb5243
parentc4e4e3af5f876df655f87ec686c99ca0e2f02c5e (diff)
downloadopenbsd-84065841685e5f7ac2060a36b85d414fc68882f8.tar.gz
openbsd-84065841685e5f7ac2060a36b85d414fc68882f8.tar.bz2
openbsd-84065841685e5f7ac2060a36b85d414fc68882f8.zip
a few tweaks
-rw-r--r--src/lib/libc/stdlib/qsort.314
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/qsort.3 b/src/lib/libc/stdlib/qsort.3
index cadfda7961..cbb1ec44d4 100644
--- a/src/lib/libc/stdlib/qsort.3
+++ b/src/lib/libc/stdlib/qsort.3
@@ -29,7 +29,7 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" $OpenBSD: qsort.3,v 1.21 2019/01/21 20:34:14 otto Exp $ 32.\" $OpenBSD: qsort.3,v 1.22 2019/01/21 20:43:27 tedu Exp $
33.\" 33.\"
34.Dd $Mdocdate: January 21 2019 $ 34.Dd $Mdocdate: January 21 2019 $
35.Dt QSORT 3 35.Dt QSORT 3
@@ -180,12 +180,16 @@ char *array[] = { "XX", "YYY", "Z" };
180int 180int
181cmp(const void *a, const void *b) 181cmp(const void *a, const void *b)
182{ 182{
183 /* a and b point to an element of the array */ 183 /*
184 * a and b point to elements of the array.
185 * Cast and dereference to obtain the actual elements,
186 * which are also pointers in this case.
187 */
184 size_t lena = strlen(*(const char **)a); 188 size_t lena = strlen(*(const char **)a);
185 size_t lenb = strlen(*(const char **)b); 189 size_t lenb = strlen(*(const char **)b);
186 /* 190 /*
187 * Do not subtract the lengths, an int cannot represent the range of 191 * Do not subtract the lengths. The difference between values cannot
188 * values the difference can take. 192 * be represented by an int.
189 */ 193 */
190 return lena < lenb ? -1 : lena > lenb; 194 return lena < lenb ? -1 : lena > lenb;
191} 195}
@@ -193,7 +197,7 @@ cmp(const void *a, const void *b)
193int 197int
194main() 198main()
195{ 199{
196 int i; 200 size_t i;
197 201
198 qsort(array, N, sizeof(array[0]), cmp); 202 qsort(array, N, sizeof(array[0]), cmp);
199 for (i = 0; i < N; i++) 203 for (i = 0; i < N; i++)