Every UNIX based system like Linux has a certain set of limitations on the kind of feature sets and resources that can be used by a program or user. This can range from simplistic models like the complete length of file’s path, to the kind of arguments and calls that a program can have.
Since these limits effectively reduce the scope and abilities of a program, an application trying to be portable across different UNIX implementations needs to account for varying limit standards. The Single UNIX Specification’s third version (SuSv3, in short) defined three discrete functions that an application could call to determine the limits of the system it was working on – fpathconf(), pathconf() andsysconf(). It also defined a limit range that a UNIX implementation could enforce. The most crucial part of this set range was a minimum limit. This particular limit would be set as a constant in the limits header file, with a name that begun with the _posix_ string. If an application could stick to the specified minimum limits, it would manage to be portable across most implementations in all likelihood. However, that would result in a loss of functionality that higher limit values would bring in. This made determining the limits of a system using sysconf() etc. particularly invariable. This function was also a great tool to determine runtime invariant and increasable values.
A function like pathconf(), on the other hand, deals with the name of file paths. Limits on these pathnames could be determined using functions like fpathconf() and pathconf(). Limits can also be ascertained through shell commands. The getconfcommand can help you determine the limits in the UNIX implementation you are currently working on.
During runtime, sysconf() can tell you the limits you need when you specify the name of the limit in the function’s argument. If the limit cannot be determined, or there is an error of any sort, the function will return a value of –1′. SuSv3 dictates that the value returned by the function has to be constant all through the calling.
The difference between pathconf() and fpathconf() is the method of specifying the file/directory. In the case of the former, the pathname needs to be specified, while for the latter, a previously opened file descriptor is required. SuSv3 does not require these functions to return values than remain constant all through an entire process runtime. This lets a file system to be mounted and dismounted multiple times, all while the process is running.
Indeterminate limits are ones that are not defined by an implementation limit constant. The functions stated above would end up returning –1′ to indicate the indeterminacy of the limits required. These hindrances can be handled in a number of ways – the most practical of them being to avoid the checking of limits, and instead perform the corresponding library function calls. If those calls fail too, the errnomust be checked to judge whether some other system limit was violated, so that you can modify the program behavior accordingly.
You should avoid hardcoding system limit assumptions into your programs, as it may not be valid across every file system or UNIX implementation. Using the necessary functions, SuSv3 can guide you to make your program adapt even in real-time.