<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>C Standard Library · The Julia Language</title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
</script><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/><link href="../assets/julia-manual.css" rel="stylesheet" type="text/css"/></head><body><nav class="toc"><a href="../index.html"><img class="logo" src="../assets/logo.png" alt="The Julia Language logo"/></a><h1>The Julia Language</h1><select id="version-selector" onChange="window.location.href=this.value" style="visibility: hidden"></select><form class="search" id="search-form" action="../search.html"><input id="search-query" name="q" type="text" placeholder="Search docs"/></form><ul><li><a class="toctext" href="../index.html">Home</a></li><li><span class="toctext">Manual</span><ul><li><a class="toctext" href="../manual/introduction.html">Introduction</a></li><li><a class="toctext" href="../manual/getting-started.html">Getting Started</a></li><li><a class="toctext" href="../manual/variables.html">Variables</a></li><li><a class="toctext" href="../manual/integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a></li><li><a class="toctext" href="../manual/mathematical-operations.html">Mathematical Operations and Elementary Functions</a></li><li><a class="toctext" href="../manual/complex-and-rational-numbers.html">Complex and Rational Numbers</a></li><li><a class="toctext" href="../manual/strings.html">Strings</a></li><li><a class="toctext" href="../manual/functions.html">Functions</a></li><li><a class="toctext" href="../manual/control-flow.html">Control Flow</a></li><li><a class="toctext" href="../manual/variables-and-scoping.html">Scope of Variables</a></li><li><a class="toctext" href="../manual/types.html">Types</a></li><li><a class="toctext" href="../manual/methods.html">Methods</a></li><li><a class="toctext" href="../manual/constructors.html">Constructors</a></li><li><a class="toctext" href="../manual/conversion-and-promotion.html">Conversion and Promotion</a></li><li><a class="toctext" href="../manual/interfaces.html">Interfaces</a></li><li><a class="toctext" href="../manual/modules.html">Modules</a></li><li><a class="toctext" href="../manual/documentation.html">Documentation</a></li><li><a class="toctext" href="../manual/metaprogramming.html">Metaprogramming</a></li><li><a class="toctext" href="../manual/arrays.html">Multi-dimensional Arrays</a></li><li><a class="toctext" href="../manual/linear-algebra.html">Linear algebra</a></li><li><a class="toctext" href="../manual/networking-and-streams.html">Networking and Streams</a></li><li><a class="toctext" href="../manual/parallel-computing.html">Parallel Computing</a></li><li><a class="toctext" href="../manual/dates.html">Date and DateTime</a></li><li><a class="toctext" href="../manual/interacting-with-julia.html">Interacting With Julia</a></li><li><a class="toctext" href="../manual/running-external-programs.html">Running External Programs</a></li><li><a class="toctext" href="../manual/calling-c-and-fortran-code.html">Calling C and Fortran Code</a></li><li><a class="toctext" href="../manual/handling-operating-system-variation.html">Handling Operating System Variation</a></li><li><a class="toctext" href="../manual/environment-variables.html">Environment Variables</a></li><li><a class="toctext" href="../manual/embedding.html">Embedding Julia</a></li><li><a class="toctext" href="../manual/packages.html">Packages</a></li><li><a class="toctext" href="../manual/profile.html">Profiling</a></li><li><a class="toctext" href="../manual/stacktraces.html">Stack Traces</a></li><li><a class="toctext" href="../manual/performance-tips.html">Performance Tips</a></li><li><a class="toctext" href="../manual/workflow-tips.html">Workflow Tips</a></li><li><a class="toctext" href="../manual/style-guide.html">Style Guide</a></li><li><a class="toctext" href="../manual/faq.html">Frequently Asked Questions</a></li><li><a class="toctext" href="../manual/noteworthy-differences.html">Noteworthy Differences from other Languages</a></li><li><a class="toctext" href="../manual/unicode-input.html">Unicode Input</a></li></ul></li><li><span class="toctext">Standard Library</span><ul><li><a class="toctext" href="base.html">Essentials</a></li><li><a class="toctext" href="collections.html">Collections and Data Structures</a></li><li><a class="toctext" href="math.html">Mathematics</a></li><li><a class="toctext" href="numbers.html">Numbers</a></li><li><a class="toctext" href="strings.html">Strings</a></li><li><a class="toctext" href="arrays.html">Arrays</a></li><li><a class="toctext" href="parallel.html">Tasks and Parallel Computing</a></li><li><a class="toctext" href="linalg.html">Linear Algebra</a></li><li><a class="toctext" href="constants.html">Constants</a></li><li><a class="toctext" href="file.html">Filesystem</a></li><li><a class="toctext" href="io-network.html">I/O and Network</a></li><li><a class="toctext" href="punctuation.html">Punctuation</a></li><li><a class="toctext" href="sort.html">Sorting and Related Functions</a></li><li><a class="toctext" href="pkg.html">Package Manager Functions</a></li><li><a class="toctext" href="dates.html">Dates and Time</a></li><li><a class="toctext" href="iterators.html">Iteration utilities</a></li><li><a class="toctext" href="test.html">Unit Testing</a></li><li><a class="toctext" href="c.html">C Interface</a></li><li class="current"><a class="toctext" href="libc.html">C Standard Library</a><ul class="internal"></ul></li><li><a class="toctext" href="libdl.html">Dynamic Linker</a></li><li><a class="toctext" href="profile.html">Profiling</a></li><li><a class="toctext" href="stacktraces.html">StackTraces</a></li><li><a class="toctext" href="simd-types.html">SIMD Support</a></li></ul></li><li><span class="toctext">Developer Documentation</span><ul><li><a class="toctext" href="../devdocs/reflection.html">Reflection and introspection</a></li><li><span class="toctext">Documentation of Julia&#39;s Internals</span><ul><li><a class="toctext" href="../devdocs/init.html">Initialization of the Julia runtime</a></li><li><a class="toctext" href="../devdocs/ast.html">Julia ASTs</a></li><li><a class="toctext" href="../devdocs/types.html">More about types</a></li><li><a class="toctext" href="../devdocs/object.html">Memory layout of Julia Objects</a></li><li><a class="toctext" href="../devdocs/eval.html">Eval of Julia code</a></li><li><a class="toctext" href="../devdocs/callconv.html">Calling Conventions</a></li><li><a class="toctext" href="../devdocs/compiler.html">High-level Overview of the Native-Code Generation Process</a></li><li><a class="toctext" href="../devdocs/functions.html">Julia Functions</a></li><li><a class="toctext" href="../devdocs/cartesian.html">Base.Cartesian</a></li><li><a class="toctext" href="../devdocs/meta.html">Talking to the compiler (the <code>:meta</code> mechanism)</a></li><li><a class="toctext" href="../devdocs/subarrays.html">SubArrays</a></li><li><a class="toctext" href="../devdocs/sysimg.html">System Image Building</a></li><li><a class="toctext" href="../devdocs/llvm.html">Working with LLVM</a></li><li><a class="toctext" href="../devdocs/stdio.html">printf() and stdio in the Julia runtime</a></li><li><a class="toctext" href="../devdocs/boundscheck.html">Bounds checking</a></li><li><a class="toctext" href="../devdocs/locks.html">Proper maintenance and care of multi-threading locks</a></li><li><a class="toctext" href="../devdocs/offset-arrays.html">Arrays with custom indices</a></li><li><a class="toctext" href="../devdocs/libgit2.html">Base.LibGit2</a></li><li><a class="toctext" href="../devdocs/require.html">Module loading</a></li></ul></li><li><span class="toctext">Developing/debugging Julia&#39;s C code</span><ul><li><a class="toctext" href="../devdocs/backtraces.html">Reporting and analyzing crashes (segfaults)</a></li><li><a class="toctext" href="../devdocs/debuggingtips.html">gdb debugging tips</a></li><li><a class="toctext" href="../devdocs/valgrind.html">Using Valgrind with Julia</a></li><li><a class="toctext" href="../devdocs/sanitizers.html">Sanitizer support</a></li></ul></li></ul></li></ul></nav><article id="docs"><header><nav><ul><li>Standard Library</li><li><a href="libc.html">C Standard Library</a></li></ul><a class="edit-page" href="https://github.com/JuliaLang/julia/blob/master/doc/src/stdlib/libc.md"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>C Standard Library</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" id="C-Standard-Library-1" href="#C-Standard-Library-1">C Standard Library</a></h1><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.malloc" href="#Base.Libc.malloc"><code>Base.Libc.malloc</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">malloc(size::Integer) -&gt; Ptr{Void}</code></pre><p>Call <code>malloc</code> from the C standard library.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L323-L327">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.calloc" href="#Base.Libc.calloc"><code>Base.Libc.calloc</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">calloc(num::Integer, size::Integer) -&gt; Ptr{Void}</code></pre><p>Call <code>calloc</code> from the C standard library.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L340-L344">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.realloc" href="#Base.Libc.realloc"><code>Base.Libc.realloc</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">realloc(addr::Ptr, size::Integer) -&gt; Ptr{Void}</code></pre><p>Call <code>realloc</code> from the C standard library.</p><p>See warning in the documentation for <code>free</code> regarding only using this on memory originally obtained from <code>malloc</code>.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L330-L337">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.free" href="#Base.Libc.free"><code>Base.Libc.free</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">free(addr::Ptr)</code></pre><p>Call <code>free</code> from the C standard library. Only use this on memory obtained from <code>malloc</code>, not on pointers retrieved from other C libraries. <code>Ptr</code> objects obtained from C libraries should be freed by the free functions defined in that library, to avoid assertion failures if multiple <code>libc</code> libraries exist on the system.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L313-L320">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.errno" href="#Base.Libc.errno"><code>Base.Libc.errno</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">errno([code])</code></pre><p>Get the value of the C library&#39;s <code>errno</code>. If an argument is specified, it is used to set the value of <code>errno</code>.</p><p>The value of <code>errno</code> is only valid immediately after a <code>ccall</code> to a C library routine that sets it. Specifically, you cannot call <code>errno</code> at the next prompt in a REPL, because lots of code is executed between prompts.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L254-L263">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.strerror" href="#Base.Libc.strerror"><code>Base.Libc.strerror</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">strerror(n=errno())</code></pre><p>Convert a system call error code to a descriptive string</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L267-L271">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.GetLastError" href="#Base.Libc.GetLastError"><code>Base.Libc.GetLastError</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">GetLastError()</code></pre><p>Call the Win32 <code>GetLastError</code> function [only available on Windows].</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L275-L279">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.FormatMessage" href="#Base.Libc.FormatMessage"><code>Base.Libc.FormatMessage</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">FormatMessage(n=GetLastError())</code></pre><p>Convert a Win32 system call error code to a descriptive string [only available on Windows].</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L282-L286">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.time-Tuple{Base.Libc.TmStruct}" href="#Base.Libc.time-Tuple{Base.Libc.TmStruct}"><code>Base.Libc.time</code></a> — <span class="docstring-category">Method</span>.</div><div><pre><code class="language-none">time(t::TmStruct)</code></pre><p>Converts a <code>TmStruct</code> struct to a number of seconds since the epoch.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L217-L221">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.strftime" href="#Base.Libc.strftime"><code>Base.Libc.strftime</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">strftime([format], time)</code></pre><p>Convert time, given as a number of seconds since the epoch or a <code>TmStruct</code>, to a formatted string using the given format. Supported formats are the same as those in the standard C library.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L163-L169">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.strptime" href="#Base.Libc.strptime"><code>Base.Libc.strptime</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">strptime([format], timestr)</code></pre><p>Parse a formatted time string into a <code>TmStruct</code> 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 <code>time</code> to convert it to seconds since the epoch, the <code>isdst</code> field should be filled in manually. Setting it to <code>-1</code> will tell the C library to use the current system settings to determine the timezone.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L182-L191">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.TmStruct" href="#Base.Libc.TmStruct"><code>Base.Libc.TmStruct</code></a> — <span class="docstring-category">Type</span>.</div><div><pre><code class="language-none">TmStruct([seconds])</code></pre><p>Convert a number of seconds since the epoch to broken-down format, with fields <code>sec</code>, <code>min</code>, <code>hour</code>, <code>mday</code>, <code>month</code>, <code>year</code>, <code>wday</code>, <code>yday</code>, and <code>isdst</code>.</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L128-L133">source</a></section><section class="docstring"><div class="docstring-header"><a class="docstring-binding" id="Base.Libc.flush_cstdio" href="#Base.Libc.flush_cstdio"><code>Base.Libc.flush_cstdio</code></a> — <span class="docstring-category">Function</span>.</div><div><pre><code class="language-none">flush_cstdio()</code></pre><p>Flushes the C <code>stdout</code> and <code>stderr</code> streams (which may have been written to by external C code).</p></div><a class="source-link" target="_blank" href="https://github.com/JuliaLang/julia/blob/d55cadc350d426a95fd967121ba77494d08364c8/base/libc.jl#L95-L99">source</a></section><footer><hr/><a class="previous" href="c.html"><span class="direction">Previous</span><span class="title">C Interface</span></a><a class="next" href="libdl.html"><span class="direction">Next</span><span class="title">Dynamic Linker</span></a></footer></article></body></html>