Picard
Picard

Reputation: 1037

Contradictory documentation on sysctlbyname return value

The man pages sysctl(3) state that sysctlbyname and the other mentioned functions return either 0 in case of success or -1 and set errno. But the Apple Documentation (for objective C) for sysctlbyname says the following about the the return values:

Return value

0 on success, or an error code that indicates a problem occurred. Possible error codes include EFAULT, EINVAL, ENOMEM, ENOTDIR, EISDIR, ENOENT, and EPERM.

So which is it, 0/-1 & errno or error code returned directly? Or does it return something different in objective C than the C function mentioned in the man pages? But even the provided example in Apple's documentation only checks for return value -1 and then uses errno to log the error. Seems to me that Apple's documentation is wrong or at least unclear.

Upvotes: 0

Views: 148

Answers (1)

Picard
Picard

Reputation: 1037

As answered here by Apple, the documentation for the KPI version of sysctlbyname is confusing. It behaves as expected like the user space version described in the man pages. It returns 0 on success or -1 if an error occurs and sets errno.

Upvotes: 1

Related Questions