root / tests / cris / check_openpf5.c @ 212b6008
History | View | Annotate | Download (955 Bytes)
1 | dd43edf4 | ths | /* Check that TRT happens when error on too many opened files.
|
---|---|---|---|
2 | dd43edf4 | ths | #notarget: cris*-*-elf
|
3 | dd43edf4 | ths | #sim: --sysroot=@exedir@
|
4 | dd43edf4 | ths | */
|
5 | dd43edf4 | ths | #include <stddef.h> |
6 | dd43edf4 | ths | #include <stdlib.h> |
7 | dd43edf4 | ths | #include <stdio.h> |
8 | dd43edf4 | ths | #include <unistd.h> |
9 | dd43edf4 | ths | #include <errno.h> |
10 | dd43edf4 | ths | #include <limits.h> |
11 | dd43edf4 | ths | #include <sys/types.h> |
12 | dd43edf4 | ths | #include <sys/stat.h> |
13 | dd43edf4 | ths | #include <fcntl.h> |
14 | dd43edf4 | ths | #include <string.h> |
15 | dd43edf4 | ths | |
16 | dd43edf4 | ths | int main (int argc, char *argv[]) |
17 | dd43edf4 | ths | { |
18 | dd43edf4 | ths | int i;
|
19 | dd43edf4 | ths | int filemax;
|
20 | dd43edf4 | ths | |
21 | dd43edf4 | ths | #ifdef OPEN_MAX
|
22 | dd43edf4 | ths | filemax = OPEN_MAX; |
23 | dd43edf4 | ths | #else
|
24 | dd43edf4 | ths | filemax = sysconf (_SC_OPEN_MAX); |
25 | dd43edf4 | ths | #endif
|
26 | dd43edf4 | ths | |
27 | dd43edf4 | ths | char *fn = malloc (strlen (argv[0]) + 2); |
28 | dd43edf4 | ths | if (fn == NULL) |
29 | dd43edf4 | ths | abort (); |
30 | dd43edf4 | ths | strcpy (fn, "/");
|
31 | dd43edf4 | ths | strcat (fn, argv[0]);
|
32 | dd43edf4 | ths | |
33 | dd43edf4 | ths | for (i = 0; i < filemax + 1; i++) |
34 | dd43edf4 | ths | { |
35 | dd43edf4 | ths | if (open (fn, O_RDONLY) < 0) |
36 | dd43edf4 | ths | { |
37 | dd43edf4 | ths | /* Shouldn't happen too early. */
|
38 | dd43edf4 | ths | if (i < filemax - 3 - 1) |
39 | dd43edf4 | ths | { |
40 | dd43edf4 | ths | fprintf (stderr, "i: %d\n", i);
|
41 | dd43edf4 | ths | abort (); |
42 | dd43edf4 | ths | } |
43 | dd43edf4 | ths | if (errno != EMFILE)
|
44 | dd43edf4 | ths | { |
45 | dd43edf4 | ths | perror ("open");
|
46 | dd43edf4 | ths | abort (); |
47 | dd43edf4 | ths | } |
48 | dd43edf4 | ths | goto ok;
|
49 | dd43edf4 | ths | } |
50 | dd43edf4 | ths | } |
51 | dd43edf4 | ths | abort (); |
52 | dd43edf4 | ths | |
53 | dd43edf4 | ths | ok:
|
54 | dd43edf4 | ths | printf ("pass\n");
|
55 | dd43edf4 | ths | exit (0);
|
56 | dd43edf4 | ths | } |