# C Standard Library

`Base.Libc.malloc` — Function

    malloc(size::Integer) -> Ptr{Cvoid}

Call `malloc` from the C standard library.

source
`Base.Libc.calloc` — Function

    calloc(num::Integer, size::Integer) -> Ptr{Cvoid}

Call `calloc` from the C standard library.

source
`Base.Libc.realloc` — Function

    realloc(addr::Ptr, size::Integer) -> Ptr{Cvoid}

Call `realloc` from the C standard library.

See warning in the documentation for `free` regarding only using this on memory originally obtained from `malloc`.

source
`Base.memcpy` — Function

    memcpy(dst::Ptr, src::Ptr, n::Integer) -> Ptr{Cvoid}

Call `memcpy` from the C standard library.

Julia 1.10

Support for `memcpy` requires at least Julia 1.10.

source
`Base.memmove` — Function

    memmove(dst::Ptr, src::Ptr, n::Integer) -> Ptr{Cvoid}

Call `memmove` from the C standard library.

Julia 1.10

Support for `memmove` requires at least Julia 1.10.

source
`Base.memset` — Function

    memset(dst::Ptr, val, n::Integer) -> Ptr{Cvoid}

Call `memset` from the C standard library.

Julia 1.10

Support for `memset` requires at least Julia 1.10.

source
`Base.memcmp` — Function

    memcmp(a::Ptr, b::Ptr, n::Integer) -> Int

Call `memcmp` from the C standard library.

Julia 1.10

Support for `memcmp` requires at least Julia 1.9.

source
`Base.Libc.free` — Function

    free(addr::Ptr)

Call `free` from the C standard library. Only use this on memory obtained from `malloc`, not on pointers retrieved from other C libraries. `Ptr` objects obtained from C libraries should be freed by the free functions defined in that library, to avoid assertion failures if multiple `libc` libraries exist on the system.

source
`Base.Libc.errno` — Function

    errno([code])

Get the value of the C library's `errno`. If an argument is specified, it is used to set the value of `errno`.

The value of `errno` is only valid immediately after a `ccall` to a C library routine that sets it. Specifically, you cannot call `errno` at the next prompt in a REPL, because lots of code is executed between prompts.

source
`Base.Libc.strerror` — Function

    strerror(n=errno())

Convert a system call error code to a descriptive string

source
`Base.Libc.GetLastError` — Function

    GetLastError()

Call the Win32 `GetLastError` function [only available on Windows].

source
`Base.Libc.FormatMessage` — Function

    FormatMessage(n=GetLastError())

Convert a Win32 system call error code to a descriptive string [only available on Windows].

source
`Base.Libc.time` — Method

    time(t::TmStruct) -> Float64

Converts a `TmStruct` struct to a number of seconds since the epoch.

source
`Base.Libc.strftime` — Function

    strftime([format], time)

Convert time, given as a number of seconds since the epoch or a `TmStruct`, to a formatted string using the given format. Supported formats are the same as those in the standard C library.

source
`Base.Libc.strptime` — Function

    strptime([format], timestr)

Parse a formatted time string into a `TmStruct` giving the seconds, minute, hour, date, etc. Supported formats are the same as those in the standard C library. On some platforms, timezones will not be parsed correctly. If the result of this function will be passed to `time` to convert it to seconds since the epoch, the `isdst` field should be filled in manually. Setting it to `-1` will tell the C library to use the current system settings to determine the timezone.

source
`Base.Libc.TmStruct` — Type

    TmStruct([seconds])

Convert a number of seconds since the epoch to broken-down format, with fields `sec`, `min`, `hour`, `mday`, `month`, `year`, `wday`, `yday`, and `isdst`.

source
`Base.Libc.FILE` — Type

    FILE(::Ptr)
    FILE(::IO)

A libc `FILE*`, representing an opened file.

It can be passed as a `Ptr{FILE}` argument to `ccall` and also supports `seek`, `position` and `close`.

A `FILE` can be constructed from an ordinary `IO` object, provided it is an open file. It must be closed afterward.

Examples

    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"

source
`Base.Libc.dup` — Function

    dup(src::RawFD[, target::RawFD])::RawFD

Duplicate the file descriptor `src` so that the duplicate refers to the same OS resource (e.g. a file or socket). A `target` file descriptor may be optionally be passed to use for the new duplicate.

source
`Base.Libc.flush_cstdio` — Function

    flush_cstdio()

Flushes the C `stdout` and `stderr` streams (which may have been written to by external C code).

source
`Base.Libc.systemsleep` — Function

    systemsleep(s::Real)

Suspends execution for `s` seconds. This function does not yield to Julia's scheduler and therefore blocks the Julia thread that it is running on for the duration of the sleep time.

See also `sleep`.

source
`Base.Libc.mkfifo` — Function

    mkfifo(path::AbstractString, [mode::Integer]) -> path

Make a FIFO special file (a named pipe) at `path`. Return `path` as-is on success.

`mkfifo` is supported only in Unix platforms.

Julia 1.11

`mkfifo` requires at least Julia 1.11.

source

Theme

This document was generated with Documenter.jl version 1.16.0 on Thursday 20 November 2025. Using Julia version 1.12.2.