@@ -33,6 +33,8 @@ export BINDIR,
33
33
iswindows,
34
34
isjsvm,
35
35
isexecutable,
36
+ isreadable,
37
+ iswriteable,
36
38
username,
37
39
which
38
40
@@ -556,20 +558,81 @@ const WINDOWS_VISTA_VER = v"6.0"
556
558
557
559
Return `true` if the given `path` has executable permissions.
558
560
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
+
559
566
!!! note
560
567
Prior to Julia 1.6, this did not correctly interrogate filesystem
561
568
ACLs on Windows, therefore it would return `true` for any
562
569
file. From Julia 1.6 on, it correctly determines whether the
563
570
file is marked as executable or not.
571
+
572
+ See also [`ispath`](@ref), [`isreadable`](@ref), [`iswriteable`](@ref).
564
573
"""
565
574
function isexecutable (path:: String )
566
575
# We use `access()` and `X_OK` to determine if a given path is
567
576
# executable by the current user. `X_OK` comes from `unistd.h`.
568
577
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
570
579
end
571
580
isexecutable (path:: AbstractString ) = isexecutable (String (path))
572
581
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
+
573
636
"""
574
637
Sys.which(program_name::String)
575
638
0 commit comments