Skip to content

Commit da19bc1

Browse files
authored
document Libc.FILE (#49908)
Adds some missing documentation for `Libc.FILE`, which is already exported.
1 parent dc06468 commit da19bc1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

base/libc.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ end
7575

7676
## FILE (not auto-finalized) ##
7777

78+
"""
79+
FILE(::Ptr)
80+
FILE(::IO)
81+
82+
A libc `FILE*`, representing an opened file.
83+
84+
It can be passed as a `Ptr{FILE}` argument to [`ccall`](@ref) and also supports
85+
[`seek`](@ref), [`position`](@ref) and [`close`](@ref).
86+
87+
A `FILE` can be constructed from an ordinary `IO` object, provided it is an open file. It
88+
must be closed afterward.
89+
90+
# Examples
91+
```jldoctest
92+
julia> using Base.Libc
93+
94+
julia> mktemp() do _, io
95+
# write to the temporary file using `puts(char*, FILE*)` from libc
96+
file = FILE(io)
97+
ccall(:fputs, Cint, (Cstring, Ptr{FILE}), "hello world", file)
98+
close(file)
99+
# read the file again
100+
seek(io, 0)
101+
read(io, String)
102+
end
103+
"hello world"
104+
```
105+
"""
78106
struct FILE
79107
ptr::Ptr{Cvoid}
80108
end

doc/src/base/libc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Base.Libc.time(::Base.Libc.TmStruct)
1717
Base.Libc.strftime
1818
Base.Libc.strptime
1919
Base.Libc.TmStruct
20+
Base.Libc.FILE
2021
Base.Libc.flush_cstdio
2122
Base.Libc.systemsleep
2223
```

0 commit comments

Comments
 (0)