Generated by GPT-5-mini| stdio.h | |
|---|---|
| Name | stdio.h |
| Type | C header |
| Introduced | 1972 |
| Standard | ANSI C, ISO/IEC 9899 |
| Influences | Ken Thompson, Dennis Ritchie, Bell Labs |
| File extensions | .c, .h |
stdio.h
stdio.h is a C language header that declares input and output routines used ubiquitously in Unix, Plan 9, Microsoft Windows, IBM, and embedded systems. Originating from the work of Ken Thompson and Dennis Ritchie at Bell Labs and standardized by ANSI and ISO/IEC 9899 committees, stdio.h provides a stable interface for file handling, formatted I/O, buffering, and error reporting across implementations by vendors such as GNU Project, Microsoft Corporation, and Apple Inc.. Its API has influenced libraries in POSIX, BSD, Linux, and proprietary systems while interacting with runtime environments like the C runtime library and toolchains from GCC, Clang, and Microsoft Visual C++.
The header defines data types, macros, and functions for stream-based I/O used by programs compiled with toolchains from GCC, Clang, MSVC, Intel, and Embarcadero Technologies. It interoperates with operating systems such as Unix System V, FreeBSD, NetBSD, OpenBSD, Linux Kernel, and Windows NT through file descriptors and runtime support provided by libraries like glibc and musl. stdio.h abstracts devices and files, enabling interaction with terminals like those on VT100 and xterm as well as with filesystems including EXT4, NTFS, and FAT32. Its design balances portability across architectures like x86_64, ARM, MIPS, and PowerPC while reflecting constraints from embedded targets such as ARM Cortex-M and AVR.
Key types and macros declared include file stream handles and constants standardized by ANSI C and ISO/IEC 9899. The central opaque type represents streams and is used by implementations in glibc, musl, and Newlib. Macros for end-of-file and error signaling, alongside buffer size hints, are standardized, and symbolic names for file positions are used in conjunction with types standardized by POSIX and influenced by earlier work at Bell Labs. Implementations may expose additional macros for feature detection used by build systems like CMake and Autoconf when targeting platforms such as Windows CE or QNX.
The header declares functions for opening, closing, reading, writing, and repositioning streams that interact with system calls provided by kernels including Linux Kernel and Windows NT Kernel. Functions for creating and removing files, controlling temporary streams, and associating streams with file descriptors are commonly implemented in standard libraries like glibc, msvcrt, and Bionic. The API enables interoperability with high-level facilities in POSIX (open, read, write) and runtime features used by toolchains such as LLVM and GCC-based compilers targeting toolchains from GNU Project or Microsoft Corporation.
Formatted I/O functions declared provide printf-family and scanf-family interfaces, which support locale-aware conversions aligned with standards discussed in committees such as ISO/IEC JTC1/SC22. Implementations in glibc and musl include extensions for secure variants introduced by vendors like Microsoft Corporation and proposals from CERT. Unformatted I/O functions provide block-oriented operations used by database engines such as SQLite and server software like Apache HTTP Server and Nginx when bridging C-level buffering with OS-level I/O on filesystems like EXT4 and XFS.
Error reporting mechanisms declared in the header integrate with errno semantics defined by POSIX and error-reporting conventions on Windows NT. Buffering control functions allow programs to set line-buffered, fully buffered, or unbuffered modes, crucial for interactive programs running in terminal emulators like xterm or for daemons on hosts such as FreeBSD servers. Implementations in glibc, musl, and embedded libraries like Newlib and uClibc may differ in buffer strategies and thread-safety guarantees documented by standards bodies like IEEE and committees involved in ANSI standardization.
Implementations of stdio.h across ecosystems — including glibc, musl, Newlib, msvcrt, and Bionic — aim to conform to ANSI C and ISO/IEC 9899 while providing extensions for platform-specific needs driven by vendors such as Microsoft Corporation, Apple Inc., and organizations like The Open Group. Conformance testing is performed using test suites from projects like POSIX Test Suite and community efforts in LLVM and GNU Project ecosystems. Compatibility concerns arise when interfacing with language bindings for Python, Perl, Ruby, and Java native interfaces, or when adapting for constrained environments supported by RTOS vendors like FreeRTOS and VxWorks.
Category:C (programming language) headers