The C Standard Library
#
Base.Libc.malloc
— Function
malloc(size::Integer) -> Ptr{Cvoid}
Calls malloc
from the C standard library.
#
Base.Libc.calloc
— Function
calloc(num::Integer, size::Integer) -> Ptr{Cvoid}
Calls calloc
from the C standard library.
#
Base.memcpy
— Function
memcpy(dst::Ptr, src::Ptr, n::Integer) -> Ptr{Cvoid}
Calls `memcpy' from the C standard library.
Compatibility: Julia 1.10
To support memcpy` a version of Julia at least 1.10 is required. |
#
Base.memmove
— Function
memmove(dst::Ptr, src::Ptr, n::Integer) -> Ptr{Cvoid}
Calls `memmove' from the C standard library.
Compatibility: Julia 1.10
To support memmove` a version of Julia at least 1.10 is required. |
#
Base.memset
— Function
memset(dst::Ptr, val, n::Integer) -> Ptr{Cvoid}
Calls memset
from the C standard library.
Compatibility: Julia 1.10
Julia version 1.10 or higher is required to support memset. |
#
Base.memcmp
— Function
memcmp(a::Ptr, b::Ptr, n::Integer) -> Int
Calls memcmp
from the C standard library.
Compatibility: Julia 1.10
To support memcmp` a Julia version of at least 1.9 is required. |
#
Base.Libc.free
— Function
free(addr::Ptr)
Calls free
from the C standard library. This feature can only be used for memory received from malloc
, but not for pointers obtained from other libraries with. Objects 'Ptr` received from C libraries should be released by the appropriate functions defined in these libraries to prevent approval failures in cases where there are multiple libc
libraries in the system.
#
Base.Libc.errno
— Function
errno([code])
Gets the value from the errno
library with. If an argument is specified, it is used to specify the value of `errno'.
The value of errno' is valid only immediately after calling `ccall
the C library routine that sets it. In particular, you cannot call `errno' on the next command line in the REPL, because most of the code is executed between command lines.
#
Base.Libc.strerror
— Function
strerror(n=errno())
Converts the system call error code into a string with a description.
#
Base.Libc.GetLastError
— Function
GetLastError()
Calls the Win32 function `GetLastError' (available only on Windows).
#
Base.Libc.FormatMessage
— Function
FormatMessage(n=GetLastError())
Converts the error code of the Win32 system call into a string with a description (available only in Windows).
#
Base.Libc.time
— Method
time(t::TmStruct) -> Float64
Converts the `TmStruct' structure to a time value (in seconds) from the beginning of the countdown.
#
Base.Libc.strftime
— Function
strftime([format], time)
Converts the time value specified in seconds from the start of the countdown or TmStruct
to a formatted string using the specified format. The same formats are supported as in the C standard library.
#
Base.Libc.strptime
— Function
strptime([format], timestr)
Analyzes the formatted string of the time value in 'TmStruct', giving seconds, minutes, hours, date, etc. The same formats are supported as in the C standard library. Time zones are not analyzed correctly on some platforms. If the result of this function is passed to time
to be converted to a time value (in seconds) from the start of the countdown, the isdst
field must be filled in manually. The set value -1
tells the C library that it is necessary to use the current system settings to determine the time zone.
#
Base.Libc.TmStruct
— Type
TmStruct([seconds])
Converts the time in seconds from the start of the countdown to a broken format (with the fields sec
, min
, hour
, mday
, month
, year
, wday
, yday
and `isdst').
#
Base.Libc.FILE
— Type
FILE(::Ptr)
FILE(::IO)
A libc FILE*
object representing an open file.
It can be passed as an argument to Ptr{FILE}
in ccall
. In addition, it supports seek
, position
and close
.
A FILE
can be created from a regular IO
object, provided that it is an open file. It should be closed later.
Examples
julia> using Base.Libc
julia> mktemp() do _, io
# write to a temporary file using `puts(char*, FILE*)` from libc
file = FILE(io)
ccall(:fputs, Cint, (Cstring, Ptr{FILE}), "hello world", file)
close(file)
# reading the file again
seek(io, 0)
read(io, String)
end
"hello world"
#
Base.Libc.flush_cstdio
— Function
flush_cstdio()
Clears the C execution streams stdout
and stderr
(which could have been written from third-party C code).
#
Base.Libc.mkfifo
— Function
mkfifo(path::AbstractString, [mode::Integer]) -> path
Creates a special FIFO file (named pipe) in the path'. On success, it returns the `path
as it is.
'mkfifo` is supported only on Unix platforms.
Compatibility: Julia 1.11
mkfifo requires a version of Julia not lower than 1.11. |