-
Notifications
You must be signed in to change notification settings - Fork 192
feat: get_cwd
and set_cwd
#1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wassup05
wants to merge
11
commits into
fortran-lang:master
Choose a base branch
from
wassup05:cwd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8d00eea
added functions and relevant wrappers
wassup05 c9345c1
added tests
wassup05 d94d7fb
added specs
wassup05 e1f68d8
added examples
wassup05 c3db3a6
cleanup
wassup05 8012ac8
improve test flow a bit
wassup05 7056a36
add subroutines and C wrappers
wassup05 988127f
add C functions
wassup05 d8fedab
add example
wassup05 ae4dcc5
add docs
wassup05 3c0fd24
Merge branch 'master' into cwd
perazz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -535,6 +535,156 @@ The function returns a `logical` value: | |||||
|
||||||
--- | ||||||
|
||||||
## `make_directory` - Creates an empty directory | ||||||
|
||||||
### Status | ||||||
|
||||||
Experimental | ||||||
|
||||||
### Description | ||||||
|
||||||
It creates an empty directory. | ||||||
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted. | ||||||
|
||||||
### Syntax | ||||||
|
||||||
`call [[stdlib_system(module):make_directory(subroutine)]] (path, mode, err)` | ||||||
|
||||||
### Class | ||||||
|
||||||
Subroutine | ||||||
|
||||||
### Arguments | ||||||
|
||||||
`path`: Shall be a character string containing the path of the directory to create. It is an `intent(in)` argument. | ||||||
|
||||||
`mode`: Shall be a scalar integer indicating the permission bits required (Not applicable to Windows). It is an `optional, intent(in)` argument. | ||||||
|
||||||
`err`: Shall be of type `state_type`, for error handling. It is an `optional, intent(out)` argument. | ||||||
|
||||||
### Return values | ||||||
|
||||||
The `err` is set accordingly. | ||||||
|
||||||
### Example | ||||||
|
||||||
```fortran | ||||||
{!example/system/example_make_directory.f90!} | ||||||
``` | ||||||
|
||||||
--- | ||||||
|
||||||
## `remove_directory` - Removes an empty directory | ||||||
|
||||||
### Status | ||||||
|
||||||
Experimental | ||||||
|
||||||
### Description | ||||||
|
||||||
It deletes an empty directory. | ||||||
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted. | ||||||
|
||||||
### Syntax | ||||||
|
||||||
`call [[stdlib_system(module):remove_directory(subroutine)]] (path, err)` | ||||||
|
||||||
### Class | ||||||
|
||||||
Subroutine | ||||||
|
||||||
### Arguments | ||||||
|
||||||
`path`: Shall be a character string containing the path of the directory to create. It is an `intent(in)` argument. | ||||||
|
||||||
`err`: Shall be of type `state_type`, for error handling. It is an `intent(out)` argument. | ||||||
|
||||||
### Return values | ||||||
|
||||||
The `err` is set accordingly. | ||||||
|
||||||
### Example | ||||||
|
||||||
```fortran | ||||||
{!example/system/example_remove_directory.f90!} | ||||||
``` | ||||||
|
||||||
--- | ||||||
|
||||||
## `get_cwd` - Gets the current working directory | ||||||
|
||||||
### Status | ||||||
|
||||||
Experimental | ||||||
|
||||||
### Description | ||||||
|
||||||
It gets the current working directory associated with the process calling this subroutine. | ||||||
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted. | ||||||
|
||||||
### Syntax | ||||||
|
||||||
`call [[stdlib_system(module):get_cwd(subroutine)]] (cwd, err)` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
### Class | ||||||
|
||||||
Subroutine | ||||||
|
||||||
### Arguments | ||||||
|
||||||
`cwd`: Shall be a character string containing the path of the current working directory (cwd). It is an `intent(out)` argument. | ||||||
|
||||||
`err`: Shall be of type `state_type`, for error handling. It is an `intent(out)` argument. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
### Return values | ||||||
|
||||||
The `err` is set accordingly. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
### Example | ||||||
|
||||||
```fortran | ||||||
{!example/system/example_cwd.f90!} | ||||||
``` | ||||||
|
||||||
--- | ||||||
|
||||||
## `set_cwd` - Sets the current working directory | ||||||
|
||||||
### Status | ||||||
|
||||||
Experimental | ||||||
|
||||||
### Description | ||||||
|
||||||
It sets the current working directory associated with the process calling this subroutine. | ||||||
It is designed to work across multiple platforms. On Windows, paths with both forward `/` and backward `\` slashes are accepted. | ||||||
|
||||||
### Syntax | ||||||
|
||||||
`call [[stdlib_system(module):set_cwd(subroutine)]] (path, err)` | ||||||
|
||||||
### Class | ||||||
|
||||||
Subroutine | ||||||
|
||||||
### Arguments | ||||||
|
||||||
`path`: Shall be a character string containing the path of the directory. It is an `intent(in)` argument. | ||||||
|
||||||
`err`: Shall be of type `state_type`, for error handling. It is an `intent(out)` argument. | ||||||
|
||||||
### Return values | ||||||
|
||||||
The `err` is set accordingly. | ||||||
|
||||||
### Example | ||||||
|
||||||
```fortran | ||||||
{!example/system/example_cwd.f90!} | ||||||
``` | ||||||
|
||||||
--- | ||||||
|
||||||
## `null_device` - Return the null device file path | ||||||
|
||||||
### Status | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
! Illustrate the usage of get_cwd, set_cwd | ||
program example_cwd | ||
use stdlib_system, only: get_cwd, set_cwd | ||
use stdlib_error, only: state_type | ||
implicit none | ||
|
||
character(len=:), allocatable :: path | ||
type(state_type) :: err | ||
|
||
call get_cwd(path, err) | ||
|
||
if (err%error()) then | ||
print *, "Error getting current working directory: "//err%print() | ||
end if | ||
|
||
print *, "CWD: "//path | ||
|
||
call set_cwd("./src", err) | ||
|
||
if (err%error()) then | ||
print *, "Error setting current working directory: "//err%print() | ||
end if | ||
|
||
call get_cwd(path, err) | ||
|
||
if (err%error()) then | ||
print *, "Error getting current working directory after using set_cwd: "//err%print() | ||
return | ||
end if | ||
|
||
print *, "CWD: "//path | ||
end program example_cwd | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
! Illustrate the usage of make_directory | ||
program example_make_directory | ||
use stdlib_system, only: make_directory, is_directory | ||
use stdlib_error, only: state_type | ||
implicit none | ||
|
||
type(state_type) :: err | ||
|
||
call make_directory("test", err=err) | ||
|
||
if (err%error()) then | ||
print *, err%print() | ||
else | ||
print *, "directory created sucessfully" | ||
end if | ||
|
||
end program example_make_directory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
! Illustrate the usage of remove_directory | ||
program example_remove_directory | ||
use stdlib_system, only: make_directory, is_directory, remove_directory | ||
use stdlib_error, only: state_type | ||
implicit none | ||
|
||
type(state_type) :: err | ||
|
||
call remove_directory("directory_to_be_removed", err) | ||
|
||
if (err%error()) then | ||
print *, err%print() | ||
else | ||
print *, "directory removed successfully" | ||
end if | ||
|
||
end program example_remove_directory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.