@@ -83,7 +83,22 @@ module stdlib_system
8383public :: kill
8484public :: elapsed
8585public :: is_windows
86-
86+
87+ ! ! Public path related functions and interfaces
88+ #ifdef WINDOWS
89+ character (len= 1 ), parameter , public :: pathsep = ' \'
90+ logical , parameter , public :: ISWIN = .true.
91+ #else
92+ character (len= 1 ), parameter , public :: pathsep = ' /'
93+ logical , parameter , public :: ISWIN = .false.
94+ #endif
95+
96+ public :: joinpath
97+ public :: operator (/ )
98+ public :: splitpath
99+ public :: basename
100+ public :: dirname
101+
87102! ! version: experimental
88103! !
89104! ! Tests if a given path matches an existing directory.
@@ -550,6 +565,87 @@ end function process_get_ID
550565
551566end interface
552567
568+ interface joinpath
569+ ! ! version: experimental
570+ ! !
571+ ! !### Summary
572+ ! ! join the paths provided according to the OS-specific path-separator
573+ ! ! ([Specification](../page/specs/stdlib_system.html#joinpath))
574+ ! !
575+ module pure function join2(p1, p2) result(path)
576+ character (:), allocatable :: path
577+ character (* ), intent (in ) :: p1, p2
578+ end function join2
579+
580+ module pure function joinarr(p) result(path)
581+ character (:), allocatable :: path
582+ character (* ), intent (in ) :: p(:)
583+ end function joinarr
584+ end interface joinpath
585+
586+ interface operator (/ )
587+ ! ! version: experimental
588+ ! !
589+ ! !### Summary
590+ ! ! A binary operator to join the paths provided according to the OS-specific path-separator
591+ ! ! ([Specification](../page/specs/stdlib_system.html#operator(/)))
592+ ! !
593+ module pure function join_op(p1, p2) result(path)
594+ character (:), allocatable :: path
595+ character (* ), intent (in ) :: p1, p2
596+ end function join_op
597+ end interface operator (/ )
598+
599+ interface splitpath
600+ ! ! version: experimental
601+ ! !
602+ ! !### Summary
603+ ! ! splits the path immediately following the final path-separator
604+ ! ! separating into typically a directory and a file name.
605+ ! ! ([Specification](../page/specs/stdlib_system.html#splitpath))
606+ ! !
607+ ! !### Description
608+ ! ! If the path is empty `head`='.' and tail=''
609+ ! ! If the path only consists of separators, `head` is set to the separator and tail is empty
610+ ! ! If the path is a root directory, `head` is set to that directory and tail is empty
611+ ! ! `head` ends with a path-separator iff the path appears to be a root directory
612+ module subroutine splitpath (p , head , tail )
613+ character (* ), intent (in ) :: p
614+ character (:), allocatable , intent (out ) :: head, tail
615+ end subroutine splitpath
616+ end interface splitpath
617+
618+ interface basename
619+ ! ! version: experimental
620+ ! !
621+ ! !### Summary
622+ ! ! returns the basename (last component) of the provided path
623+ ! ! ([Specification](../page/specs/stdlib_system.html#basename))
624+ ! !
625+ ! !### Description
626+ ! ! The value returned is the `tail` of the interface `splitpath`
627+ module function basename (p ) result(base)
628+ character (:), allocatable :: base
629+ character (* ), intent (in ) :: p
630+ end function basename
631+ end interface basename
632+
633+ interface dirname
634+ ! ! version: experimental
635+ ! !
636+ ! !### Summary
637+ ! ! returns everything but the last component of the provided path
638+ ! ! ([Specification](../page/specs/stdlib_system.html#dirname))
639+ ! !
640+ ! !### Description
641+ ! ! The value returned is the `head` of the interface `splitpath`
642+ module function dirname (p ) result(base)
643+ character (:), allocatable :: base
644+ character (* ), intent (in ) :: p
645+ end function dirname
646+ end interface dirname
647+
648+
553649contains
554650
555651integer function get_runtime_os () result(os)
0 commit comments