Greetings,

The Hurd porting guidelines don't show any example for using sysconf()
to fetch IOV_MAX and friends. It would be desirable to show one,
ideally one using the preferred method. It would save porters a lot of
frustrations if they could just copy-paste that one, since it's a
common issue.

Having done some googling returned the attached example. Is this the
preferred method? If yes, could someone add it to the porting
guidelines. If not, please comment.

Thanks!
Martin-Éric
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

int main(void) {
    // Clear errno before calling sysconf to distinguish errors from an infinite limit
    errno = 0;
    
    long iov_max = sysconf(_SC_IOV_MAX);

    if (iov_max == -1) {
        if (errno == EINVAL) {
            // The key _SC_IOV_MAX is not recognized by this version of glibc
            printf("Error: _SC_IOV_MAX is invalid or unsupported on this system.\n");
        } else {
            // A return value of -1 with no error indicates no fixed limit exists
            printf("GNU/Hurd does not impose a fixed limit on IOV_MAX (it is indeterminate or infinite).\n");
        }
    } else {
        // A valid limit was successfully retrieved
        printf("The maximum number of iovec structures (IOV_MAX) is: %ld\n", iov_max);
    }

    return 0;
}

Reply via email to