View | Details | Raw Unified | Return to bug 176197 | Differences between
and this patch

Collapse All | Expand All

(-)b/lib/libc/stdlib/qsort.3 (-15 / +8 lines)
Lines 220-226 and then prints the sorted array to standard output is: Link Here
220
.Bd -literal
220
.Bd -literal
221
#include <stdio.h>
221
#include <stdio.h>
222
#include <stdlib.h>
222
#include <stdlib.h>
223
#include <string.h>
224
223
225
/*
224
/*
226
 * Custom comparison function that can compare 'int' values through pointers
225
 * Custom comparison function that can compare 'int' values through pointers
Lines 229-243 and then prints the sorted array to standard output is: Link Here
229
static int
228
static int
230
int_compare(const void *p1, const void *p2)
229
int_compare(const void *p1, const void *p2)
231
{
230
{
232
        int *left = (int *)p1;
231
        int left  = *(const int *)p1;
233
        int *right = (int *)p2;
232
        int right = *(const int *)p2;
234
233
235
        if (*left < *right)
234
        return ((left > right) - (left < right));
236
                return (-1);
237
        else if (*left > *right)
238
                return (1);
239
        else
240
                return (0);
241
}
235
}
242
236
243
/*
237
/*
Lines 247-260 int Link Here
247
main(void)
241
main(void)
248
{
242
{
249
       int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
243
       int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
250
       const int array_size = sizeof(int_array) / sizeof(int_array[0]);
244
       const size_t array_size = sizeof(int_array) / sizeof(int_array[0]);
251
       int k;
245
       size_t k;
252
246
253
       qsort(&int_array, array_size, sizeof(int), int_compare);
247
       qsort(&int_array, array_size, sizeof(int_array[0]), int_compare);
254
       for (k = 0; k < array_size; k++)
248
       for (k = 0; k < array_size; k++)
255
                printf(" %d", int_array[k]);
249
                printf(" %d", int_array[k]);
256
        printf("\\n");
250
       puts("");
257
        exit(EXIT_SUCCESS);
251
       return (EXIT_SUCCESS);
258
}
252
}
259
.Ed
253
.Ed
260
.Sh ERRORS
254
.Sh ERRORS
261
- 

Return to bug 176197