41 implicit none;
private
88 integer,
intent(in) :: os
89 character(:),
allocatable :: res
100 case default ; res =
'UNKNOWN'
120 character(len=255) :: val
121 integer :: length, rc
122 logical :: file_exists
123 logical,
save :: first_run = .true.
127 if (.not. first_run)
then
136 call get_environment_variable(
'OSTYPE', val, length, rc)
138 if (rc == 0 .and. length > 0)
then
140 if (index(val,
'linux') > 0)
then
147 if (index(val,
'darwin') > 0)
then
154 if (index(val,
'win') > 0 .or. index(val,
'msys') > 0)
then
161 if (index(val,
'cygwin') > 0)
then
168 if (index(val,
'SunOS') > 0 .or. index(val,
'solaris') > 0)
then
175 if (index(val,
'FreeBSD') > 0 .or. index(val,
'freebsd') > 0)
then
182 if (index(val,
'OpenBSD') > 0 .or. index(val,
'openbsd') > 0)
then
190 call get_environment_variable(
'OS', val, length, rc)
192 if (rc == 0 .and. length > 0 .and. index(val,
'Windows_NT') > 0)
then
195 call get_environment_variable(
'PROCESSOR_ARCHITECTURE', val, length, rc)
196 if (rc == 0 .and. length > 0 .and. index(val,
'x86') > 0)
then
204 inquire(file=
'/etc/os-release', exist=file_exists)
206 if (file_exists)
then
213 inquire(file=
'/usr/bin/sw_vers', exist=file_exists)
215 if (file_exists)
then
222 inquire(file=
'/bin/freebsd-version', exist=file_exists)
224 if (file_exists)
then
240 integer,
intent(in),
optional :: os
242 if (
present(os))
then
integer, parameter, public os_windowsx86
Microsoft Windows — explicitly 32-bit (x86) architecture.
integer, parameter, public os_solaris
Oracle Solaris / OpenSolaris derivatives.
integer, parameter, public os_windows
Microsoft Windows (native, 32-bit or 64-bit)
integer, parameter, public os_linux
Linux (any distribution, including GNU/Linux)
integer, parameter, public os_openbsd
OpenBSD.
integer, parameter, public os_freebsd
FreeBSD and its direct derivatives.
integer, parameter, public os_macos
macOS (Darwin-based Apple operating system)
integer, parameter, public os_unknown
Unknown / undetected operating system.
logical function, public os_is_unix(os)
Return .true. if the current (or supplied) OS is Unix-like Convenience wrapper that returns ....
integer function, public get_os_type()
Determine the current operating system type Returns one of the OS_* constants. Detection is performed...
pure character(:) function, allocatable, public os_name(os)
Return a human-readable string describing the OS type flag Converts any of the OS_* integer constants...
integer, parameter, public os_cygwin
Cygwin POSIX environment on Windows.