]>
git.saurik.com Git - apple/libc.git/blob - tests/stdio.c
5 #include <sys/resource.h>
7 #include <darwintest.h>
11 T_DECL(stdio_PR_22813396
, "STREAM_MAX is affected by changes to RLIMIT_NOFILE")
13 struct rlimit theLimit
;
14 getrlimit( RLIMIT_NOFILE
, &theLimit
);
15 theLimit
.rlim_cur
= FILE_LIMIT
;
16 setrlimit( RLIMIT_NOFILE
, &theLimit
);
18 long stream_max
= sysconf(_SC_STREAM_MAX
);
19 T_EXPECT_EQ_LONG(stream_max
, (long)FILE_LIMIT
, "stream_max = FILE_LIMIT");
22 for(int i
= 3; i
< stream_max
; i
++) {
23 if((f
= fdopen(0, "r")) == NULL
) {
24 T_FAIL("Failed after %d streams", i
);
29 T_EXPECT_NULL(f
, "fdopen fail after stream_max streams");
31 theLimit
.rlim_cur
= FILE_LIMIT
+ 1;
32 setrlimit( RLIMIT_NOFILE
, &theLimit
);
35 T_EXPECT_NOTNULL(f
, "fdopen succeed after RLIMIT_NOFILE increased");
38 T_DECL(stdio_PR_22813396_close
, "STREAM_MAX is enforced properly after fclose")
40 struct rlimit theLimit
;
41 getrlimit( RLIMIT_NOFILE
, &theLimit
);
42 theLimit
.rlim_cur
= FILE_LIMIT
;
43 setrlimit( RLIMIT_NOFILE
, &theLimit
);
45 long stream_max
= sysconf(_SC_STREAM_MAX
);
46 T_EXPECT_EQ_LONG(stream_max
, (long)FILE_LIMIT
, "stream_max = FILE_LIMIT");
49 for(int i
= 3; i
< stream_max
- 1; i
++) {
50 if((f
= fdopen(0, "r")) == NULL
) {
51 T_FAIL("Failed after %d streams", i
);
55 // the last stream is for dup(0), it needs to be fclose'd
57 T_EXPECT_NOTNULL(dupf
= fdopen(dup(0), "r"), NULL
);
59 T_EXPECT_NULL(f
= fdopen(0, "r"), "fdopen fail after stream_max streams");
61 T_EXPECT_POSIX_ZERO(fclose(dupf
), "fclose succeeds");
64 T_WITH_ERRNO
; T_EXPECT_NOTNULL(f
, "fdopen succeed after fclose");