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
241
241
! ! Any encountered errors are handled using `state_type`.
242
242
! !
243
243
public :: exists
244
+
245
+ public :: is_symlink
246
+ public :: is_regular_file
244
247
245
248
! CPU clock ticks storage
246
249
integer , parameter , private :: TICKS = int64
@@ -1204,6 +1207,25 @@ end function stdlib_exists
1204
1207
end if
1205
1208
end function exists
1206
1209
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
+
1207
1229
character function path_sep ()
1208
1230
if (OS_TYPE() == OS_WINDOWS) then
1209
1231
path_sep = ' \'
Original file line number Diff line number Diff line change @@ -119,3 +119,15 @@ int stdlib_exists(const char* path, int* stat){
119
119
#endif /* ifdef _WIN32 */
120
120
return type ;
121
121
}
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