Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a5a340e

Browse files
committed
type renaming + docs
1 parent 306bc86 commit a5a340e

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

‎doc/specs/stdlib_system.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ Any encountered errors are handled using `state_type`.
666666

667667
### Syntax
668668

669-
`res = [[stdlib_system(module):exists(function)]] (path [, err])`
669+
`fs_type = [[stdlib_system(module):exists(function)]] (path [, err])`
670670

671671
### Class
672672

@@ -680,7 +680,13 @@ Function
680680

681681
### Return values
682682

683-
`err` is an optional state return flag. If not requested and an error occurs, an `FS_ERROR` will trigger an error stop.
683+
`fs_type`: An `intent(out), integer` parameter indicating the type. The possible values are:
684+
- `fs_type_unknown`: 0 => an unknown type
685+
- `fs_type_regular_file`: 1 => a regular file
686+
- `fs_type_directory`: 2 => a directory
687+
- `fs_type_symlink`: 3 => a symbolic link
688+
689+
`err`(optional): It is an optional state return flag. If not requested and an error occurs, an `FS_ERROR` will trigger an error stop.
684690

685691
### Example
686692

‎example/system/example_exists.f90‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! Illustrate the usage of `exists`
22
program example_exists
3-
use stdlib_system, only: exists, type_unknown, type_regular_file, &
4-
type_directory, type_symlink
3+
use stdlib_system, only: exists, fs_type_unknown, fs_type_regular_file, &
4+
fs_type_directory, fs_type_symlink
55
use stdlib_error, only: state_type
66
implicit none
77

@@ -19,12 +19,12 @@ program example_exists
1919
print *, err%print()
2020
end if
2121

22-
! switching on the types returned by `exists`
22+
! switching on the type returned by `exists`
2323
select case (t)
24-
case (type_unknown); print *, "Unknown type!"
25-
case (type_regular_file); print *, "Regular File!"
26-
case (type_directory); print *, "Directory!"
27-
case (type_symlink); print *, "Symbolic Link!"
24+
case (fs_type_unknown); print *, "Unknown type!"
25+
case (fs_type_regular_file); print *, "Regular File!"
26+
case (fs_type_directory); print *, "Directory!"
27+
case (fs_type_symlink); print *, "Symbolic Link!"
2828
end select
2929
end program example_exists
3030

‎src/stdlib_system.F90‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,13 @@ module stdlib_system
211211
!> ([Specification](../page/specs/stdlib_system.html))
212212
integer, parameter, public :: &
213213
!> Represents an unknown path type
214-
type_unknown = 0, &
214+
fs_type_unknown = 0, &
215215
!> Represents a regular file
216-
type_regular_file = 1, &
216+
fs_type_regular_file = 1, &
217217
!> Represents a directory
218-
type_directory = 2, &
218+
fs_type_directory = 2, &
219219
!> Represents a symbolic link
220-
type_symlink = 3
220+
fs_type_symlink = 3
221221

222222
!! version: experimental
223223
!!

‎src/stdlib_system.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,27 @@ int stdlib_remove_directory(const char* path){
7878
// Returns the `type` of the path, and sets the `stat`(if any errors).
7979
int stdlib_exists(const char* path, int* stat){
8080
// All the valid types
81-
const int type_unknown = 0;
82-
const int type_regular_file = 1;
83-
const int type_directory = 2;
84-
const int type_symlink = 3;
81+
const int fs_type_unknown = 0;
82+
const int fs_type_regular_file = 1;
83+
const int fs_type_directory = 2;
84+
const int fs_type_symlink = 3;
8585

86-
int type = type_unknown;
86+
int type = fs_type_unknown;
8787
*stat = 0;
8888

8989
#ifdef _WIN32
9090
DWORD attrs = GetFileAttributesA(path);
9191

9292
if (attrs == INVALID_FILE_ATTRIBUTES) {
9393
*stat = (int) GetLastError();
94-
return type_unknown;
94+
return fs_type_unknown;
9595
}
9696

9797
// Let's assume it is a regular file
98-
type = type_regular_file;
98+
type = fs_type_regular_file;
9999

100-
if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) type = type_symlink;
101-
if (attrs & FILE_ATTRIBUTE_DIRECTORY) type = type_directory;
100+
if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) type = fs_type_symlink;
101+
if (attrs & FILE_ATTRIBUTE_DIRECTORY) type = fs_type_directory;
102102
#else
103103
struct stat buf = {0};
104104
int status;
@@ -107,14 +107,14 @@ int stdlib_exists(const char* path, int* stat){
107107
if (status == -1) {
108108
// `lstat` failed
109109
*stat = errno;
110-
return type_unknown;
110+
return fs_type_unknown;
111111
}
112112

113113
switch (buf.st_mode & S_IFMT) {
114-
case S_IFREG: type = type_regular_file; break;
115-
case S_IFDIR: type = type_directory; break;
116-
case S_IFLNK: type = type_symlink; break;
117-
default: type = type_unknown; break;
114+
case S_IFREG: type = fs_type_regular_file; break;
115+
case S_IFDIR: type = fs_type_directory; break;
116+
case S_IFLNK: type = fs_type_symlink; break;
117+
default: type = fs_type_unknown; break;
118118
}
119119
#endif /* ifdef _WIN32 */
120120
return type;

‎test/system/test_filesystem.f90‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module test_filesystem
22
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
33
use stdlib_system, only: is_directory, delete_file, FS_ERROR, FS_ERROR_CODE, &
44
make_directory, remove_directory, make_directory_all, is_windows, OS_TYPE, &
5-
OS_WINDOWS, exists, type_unknown, type_regular_file, type_directory, type_symlink
5+
OS_WINDOWS, exists, fs_type_unknown, fs_type_regular_file, fs_type_directory, fs_type_symlink
66
use stdlib_error, only: state_type, STDLIB_FS_ERROR
77
use stdlib_strings, only: to_string
88

@@ -89,7 +89,7 @@ subroutine test_exists_reg_file(error)
8989
return
9090
end if
9191

92-
call check(error, t == type_regular_file, "exists incorrectly identifies type of &
92+
call check(error, t == fs_type_regular_file, "exists incorrectly identifies type of &
9393
reg files!: type=" // to_string(t))
9494

9595
if (allocated(error)) then
@@ -130,7 +130,7 @@ subroutine test_exists_dir(error)
130130
return
131131
end if
132132

133-
call check(error, t == type_directory, "exists incorrectly identifies type of &
133+
call check(error, t == fs_type_directory, "exists incorrectly identifies type of &
134134
directories!: type=" // to_string(t))
135135

136136
if (allocated(error)) then
@@ -193,7 +193,7 @@ subroutine test_exists_symlink(error)
193193
return
194194
end if
195195

196-
call check(error, t == type_symlink, "exists incorrectly identifies type of &
196+
call check(error, t == fs_type_symlink, "exists incorrectly identifies type of &
197197
symlinks!: type=" // to_string(t))
198198

199199
if (allocated(error)) then

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /