test: 90-readdir: Remove qsort dependency. Fixes tmpfs failures.

* lib/tests/dirent/90-readdir.c (check_seen): New function.
(main): Use it instead of qsort.
(qsort_strcmp): Remove.
This commit is contained in:
Jan Nieuwenhuizen 2019-12-01 23:58:48 +01:00
parent 46b73f494b
commit 35c97baaef
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -25,10 +25,25 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
int int dot_seen = 0;
qsort_strcmp (void const *a, void const *b) int dot_dot_seen = 0;
int dir_seen = 0;
int file_seen = 0;
int link_seen = 0;
void
check_seen (char const* name)
{ {
return strcmp (*((char **) a), *((char **) b)); if (!strcmp (name, "."))
dot_seen = 1;
if (!strcmp (name, ".."))
dot_dot_seen = 1;
if (!strcmp (name, "dir"))
dir_seen = 1;
if (!strcmp (name, "file"))
file_seen = 1;
if (!strcmp (name, "link"))
link_seen = 1;
} }
int int
@ -55,59 +70,60 @@ main ()
return 6; return 6;
int i = 0; int i = 0;
char *list[6] = { 0 };
struct dirent *entry = readdir (d); struct dirent *entry = readdir (d);
if (!entry) if (!entry)
return 7; return 7;
oputs (entry->d_name); oputs (entry->d_name);
oputs ("\n"); oputs ("\n");
list[i++] = entry->d_name; check_seen (entry->d_name);
entry = readdir (d); entry = readdir (d);
if (!entry) if (!entry)
return 8; return 8;
oputs (entry->d_name); oputs (entry->d_name);
oputs ("\n"); oputs ("\n");
list[i++] = entry->d_name; check_seen (entry->d_name);
entry = readdir (d); entry = readdir (d);
if (!entry) if (!entry)
return 9; return 9;
oputs (entry->d_name); oputs (entry->d_name);
oputs ("\n"); oputs ("\n");
list[i++] = entry->d_name; check_seen (entry->d_name);
entry = readdir (d); entry = readdir (d);
if (!entry) if (!entry)
return 10; return 10;
oputs (entry->d_name); oputs (entry->d_name);
oputs ("\n"); oputs ("\n");
list[i++] = entry->d_name; check_seen (entry->d_name);
entry = readdir (d); entry = readdir (d);
if (!entry) if (!entry)
return 11; return 11;
oputs (entry->d_name); oputs (entry->d_name);
oputs ("\n"); oputs ("\n");
list[i++] = entry->d_name; check_seen (entry->d_name);
entry = readdir (d); entry = readdir (d);
if (entry) if (entry)
return 12; return 12;
oputs ("\nls:\n"); if (!dot_seen)
qsort (list, 5, sizeof (char *), qsort_strcmp);
for (int i = 0; i < 5; i++)
{
oputs (list[i]);
oputs ("\n");
}
if (strcmp (list[0], "."))
return 13; return 13;
if (strcmp (list[4], "link")) if (!dot_dot_seen)
return 14; return 14;
if (!dir_seen)
return 15;
if (!file_seen)
return 16;
if (!link_seen)
return 17;
return 0; return 0;
} }