Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / regress / lib / libc / gen / telldir-memuse / telldir-memuse.c
blob37b2a130769817317b2cc99cd6f1b0f309351260
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <dirent.h>
4 #include <err.h>
7 int main(void)
9 DIR *dp;
10 long loc;
11 void *memused;
12 int i;
13 int oktouse = 4096;
15 dp = opendir(".");
16 if (dp == NULL)
17 err(EXIT_FAILURE, "Could not open current directory");
18 loc = telldir(dp);
19 memused = sbrk(0);
20 closedir(dp);
22 for (i=0; i<1000; i++) {
23 dp = opendir(".");
24 if (dp == NULL)
25 err(EXIT_FAILURE, "Could not open current directory");
26 loc = telldir(dp);
27 closedir(dp);
29 if (sbrk(0) - memused > oktouse) {
30 warnx("Used %d extra bytes for %d telldir calls",
31 (sbrk(0)-memused), i);
32 oktouse = sbrk(0) - memused;
35 if (oktouse > 4096) {
36 errx(EXIT_FAILURE, "Failure: leaked %d bytes", oktouse);
37 #ifdef DEBUG
38 } else {
39 printf("OK: used %d bytes\n", sbrk(0)-memused);
40 #endif
42 return 0;