Skip to content
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

Add Libc.mkfifo #34587

Merged
merged 19 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Libc.mkfifo
  • Loading branch information
tkf committed Jan 30, 2020
commit e48ada68cb70acbf90a9e31c4a055a4d80fb2b33
21 changes: 21 additions & 0 deletions base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Core.Intrinsics: bitcast

export FILE, TmStruct, strftime, strptime, getpid, gethostname, free, malloc, calloc, realloc,
errno, strerror, flush_cstdio, systemsleep, time, transcode
if Sys.isunix()
tkf marked this conversation as resolved.
Show resolved Hide resolved
export mkfifo
end
if Sys.iswindows()
export GetLastError, FormatMessage
end
Expand Down Expand Up @@ -400,4 +403,22 @@ Interface to the C `srand(seed)` function.
"""
srand(seed=floor(Int, time()) % Cuint) = ccall(:srand, Cvoid, (Cuint,), seed)

if Sys.isunix()
tkf marked this conversation as resolved.
Show resolved Hide resolved
@doc """
mkfifo(path::AbstractString, [mode::Integer]) -> path

Make a FIFO special file (a named pipe) at `path`. Return `path` as-is on success.
""" ->
function mkfifo(
path::AbstractString,
mode::Integer = Base.S_IRUSR | Base.S_IWUSR | Base.S_IRGRP | Base.S_IWGRP |
Base.S_IROTH | Base.S_IWOTH,
)
# Default `mode` is compatible with `mkfifo` CLI in coreutils.
ret = ccall(:mkfifo, Cint, (Cstring, Base.Cmode_t), path, mode)
systemerror("mkfifo", ret == -1)
return path
end
end

end # module
16 changes: 16 additions & 0 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1477,3 +1477,19 @@ end
end
end
end

@testset "mkfifo" begin
mktempdir() do dir
path = Libc.mkfifo(joinpath(dir, "fifo"))
@sync begin
cat_exec = `$(Base.julia_cmd()) --startup-file=no -e "write(stdout, read(ARGS[1]))"`
reader = @async read(`$cat_exec $path`, String)
@async write(path, "hello")
@test fetch(reader) == "hello"
end

existing_file = joinpath(dir, "existing")
write(existing_file, "")
@test_throws SystemError Libc.mkfifo(existing_file)
end
end