# Libc.FILE for stdout

**URL:** https://discourse.julialang.org/t/libc-file-for-stdout/22482
**Category:** General Usage
**Tags:** ccall
**Created:** [March 28, 2019, 10:39pm UTC](https://discourse.julialang.org/t/libc-file-for-stdout/22482 "2019-03-28T22:39:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [March 28, 2019, 10:39pm UTC](https://discourse.julialang.org/t/libc-file-for-stdout/22482/1 "2019-03-28T22:39:51Z")

</div>

I need to `ccall` a function that expects a C `FILE *`. To have the function write to a file on disk, I figured out that I can get an appropriate `FILE *` using

```julia
foo = open("foo.txt", "w")
Libc.FILE(foo)

```

This works fine, but I’d also like to be able to have this work for `stdout`. So I tried:

```julia
Libc.FILE(stdout)
ERROR: MethodError: no method matching fd(::Base.TTY)
Closest candidates are:
  fd(::Base.Filesystem.File) at filesystem.jl:231
  fd(::IOStream) at iostream.jl:36
Stacktrace:
 [1] Base.Libc.FILE(::Base.TTY) at ./libc.jl:87
 [2] top-level scope at none:0

```

I can instead do

```julia
Libc.FILE(RawFD(1), "w")

```

but is the fact that `Libc.FILE(stdout)` doesn’t work an oversight?

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [March 29, 2019, 1:54am UTC](https://discourse.julialang.org/t/libc-file-for-stdout/22482/2 "2019-03-29T01:54:25Z")

</div>

So in this method:

> <https://github.com/JuliaLang/julia/blob/80516ca20297a67b996caa08c38786332379b6a5/base/libc.jl#L86-L90>

there are two issues for `TTY`:

- `fd(::TTY)` is not defined; however `Base._fd(::TTY)` exists and appears to return a valid `RawFD` for `stdout`; so why don’t we just have `Base.fd(io::TTY) = Base._fd(io)`?
- `position(::TTY)` and `seek(::TTY)` are not defined. Should there be an `isseekable(io::IO)` function to guard this?

---

<div class="post-metadata">

### Author: ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)
#### Post date: [March 1, 2022, 7:57pm UTC](https://discourse.julialang.org/t/libc-file-for-stdout/22482/3 "2022-03-01T19:57:04Z")

</div>

Same issue when using an `IOBuffer`
