Skip to content

Commit 306bc86

Browse files
committed
better docs
1 parent 1aa265d commit 306bc86

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

doc/specs/stdlib_system.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,16 +654,15 @@ Experimental
654654

655655
### Description
656656

657-
This function performs a system call (syscall) to the operating system, to retrieve the metadata
658-
corresponding to the path, and identifies the type of path it is.
659-
It can distinguish among the following path types
657+
This function makes a system call (syscall) to retrieve metadata for the specified path and determines its type.
658+
It can distinguish between the following path types:
660659

661660
- Regular File
662661
- Directory
663662
- Symbolic Link
664663

665-
Returns a constant representing the path type or `type_unknown` if it cannot be determined.
666-
If there has been an error, It is handled using `state_type`.
664+
It returns a constant representing the detected path type, or `type_unknown` if the type cannot be determined.
665+
Any encountered errors are handled using `state_type`.
667666

668667
### Syntax
669668

@@ -681,7 +680,7 @@ Function
681680

682681
### Return values
683682

684-
`err` is an optional state return flag. On error if not requested, an `FS_ERROR` will trigger an error stop.
683+
`err` is an optional state return flag. If not requested and an error occurs, an `FS_ERROR` will trigger an error stop.
685684

686685
### Example
687686

example/system/example_exists.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ program example_exists
77

88
type(state_type) :: err
99

10+
! Path to check
1011
character(*), parameter :: path = "path"
12+
! To get the type of the path
1113
integer :: t
1214

1315
t = exists(path, err)
1416

1517
if (err%error()) then
18+
! An error occured, print it
1619
print *, err%print()
1720
end if
1821

22+
! switching on the types returned by `exists`
1923
select case (t)
2024
case (type_unknown); print *, "Unknown type!"
2125
case (type_regular_file); print *, "Regular File!"

src/stdlib_system.F90

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,16 @@ module stdlib_system
229229
!! If the path does exist, returns the type of the path.
230230
!!
231231
!!### Description
232-
!!
233-
!! The function performs a system call (syscall) to the operating system, to retrieve the metadata
234-
!! corresponding to a path, and identifies the type of path it is.
235-
!! It can distinguish among the following path types
232+
!!
233+
!! This function makes a system call (syscall) to retrieve metadata for the specified path and determines its type.
234+
!! It can distinguish between the following path types:
236235
!!
237236
!! - Regular File
238237
!! - Directory
239238
!! - Symbolic Link
240239
!!
241-
!! Returns a constant representing the path type or `type_unknown` if it cannot be determined.
242-
!! If there has been an error, It is handled using `state_type`.
240+
!! It returns a constant representing the detected path type, or `type_unknown` if the type cannot be determined.
241+
!! Any encountered errors are handled using `state_type`.
243242
!!
244243
public :: exists
245244

@@ -1177,6 +1176,7 @@ pure function FS_ERROR(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,&
11771176
a13,a14,a15,a16,a17,a18,a19,a20)
11781177
end function FS_ERROR
11791178

1179+
! checks if a path exists and returns its type
11801180
function exists(path, err) result(fs_type)
11811181
character(*), intent(in) :: path
11821182
type(state_type), optional, intent(out) :: err
@@ -1188,6 +1188,7 @@ function exists(path, err) result(fs_type)
11881188
integer function stdlib_exists(path, stat) bind(C, name='stdlib_exists')
11891189
import c_char, c_int
11901190
character(kind=c_char), intent(in) :: path(*)
1191+
! to return the error code if any
11911192
integer(kind=c_int), intent(out) :: stat
11921193
end function stdlib_exists
11931194
end interface
@@ -1196,6 +1197,7 @@ end function stdlib_exists
11961197

11971198
fs_type = stdlib_exists(to_c_char(trim(path)), stat)
11981199

1200+
! an error occurred
11991201
if (stat /= 0) then
12001202
err0 = FS_ERROR_CODE(stat, c_get_strerror())
12011203
call err0%handle(err)

src/stdlib_system.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int stdlib_exists(const char* path, int* stat){
9494
return type_unknown;
9595
}
9696

97-
// It is not a directory or a symlink
97+
// Let's assume it is a regular file
9898
type = type_regular_file;
9999

100100
if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) type = type_symlink;

0 commit comments

Comments
 (0)