Skip to content

Commit

Permalink
document Libc.FILE (#49908)
Browse files Browse the repository at this point in the history
Adds some missing documentation for `Libc.FILE`, which is already
exported.
  • Loading branch information
cjdoris authored Jul 27, 2023
1 parent dc06468 commit da19bc1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ end

## FILE (not auto-finalized) ##

"""
FILE(::Ptr)
FILE(::IO)
A libc `FILE*`, representing an opened file.
It can be passed as a `Ptr{FILE}` argument to [`ccall`](@ref) and also supports
[`seek`](@ref), [`position`](@ref) and [`close`](@ref).
A `FILE` can be constructed from an ordinary `IO` object, provided it is an open file. It
must be closed afterward.
# Examples
```jldoctest
julia> using Base.Libc
julia> mktemp() do _, io
# write to the temporary file using `puts(char*, FILE*)` from libc
file = FILE(io)
ccall(:fputs, Cint, (Cstring, Ptr{FILE}), "hello world", file)
close(file)
# read the file again
seek(io, 0)
read(io, String)
end
"hello world"
```
"""
struct FILE
ptr::Ptr{Cvoid}
end
Expand Down
1 change: 1 addition & 0 deletions doc/src/base/libc.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Base.Libc.time(::Base.Libc.TmStruct)
Base.Libc.strftime
Base.Libc.strptime
Base.Libc.TmStruct
Base.Libc.FILE
Base.Libc.flush_cstdio
Base.Libc.systemsleep
```

0 comments on commit da19bc1

Please sign in to comment.