tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

return value of sysctlbyname(3)



Hi,

I have a simple question: what is the return value of the function
sysctlbyname?

The manual page sysctlbyname(3) states:

"RETURN VALUES
     If the call to sysctl is successful, the number of bytes copied out is
     returned.  Otherwise -1 is returned and errno is set appropriately."

So the following test program should print "... returns 4", but it prints
"kern_argmax=262144 size=4 sysctlbyname() returns 0":

#include <sys/param.h>
#include <sys/sysctl.h>
#include <stdio.h>

int main()
{
    unsigned kern_argmax ;
    size_t size = sizeof(kern_argmax) ;
    int res ;

    res = sysctlbyname("kern.argmax", &kern_argmax, &size, NULL, 0) ;

    printf("kern_argmax=%d size=%d sysctlbyname() returns %d\n", kern_argmax, 
size, res) ;
    return 0 ;
}

Greetings,
Ilya Dogolazky



Home | Main Index | Thread Index | Old Index