1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
3 // UNSUPPORTED: linux, target={{.*solaris.*}}
8 #include <sys/sysctl.h>
15 #define __arraycount(a) (sizeof(a) / sizeof(a[0]))
20 size_t len
= sizeof(buf
);
21 int mib
[] = {CTL_KERN
, KERN_OSTYPE
};
22 int rv
= sysctl(mib
, __arraycount(mib
), buf
, &len
, NULL
, 0);
25 printf("sysctl: '%s' size: '%zu'\n", buf
, len
);
28 void test_sysctlbyname() {
30 size_t len
= sizeof(buf
);
31 int rv
= sysctlbyname("kern.ostype", buf
, &len
, NULL
, 0);
34 printf("sysctlbyname: '%s' size: '%zu'\n", buf
, len
);
37 void test_sysctlnametomib() {
39 size_t mib_len
= __arraycount(mib
);
40 int rv
= sysctlnametomib("kern.ostype", &mib
[0], &mib_len
);
44 size_t len
= sizeof(buf
);
45 rv
= sysctl(mib
, mib_len
, buf
, &len
, NULL
, 0);
48 printf("sysctlnametomib: '%s' size: '%zu'\n", buf
, len
);
56 test_sysctlnametomib();
59 // CHECK: sysctl: '{{.*}}' size: '{{.*}}'
60 // CHECK: sysctlbyname: '{{.*}}' size: '{{.*}}'
61 // CHECK: sysctlnametomib: '{{.*}}' size: '{{.*}}'