/* - | Copyright | ------------------------------------------------------------ Copyright (c) 2026 Randy Jordan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * --------------------------------------------------------------------------*/ #define DEBUG #include "../include/ci2.h" #include #include #include /* Platform-specific verification headers */ #if defined(CI2_WINDOWS) #include /* GetSystemInfo, SYSTEM_INFO */ #elif defined(CI2_UNIX) #include /* uname() — POSIX */ #include /* sysconf, _SC_* constants — POSIX */ #endif int main(int argc, char* argv[]) { (void)argc; (void)argv; #if defined(CI2_WINDOWS) printf(" Detected platform : Windows\n"); /* * GetSystemInfo() is a Win32 API that fills SYSTEM_INFO. * If _WIN32 were wrong this wouldn't compile or link. */ SYSTEM_INFO si; GetSystemInfo(&si); printf(" Page size : %lu bytes\n", (unsigned long)si.dwPageSize); printf(" Processor count : %lu\n", (unsigned long)si.dwNumberOfProcessors); printf(" Processor arch : %u\n", (unsigned)si.wProcessorArchitecture); CI2_ASSERT(si.dwPageSize > 0); CI2_ASSERT(si.dwNumberOfProcessors > 0); #elif defined(CI2_UNIX) /* * uname() fills a struct utsname with kernel name, release, machine, etc. * This is a POSIX function — available on Linux, macOS, and all BSDs. * It won't compile on Windows, proving our platform guard is correct. */ struct utsname uts; int ret = uname(&uts); CI2_ASSERT(ret == 0); printf(" Detected platform : Unix-like\n"); printf(" OS / sysname : %s\n", uts.sysname); printf(" Kernel release : %s\n", uts.release); printf(" Machine arch : %s\n", uts.machine); printf(" Node name : %s\n", uts.nodename); /* * sysconf() is another POSIX function. * _SC_PAGESIZE and _SC_NPROCESSORS_ONLN are available on Linux & macOS. */ long page_size = sysconf(_SC_PAGESIZE); long n_cpus = sysconf(_SC_NPROCESSORS_ONLN); printf(" Page size : %ld bytes\n", page_size); printf(" CPUs online : %ld\n", n_cpus); CI2_ASSERT(page_size > 0); CI2_ASSERT(n_cpus > 0); /* Sanity: page size is always a power of two */ CI2_ASSERT((page_size & (page_size - 1)) == 0); #if defined(CI2_LINUX) printf(" Sub-platform : Linux\n"); CI2_ASSERT(strlen(uts.sysname) > 0); #elif defined(CI2_MACOS) printf(" Sub-platform : macOS\n"); CI2_ASSERT(strlen(uts.sysname) > 0); #endif #else printf(" [FAIL] No platform macro was defined!\n"); return EXIT_FAILURE; #endif return EXIT_SUCCESS; }