| 1 | // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | |
| 3 | #include <sys/param.h> |
| 4 | #include <sys/types.h> |
| 5 | |
| 6 | #include <sys/sysctl.h> |
| 7 | |
| 8 | #include <assert.h> |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | |
| 12 | void test_asysctl() { |
| 13 | int mib[] = {CTL_KERN, KERN_OSTYPE}; |
| 14 | size_t len; |
| 15 | char *buf = (char *)asysctl(mib, __arraycount(mib), &len); |
| 16 | assert(buf); |
| 17 | |
| 18 | printf(format: "asysctl: '%s' size: '%zu'\n" , buf, len); |
| 19 | |
| 20 | free(ptr: buf); |
| 21 | } |
| 22 | |
| 23 | void test_asysctlbyname() { |
| 24 | size_t len; |
| 25 | char *buf = (char *)asysctlbyname("kern.ostype" , &len); |
| 26 | assert(buf); |
| 27 | |
| 28 | printf(format: "asysctlbyname: '%s' size: '%zu'\n" , buf, len); |
| 29 | |
| 30 | free(ptr: buf); |
| 31 | } |
| 32 | |
| 33 | int main(void) { |
| 34 | printf(format: "asysctl\n" ); |
| 35 | |
| 36 | test_asysctl(); |
| 37 | test_asysctlbyname(); |
| 38 | |
| 39 | return 0; |
| 40 | |
| 41 | // CHECK: asysctl |
| 42 | // CHECK: asysctl: '{{.*}}' size: '{{.*}}' |
| 43 | // CHECK: asysctlbyname: '{{.*}}' size: '{{.*}}' |
| 44 | } |
| 45 | |