Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / cris / libc / check_openpf5.c
blob1f86ea283d4b82ae4fc71228c26f953f9ecc8b56
1 /* Check that TRT happens when error on too many opened files.
2 #notarget: cris*-*-elf
3 #sim: --sysroot=@exedir@
4 */
5 #include <stddef.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <errno.h>
10 #include <limits.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <string.h>
16 int main (int argc, char *argv[])
18 int i;
19 int filemax;
21 #ifdef OPEN_MAX
22 filemax = OPEN_MAX;
23 #else
24 filemax = sysconf (_SC_OPEN_MAX);
25 #endif
27 char *fn = malloc (strlen (argv[0]) + 2);
28 if (fn == NULL)
29 abort ();
30 strcpy (fn, "/");
31 strcat (fn, argv[0]);
33 for (i = 0; i < filemax + 1; i++)
35 if (open (fn, O_RDONLY) < 0)
37 /* Shouldn't happen too early. */
38 if (i < filemax - 3 - 1)
40 fprintf (stderr, "i: %d\n", i);
41 abort ();
43 if (errno != EMFILE)
45 perror ("open");
46 abort ();
48 goto ok;
51 abort ();
53 ok:
54 printf ("pass\n");
55 exit (0);