{{Short description|Minimalist implementation of C standard library}} {{Infobox software | name = klibc | logo = | caption = | screenshot = | developer = H. Peter Anvin | latest release version = {{wikidata|property|reference|P348}} | latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}} | operating system = Linux | genre = Runtime library | license = BSD licenses/GPLv2 }}
In computing, '''klibc''' is a minimalistic subset of the standard C library developed by H. Peter Anvin. It was developed mainly to be used during the Linux startup process, and it is part of the early user space, i.e. components used during kernel startup, but which do not run in kernel mode.<ref name=readme>{{Cite web | title=Early userspace support | url=https://www.kernel.org/doc/Documentation/early-userspace/README | archive-url=https://web.archive.org/web/20110502052928/http://www.kernel.org/doc/Documentation/early-userspace/README | archive-date=2011-05-02 | access-date=2020-09-29 | url-status=live }}</ref> These components do not have access to the standard library (usually glibc or musl) used by normal userspace programs.
The development of klibc library was part of the 2002 effort to move some Linux initialization code out of the kernel.<ref>Jonathan Corbet, (November 2002) [https://lwn.net/Articles/14776/ Initramfs arrives], LWN.net</ref><ref>{{cite web |url=http://marc.info/?l=linux-kernel&m=103622506919278&w=2 |title=initramfs merge, part 1 of N |date=2002-02-11 }}</ref><ref>{{cite web |url= http://marc.info/?l=linux-kernel&m=103626389507412&w=2 |title= Re: initramfs merge, part 1 of N |date=2002-02-11 }}</ref> According to its documentation, the klibc library is optimized for correctness and small size.<ref name=readme/> Because of its design, klibc is also technically suitable for embedded software in general on a variety of platforms, and is used even by full-featured programs such as the MirBSD Korn Shell.
During the Linux startup process, klibc is loaded from within a temporary RAM file system, initramfs. It is incorporated by default into initial RAM file systems that are created by the <code>mkinitramfs</code> script in Debian<ref>[http://packages.debian.org/source/stable/klibc Debian stable Klibc].</ref> and Ubuntu. Furthermore, it has a set of small Unix utilities that are useful in early user space: cpio, dash, fstype, mkdir, mknod, mount, nfsmount, run-init, etc. all using the ''klibc'' library.<ref>{{cite web|url=https://git.kernel.org/?p=libs/klibc/klibc.git;a=tree;f=usr;h=f3224b691ca990bed5081ea31106bed47ce23653;hb=HEAD|archive-url=https://archive.today/20120708115938/http://git.kernel.org/?p=libs/klibc/klibc.git;a=tree;f=usr;h=f3224b691ca990bed5081ea31106bed47ce23653;hb=HEAD|url-status=dead|archive-date=2012-07-08|title=libs/klibc/klibc.git / tree}}</ref> An alternate strategy is to include everything in one executable, like BusyBox, which determines the requested applet via arguments or hard links or symlinks.
==Licensing==
klibc is dual-licensed under a BSD three-clause<ref>{{Cite web|title=klibc.spec.in - klibc/klibc.git - klibc main development tree|url=https://git.kernel.org/pub/scm/libs/klibc/klibc.git/tree/klibc.spec.in?id=HEAD#n5|access-date=2020-12-06|website=git.kernel.org}}</ref> (formerly four-clause, rectified via the Historical Permission Notice and Disclaimer), as well as the GPLv2 (GPLv2 ''only'', due to Linux-kernel restrictions).
This dual license allows compatibility with both non-copyleft software, ''as well as'' GPLv3 programs '''''via''''' ''the BSD license'' (which otherwise would not be compatible). (However, if klibc includes any GPLv2 kernel code such as that in glibc, the entire application reverts to GPLv2.)
==References== {{Reflist}}
==External links== {{Portal|Free and open-source software}} * [https://lists.zytor.com/klibc/ klibc mailing list] * [https://lwn.net/Articles/191004/ initramfs and where user space truly begins] - LWN, Jonathan Corbet, July 11, 2006.
{{CProLang}} {{Lowercase title}}
Category:C standard library Category:Free computer libraries Category:Free software programmed in C Category:Interfaces of the Linux kernel Category:Linux APIs Category:Software using the BSD license Category:Software using the GNU General Public License