File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,9 @@ module stdlib_system
241241! ! Any encountered errors are handled using `state_type`.
242242! !
243243public :: exists
244+
245+ public :: is_symlink
246+ public :: is_regular_file
244247
245248! CPU clock ticks storage
246249integer , parameter , private :: TICKS = int64
@@ -1204,6 +1207,25 @@ end function stdlib_exists
12041207 end if
12051208end function exists
12061209
1210+ logical function is_symlink (path )
1211+ character (len=* ), intent (in ) :: path
1212+
1213+ is_symlink = exists(path) == fs_type_symlink
1214+ end function is_symlink
1215+
1216+ logical function is_regular_file (path )
1217+ character (len=* ), intent (in ) :: path
1218+
1219+ interface
1220+ logical (c_bool) function stdlib_is_regular_file(path) bind(C, name= ' stdlib_is_regular_file' )
1221+ import c_char, c_bool
1222+ character (kind= c_char) :: path(:)
1223+ end function stdlib_is_regular_file
1224+ end interface
1225+
1226+ is_regular_file = logical (stdlib_is_regular_file(to_c_char(path)))
1227+ end function is_regular_file
1228+
12071229character function path_sep ()
12081230 if (OS_TYPE() == OS_WINDOWS) then
12091231 path_sep = ' \'
Original file line number Diff line number Diff line change @@ -119,3 +119,15 @@ int stdlib_exists(const char* path, int* stat){
119119#endif /* ifdef _WIN32 */
120120 return type ;
121121}
122+
123+ // `stat` and `_stat` follow symlinks automatically.
124+ // so no need for winapi functions.
125+ bool stdlib_is_regular_file (const char * path ) {
126+ #ifdef _WIN32
127+ struct _stat buf = {0 };
128+ return _stat (path , & buf ) == 0 && S_ISREG (buf .st_mode );
129+ #else
130+ struct stat buf = {0 };
131+ return stat (path , & buf ) == 0 && S_ISREG (buf .st_mode );
132+ #endif /* ifdef _WIN32 */
133+ }
You can’t perform that action at this time.
0 commit comments