OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [stdlib/] [qsort.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdio.h>
2
#include <dirent.h>
3
#include <stdlib.h>
4
#include <unistd.h>
5
 
6
int select_files(const struct dirent *dirbuf)
7
{
8
    if (dirbuf->d_name[0] == '.')
9
        return 0;
10
    else
11
        return 1;
12
}
13
 
14
 
15
int main(void)
16
{
17
    struct dirent **array;
18
    struct dirent *dirbuf;
19
 
20
    int i, numdir;
21
 
22
    chdir("/");
23
    numdir = scandir(".", &array, select_files, NULL);
24
    printf("\nGot %d entries from scandir().\n", numdir);
25
    for (i = 0; i < numdir; ++i) {
26
        dirbuf = array[i];
27
        printf("[%d] %s\n", i, dirbuf->d_name);
28
        free(array[i]);
29
    }
30
    free(array);
31
    numdir = scandir(".", &array, select_files, alphasort);
32
    printf("\nGot %d entries from scandir() using alphasort().\n", numdir);
33
    for (i = 0; i < numdir; ++i) {
34
        dirbuf = array[i];
35
        printf("[%d] %s\n", i, dirbuf->d_name);
36
    }
37
    printf("\nCalling qsort()\n");
38
    qsort(array, numdir, sizeof(struct dirent *), alphasort);
39
    for (i = 0; i < numdir; ++i) {
40
        dirbuf = array[i];
41
        printf("[%d] %s\n", i, dirbuf->d_name);
42
        free(array[i]);
43
    }
44
    free(array);
45
    return(0);
46
}
47
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.