When writing safe code in straight C, I'm sick and tired of coming up with arbitrary numbers to represent limitations -- specifically, the maximum amount of memory to allocate for a single line of text. I know I can always say stuff like
#define MAX_LINE_LENGTH 1024
and then pass that macro to functions such as snprintf().
I work and code in NetBSD, which has a sysctl(3) variable called "user.line_max" designed for this very purpose. So I don't need to come up with an arbitrary number like MAX_LINE_LENGTH, above. I just read the "user.line_max" sysctl variable, which by the way is settable by the user.
My question is whether this is the Right Thing in terms of safety and portability. Perhaps different operating systems have a different name for this sysctl, but I'm more interested in whether I should be using this technique at all.
And for the record, "portability" excludes Microsoft Windows in this case.
Well the linux SYSCTL (2) man page has this to say in the Notes section:
So that is one consideration.