Is there a programmable way to check for Darwin (Mac OS X) or Linux?

If you don’t mind compile some C code, here’s how Jason Hickey’s libmojave does it, and it is compatible with Win32: