From e043fbfcdef275f645d6adf3820734fe0532f487 Mon Sep 17 00:00:00 2001 From: wollman Date: Wed, 27 Feb 2008 05:56:57 +0000 Subject: stdio is currently limited to file descriptors not greater than {SHRT_MAX}, so {STREAM_MAX} should be no greater than that. (This does not exactly meet the letter of POSIX but comes reasonably close to it in spirit.) MFC after: 14 days --- lib/libc/gen/sysconf.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 8ea61af..3c342ee 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -100,7 +100,6 @@ sysconf(name) mib[1] = KERN_NGROUPS; break; case _SC_OPEN_MAX: - case _SC_STREAM_MAX: /* assume fds run out before memory does */ if (getrlimit(RLIMIT_NOFILE, &rl) != 0) return (-1); if (rl.rlim_cur == RLIM_INFINITY) @@ -110,6 +109,25 @@ sysconf(name) return (-1); } return ((long)rl.rlim_cur); + case _SC_STREAM_MAX: + if (getrlimit(RLIMIT_NOFILE, &rl) != 0) + return (-1); + if (rl.rlim_cur == RLIM_INFINITY) + return (-1); + if (rl.rlim_cur > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + /* + * struct __sFILE currently has a limitation that + * file descriptors must fit in a signed short. + * This doesn't precisely capture the letter of POSIX + * but approximates the spirit. + */ + if (rl.rlim_cur > SHRT_MAX) + return (SHRT_MAX); + + return ((long)rl.rlim_cur); case _SC_JOB_CONTROL: return (_POSIX_JOB_CONTROL); case _SC_SAVED_IDS: -- cgit v1.1