-
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
base: master
Are you sure you want to change the base?
Conversation
I am honestly not sure how I should go about testing these functions independently |
If I uncerstand correctly, it looks like you're already doing that by invoking |
Those are commits from the other branch @sebastian-mutz, the one in this PR: #1014 I don't think I can use |
Suggestions for testing (summarising from the chat with Jose): For testing For testing Alternatively, using |
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.
Thank you for this PR @wassup05. Here is a couple of comments:
- the state handler
err
should be optional. So, the internalhandle
ing features returning the state variable if present, or triggering an error stop if not. This will make behavior consistent to everywhere else. - For testing: I think set/get can be tested in the same test program imho. Here is an example:
- get current directory and save it to "pwd" variable -> must be successful
- create a new local temporary directory -> must be successful
set_cwd
to thatget_cwd
should now return the temporary directoryset_cwd
back to "pwd"- check successful
I suggest to merge this PR after directory handling is merged into the library already.
|
||
### Description | ||
|
||
It gets the current working directory associated with the process calling this subroutine. |
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.
It gets the current working directory associated with the process calling this subroutine. | |
This subroutine retrieves the current working directory the running process is executing from. |
|
||
### Syntax | ||
|
||
`call [[stdlib_system(module):get_cwd(subroutine)]] (cwd, err)` |
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.
`call [[stdlib_system(module):get_cwd(subroutine)]] (cwd, err)` | |
`call [[stdlib_system(module):get_cwd(subroutine)]] (cwd [, err])` |
|
||
`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 comment
The reason will be displayed to describe this comment to others. Learn more.
`err`: Shall be of type `state_type`, for error handling. It is an `intent(out)` argument. | |
`err` (optional): Shall be of type `state_type`, for error handling. It is an `intent(out)` argument. |
|
||
### Return values | ||
|
||
The `err` is set accordingly. |
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.
The `err` is set accordingly. | |
`err` is an optional state return flag. On error if not requested, a `FS_ERROR` will trigger an error stop. |
|
||
subroutine set_cwd(path, err) | ||
character(len=*), intent(in) :: path | ||
type(state_type), intent(out) :: err |
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.
type(state_type), intent(out) :: err | |
type(state_type), optional, intent(out) :: err |
|
||
subroutine get_cwd(cwd, err) | ||
character(:), allocatable, intent(out) :: cwd | ||
type(state_type), intent(out) :: err |
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.
type(state_type), intent(out) :: err | |
type(state_type), optional, intent(out) :: err |
src/stdlib_system.F90
Outdated
@@ -2,7 +2,7 @@ module stdlib_system | |||
use, intrinsic :: iso_c_binding, only : c_int, c_long, c_ptr, c_null_ptr, c_int64_t, c_size_t, & | |||
c_f_pointer | |||
use stdlib_kinds, only: int64, dp, c_bool, c_char | |||
use stdlib_strings, only: to_c_char | |||
use stdlib_strings, only: to_c_char, to_string | |||
use stdlib_error, only: state_type, STDLIB_SUCCESS, STDLIB_FS_ERROR |
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.
use stdlib_error, only: state_type, STDLIB_SUCCESS, STDLIB_FS_ERROR | |
use stdlib_error, only: state_type, STDLIB_SUCCESS, FS_ERROR |
|
||
if (is_windows() .and. present(mode)) then | ||
! _mkdir() doesn't have a `mode` argument | ||
err0 = state_type(STDLIB_FS_ERROR, "mode argument not present for Windows") |
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.
err0 = state_type(STDLIB_FS_ERROR, "mode argument not present for Windows") | |
err0 = FS_ERROR("mode argument not available on Windows") |
return | ||
case default | ||
! error | ||
err0 = state_type(STDLIB_FS_ERROR, "code:", to_string(code)//',', c_get_strerror()) |
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.
err0 = state_type(STDLIB_FS_ERROR, "code:", to_string(code)//',', c_get_strerror()) | |
err0 = FS_ERROR_CODE(code, c_get_strerror()) |
Depends on #1011
get_cwd (cwd, err)
- Gets the current working directory (cwd) of the process.set_cwd (path, err)
- Sets the current working directory (cwd) of the process.getcwd, chdir
on Unix and_getcwd, _chdir
on Windowsstate_type
and both the platform specific error code and the user friendly error message are provided if an error occurs