Help with ccall to clib functions

You originally had termios be a immutable type, so no C code can mutate the variable tty which is of an immutable type (see the implication of immutable type I give above). If you keep it as immutable you can embed it in a mutable type (the common one used being Ref) which will allow the C code to mutate it (much the same as embedding the tuple in the mutable termios allows C code to mutate the tuple content). You can (have) achieve(d) the same by making termios itself a mutable type.

I think you wanted message[buffer + 1] = 0

This is invalid although it shouldn’t be the problem. You should resize the message and call String on it.

So you should write, roughly

message = Vector{UInt8}(bufSize)
buffer = ccall((:read, "libc"), Int32, (Int, Ptr{UInt8}, Csize_t), fd, message, sizeof(message))
resize!(message, buffer)
println(String(message))

So, can I ask you where you learn all of this from. I know I’m new to Julia, but you’re like amazing with your knowledge of it.

Well, that didn’t help the garbage, but thanks for helping me correct my code. I’ll go through it line by line versus the C code and see if I screwed something up.

Well, not really all at the same place/through the same way and that’s a hard question in general…

By falling into the trap of the subtle difference between array and pointer in C mutiple time…

For most of the rest, they are from trying things myself, reading the doc and following github issues. For most of the issues mentioned here, it helps to have a clear model of the layout and the things that are allowed though.

I do agree that the doc needs improvements, not just for what each function does but also how they can be used. I myself is pretty bad at doing that though so I took the approach of answering questions and hoping one of the readers can do a better job contributing to the doc knowing what’s not obvious for them.