From 06c6c56fddf41b30a762698f5fc86c02f6a90d50 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Thu, 15 Feb 2024 23:28:53 +0100 Subject: [PATCH] wip: temporary fix for ispath --- base/stat.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/base/stat.jl b/base/stat.jl index f527664f228ada..35e02d2c373f99 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -327,10 +327,15 @@ This is the generalization of [`isfile`](@ref), [`isdir`](@ref) etc. """ ispath(st::StatStruct) = filemode(st) & 0xf000 != 0x0000 function ispath(path::String) + if contains(path, '\0') + throw(ArgumentError("embedded NULs are not allowed in C strings: \"$(repr(path))\"")) + end # We use `access()` and `F_OK` to determine if a given path exists. # `F_OK` comes from `unistd.h`. F_OK = 0x00 - return ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, F_OK) == 0 + res = ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, F_OK) + @assert res in (0, Base.UV_ENOENT) + return res == 0 end ispath(path::AbstractString) = ispath(String(path))