On my Linux system there seems to be a massive difference between the value of _POSIX_OPEN_MAX and what sysconf(_SC_OPEN_MAX) returns and also what I'd expect from the table of examples of configuration limits from Advanced Programming In The UNIX Environment, 2nd Ed.
_POSIX_OPEN_MAX: 16
sysconf(_SC_OPEN_MAX): 65535
Advanced Programming In The UNIX Environment, 2nd Ed, 2005
Figure 2.14. Examples of configuration limits
OPEN_MAX:
FreeBSD 5.2.1: 1735
Linux 2.4.22: 1024
Mac OS X 10.3: 256
Solaris 9: 256
Doesn't the value of 65,535 returned by sysconf(_SC_OPEN_MAX) seem way too high?
No. It is controlled by the kernel and the values in limits.h provided by the people who built the kernel. On some systems it may be dynamic, others it is fixed.
You may also have _POSIX2_ values for things. See /usr/include/limits.h
FWIW -
I have an old version of solaris with _POSIX_OPEN_MAX = 16
PS: you don't have to write C code to get those values - try the getconf command.
The _POSIX_OPEN_MAX that you print from you program is the limits as defined by the POSIX standard (as of IEEE 1003.1-2008, it's 20). This limit states the minimal number of files that a process can have opened at any time. That is, on a POSIX platform, it is guarantee that any process can have at least up to _POSIX_OPEN_MAX files opened.
Typically, systems like Linux support much more opened file per process that _POSIX_OPEN_MAX.
Now, the value you get with getconf _POSIX_OPEN_MAX is in fact the value obtained with sysconf(_SC_OPEN_MAX). That is, the max. number of files a process can have for the user executing the program (also, in your case what ulimit -n would return).