]> git.saurik.com Git - apple/libc.git/blame - tests/stdio.c
Libc-1158.50.2.tar.gz
[apple/libc.git] / tests / stdio.c
CommitLineData
974e3884
A
1#include <stdio.h>
2#include <err.h>
3#include <errno.h>
4#include <unistd.h>
5#include <sys/resource.h>
6
7#include <darwintest.h>
8
9#define FILE_LIMIT 100
10
11T_DECL(PR_22813396, "STREAM_MAX is affected by changes to RLIMIT_NOFILE")
12{
13 struct rlimit theLimit;
14 getrlimit( RLIMIT_NOFILE, &theLimit );
15 theLimit.rlim_cur = FILE_LIMIT;
16 setrlimit( RLIMIT_NOFILE, &theLimit );
17
18 long stream_max = sysconf(_SC_STREAM_MAX);
19 T_EXPECT_EQ_LONG(stream_max, (long)FILE_LIMIT, "stream_max = FILE_LIMIT");
20
21 FILE *f;
22 for(int i = 3; i < stream_max; i++) {
23 if((f = fdopen(0, "r")) == NULL) {
24 T_FAIL("Failed after %d streams", i);
25 }
26 }
27
28 f = fdopen(0, "r");
29 T_EXPECT_NULL(f, "fdopen fail after stream_max streams");
30
31 theLimit.rlim_cur = FILE_LIMIT + 1;
32 setrlimit( RLIMIT_NOFILE, &theLimit );
33
34 f = fdopen(0, "r");
35 T_EXPECT_NOTNULL(f, "fdopen succeed after RLIMIT_NOFILE increased");
36}