@@ -33,6 +33,8 @@ export BINDIR,
3333 iswindows,
3434 isjsvm,
3535 isexecutable,
36+ isreadable,
37+ iswriteable,
3638 username,
3739 which
3840
@@ -556,20 +558,81 @@ const WINDOWS_VISTA_VER = v"6.0"
556558
557559Return `true` if the given `path` has executable permissions.
558560
561+ !!! note
562+ This permission may change before the user executes `path`,
563+ so it is recommended to execute the file and handle the error if that fails,
564+ rather than calling `isexecutable` first.
565+
559566!!! note
560567 Prior to Julia 1.6, this did not correctly interrogate filesystem
561568 ACLs on Windows, therefore it would return `true` for any
562569 file. From Julia 1.6 on, it correctly determines whether the
563570 file is marked as executable or not.
571+
572+ See also [`ispath`](@ref), [`isreadable`](@ref), [`iswriteable`](@ref).
564573"""
565574function isexecutable (path:: String )
566575 # We use `access()` and `X_OK` to determine if a given path is
567576 # executable by the current user. `X_OK` comes from `unistd.h`.
568577 X_OK = 0x01
569- return ccall (:jl_fs_access , Cint, (Ptr{UInt8} , Cint), path, X_OK) == 0
578+ return ccall (:jl_fs_access , Cint, (Cstring , Cint), path, X_OK) == 0
570579end
571580isexecutable (path:: AbstractString ) = isexecutable (String (path))
572581
582+ """
583+ Sys.isreadable(path::String)
584+
585+ Return `true` if the access permissions for the given `path` permitted reading by the current user.
586+
587+ !!! note
588+ This permission may change before the user calls `open`,
589+ so it is recommended to just call `open` alone and handle the error if that fails,
590+ rather than calling `isreadable` first.
591+
592+ !!! note
593+ Currently this function does not correctly interrogate filesystem
594+ ACLs on Windows, therefore it can return wrong results.
595+
596+ !!! compat "Julia 1.11"
597+ This function requires at least Julia 1.11.
598+
599+ See also [`ispath`](@ref), [`isexecutable`](@ref), [`iswriteable`](@ref).
600+ """
601+ function isreadable (path:: String )
602+ # We use `access()` and `R_OK` to determine if a given path is
603+ # readable by the current user. `R_OK` comes from `unistd.h`.
604+ R_OK = 0x04
605+ return ccall (:jl_fs_access , Cint, (Cstring, Cint), path, R_OK) == 0
606+ end
607+ isreadable (path:: AbstractString ) = isreadable (String (path))
608+
609+ """
610+ Sys.iswriteable(path::String)
611+
612+ Return `true` if the access permissions for the given `path` permitted writing by the current user.
613+
614+ !!! note
615+ This permission may change before the user calls `open`,
616+ so it is recommended to just call `open` alone and handle the error if that fails,
617+ rather than calling `iswriteable` first.
618+
619+ !!! note
620+ Currently this function does not correctly interrogate filesystem
621+ ACLs on Windows, therefore it can return wrong results.
622+
623+ !!! compat "Julia 1.11"
624+ This function requires at least Julia 1.11.
625+
626+ See also [`ispath`](@ref), [`isexecutable`](@ref), [`isreadable`](@ref).
627+ """
628+ function iswriteable (path:: String )
629+ # We use `access()` and `W_OK` to determine if a given path is
630+ # writeable by the current user. `W_OK` comes from `unistd.h`.
631+ W_OK = 0x02
632+ return ccall (:jl_fs_access , Cint, (Cstring, Cint), path, W_OK) == 0
633+ end
634+ iswriteable (path:: AbstractString ) = iswriteable (String (path))
635+
573636"""
574637 Sys.which(program_name::String)
575638
0 commit comments