diff options
author | wollman <wollman@FreeBSD.org> | 2008-02-27 05:56:57 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 2008-02-27 05:56:57 +0000 |
commit | e043fbfcdef275f645d6adf3820734fe0532f487 (patch) | |
tree | 1f320a133785773856b555d4732b4edc416fa46e | |
parent | bcd067ff4ff4fa9e5ca8c53935834e040876eb18 (diff) | |
download | FreeBSD-src-e043fbfcdef275f645d6adf3820734fe0532f487.zip FreeBSD-src-e043fbfcdef275f645d6adf3820734fe0532f487.tar.gz |
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
-rw-r--r-- | lib/libc/gen/sysconf.c | 20 |
1 files changed, 19 insertions, 1 deletions
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: |