You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/specs/stdlib_system.md
+106Lines changed: 106 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -335,3 +335,109 @@ Returns a `logical` flag: `.true.` if the system is Windows, or `.false.` otherw
335
335
```fortran
336
336
{!example/system/example_process_1.f90!}
337
337
```
338
+
339
+
## `get_runtime_os` - Determine the OS type at runtime
340
+
341
+
### Status
342
+
343
+
Experimental
344
+
345
+
### Description
346
+
347
+
`get_runtime_os` inspects the runtime environment to identify the current OS type. It evaluates environment variables (`OSTYPE`, `OS`) and checks for specific files associated with known operating systems.
348
+
The supported OS types are `integer, parameter` variables stored in the `stdlib_system` module:
349
+
350
+
-**Linux** (`OS_LINUX`)
351
+
-**macOS** (`OS_MACOS`)
352
+
-**Windows** (`OS_WINDOWS`)
353
+
-**Cygwin** (`OS_CYGWIN`)
354
+
-**Solaris** (`OS_SOLARIS`)
355
+
-**FreeBSD** (`OS_FREEBSD`)
356
+
-**OpenBSD** (`OS_OPENBSD`)
357
+
358
+
If the OS cannot be identified, the function returns `OS_UNKNOWN`.
Returns one of the `integer``OS_*` parameters representing the OS type, from the `stdlib_system` module, or `OS_UNKNOWN` if undetermined.
375
+
376
+
### Example
377
+
378
+
```fortran
379
+
program example_os_detection
380
+
use stdlib_system, only: OS_TYPE, get_runtime_os
381
+
implicit none
382
+
integer :: os_type_cached, os_type_runtime
383
+
384
+
! Cached OS detection
385
+
os_type_cached = OS_TYPE()
386
+
print *, "Cached OS Type: ", os_type_cached
387
+
388
+
! Runtime OS detection (full inspection)
389
+
os_type_runtime = get_runtime_os()
390
+
print *, "Runtime OS Type: ", os_type_runtime
391
+
end program example_os_detection
392
+
```
393
+
394
+
---
395
+
396
+
## `OS_TYPE` - Cached OS type retrieval
397
+
398
+
### Status
399
+
400
+
Experimental
401
+
402
+
### Description
403
+
404
+
`OS_TYPE` provides a cached result of the `get_runtime_os` function. The OS type is determined during the first invocation and stored in a static variable.
405
+
Subsequent calls reuse the cached value, making this function highly efficient.
406
+
407
+
This caching mechanism ensures negligible overhead for repeated calls, unlike `get_runtime_os`, which performs a full runtime inspection.
0 commit comments