Skip to content

Commit eaaa0d1

Browse files
committed
add docs
1 parent d0aa547 commit eaaa0d1

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

doc/specs/stdlib_system.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,109 @@ Returns a `logical` flag: `.true.` if the system is Windows, or `.false.` otherw
335335
```fortran
336336
{!example/system/example_process_1.f90!}
337337
```
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`.
359+
360+
### Syntax
361+
362+
`os = [[stdlib_system(module):get_runtime_os(function)]]()`
363+
364+
### Class
365+
366+
Function
367+
368+
### Arguments
369+
370+
None.
371+
372+
### Return Value
373+
374+
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.
408+
409+
### Syntax
410+
411+
`os = [[stdlib_system(module):OS_TYPE(function)]]()`
412+
413+
### Class
414+
415+
Function
416+
417+
### Arguments
418+
419+
None.
420+
421+
### Return Value
422+
423+
Returns one of the `integer` `OS_*` parameters representing the OS type, from the `stdlib_system` module, or `OS_UNKNOWN` if undetermined.
424+
425+
---
426+
427+
### Example
428+
429+
```fortran
430+
program example_os_detection
431+
use stdlib_system, only: OS_TYPE, get_runtime_os
432+
implicit none
433+
integer :: os_type_cached, os_type_runtime
434+
435+
! Cached OS detection
436+
os_type_cached = OS_TYPE()
437+
print *, "Cached OS Type: ", os_type_cached
438+
439+
! Runtime OS detection (full inspection)
440+
os_type_runtime = get_runtime_os()
441+
print *, "Runtime OS Type: ", os_type_runtime
442+
end program example_os_detection
443+
```

0 commit comments

Comments
 (0)