26 lines
618 B
C
26 lines
618 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
|
|
extern char * _argv_0;
|
|
extern int __libc_debug;
|
|
|
|
void qsort(void * base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) {
|
|
if (!nmemb) return;
|
|
if (!size) return;
|
|
for (size_t i = 0; i < nmemb-1; ++i) {
|
|
for (size_t j = 0; j < nmemb-1; ++j) {
|
|
void * left = (char *)base + size * j;
|
|
void * right = (char *)base + size * (j + 1);
|
|
if (compar(left,right) > 0) {
|
|
char tmp[size];
|
|
memcpy(tmp, right, size);
|
|
memcpy(right, left, size);
|
|
memcpy(left, tmp, size);
|
|
}
|
|
}
|
|
}
|
|
}
|