Skip to content

Commit a89bc91

Browse files
committed
add null_device
1 parent d724658 commit a89bc91

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/stdlib_system.F90

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ module stdlib_system
8181
public :: elapsed
8282
public :: is_windows
8383

84+
!! version: experimental
85+
!!
86+
!! Returns the file path of the null device, which discards all data written to it.
87+
!! ([Specification](../page/specs/stdlib_system.html#null_device-return-the-null-device-file-path))
88+
!!
89+
!! ### Summary
90+
!! Function that provides the file path of the null device appropriate for the current operating system.
91+
!!
92+
!! ### Description
93+
!!
94+
!! The null device is a special file that discards all data written to it and always reads as
95+
!! an empty file. This function returns the null device path, adapted for the operating system in use.
96+
!!
97+
!! On Windows, this is `NUL`. On UNIX-like systems, this is `/dev/null`.
98+
!!
99+
public :: null_device
100+
84101
! CPU clock ticks storage
85102
integer, parameter, private :: TICKS = int64
86103
integer, parameter, private :: RTICKS = dp
@@ -618,4 +635,17 @@ pure function OS_NAME(os)
618635
end select
619636
end function OS_NAME
620637

638+
!> Return the file path of the null device for the current operating system.
639+
function null_device() result(path)
640+
!> File path of the null device
641+
character(:), allocatable :: path
642+
643+
if (OS_TYPE()==OS_WINDOWS) then
644+
path = 'NUL'
645+
else
646+
path = '/dev/null'
647+
end if
648+
649+
end function null_device
650+
621651
end module stdlib_system

0 commit comments

Comments
 (0)