C, Ocean Edition I

7.2 Standard Headers

Clause
7.2
ISO C99 mapping
7.2 through 7.31
Status
Normative

7.2.0 How to Read This Clause

Each subclause names a header, lists what it declares and defines, and states the behavior that differs from ISO C99. Where a subclause does not state a difference, the ISO C99 specification of that facility applies, as clause 2.3 provides, adjusted by the language rules of clause 6 and by the library conventions of clause 7.1.7.

Every header in this clause may be imported with #import or included with #include, and contributes the same declarations and macros either way. See clause 7.1.2. Every entity and macro described here is a member of the global namespace under clause 6.9.6.2.

Headers are numbered by subject rather than alphabetically. The alphabetical index is here:

Header Clause Header Clause
<assert.h> 7.2.1 <stdarg.h> 7.2.13
<complex.h> 7.2.2 <signal.h> 7.2.14
<ctype.h> 7.2.3 <stdbool.h> 7.2.15
<errno.h> 7.2.4 <stddef.h> 7.2.16
<float.h> 7.2.5 <stdio.h> 7.2.17
<math.h> 7.2.6 <stdlib.h> 7.2.18
<fenv.h> 7.2.7 <string.h> 7.2.19
<limits.h> 7.2.8 <stdint.h> 7.2.20
<iso646.h> 7.2.9 <stdalign.h> 7.2.21
<locale.h> 7.2.10 <tgmath.h> 7.2.22
<inttypes.h> 7.2.11 <time.h> 7.2.23
<setjmp.h> 7.2.12 <wchar.h> 7.2.24
<wctype.h> 7.2.25

7.2.1 Diagnostics <assert.h>

Defines the macro assert and refers to NDEBUG.

void assert(scalar expression);

If NDEBUG is defined at the point <assert.h> is included, assert expands to an expression with no effect. Otherwise, assert evaluates its argument, and if the result compares equal to zero, writes a diagnostic naming the expression text, the source file, the line number, and the enclosing function, and then causes a defined trap.

The source file name it reports is the one __FILE__ gives, recorded under Annex K clause K.6.3. An assertion message therefore does not carry the absolute path of the machine that built the program.

Difference: ISO C99 specifies a call to abort. Ocean Edition I specifies a defined trap, which is the same observable outcome expressed in this edition's vocabulary. See annex-d-defined-traps-and-unsafe-operations.md.

The argument shall have scalar type. An implementation shall diagnose an assert whose argument is an assignment expression, since assert(x = 0) is nearly always a typing error.

ISO C99 mapping: 7.2.


7.2.2 Complex Arithmetic <complex.h>

Complex arithmetic is an optional extension of this edition. See clause 6.2.5.2.

Where an implementation provides it, it shall define __OCEAN_COMPLEX__, shall provide <complex.h> with the contents ISO C99 specifies, and shall follow ISO C99 for the semantics of the complex types and functions.

Where an implementation does not provide it, <complex.h> shall not be present, and #if __has_include(<complex.h>) reports its absence.

ISO C99 mapping: 7.3, made optional.


7.2.3 Character Handling <ctype.h>

Declares the classification functions isalnum, isalpha, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit, and the conversion functions tolower and toupper.

Argument range.

Each function takes an int whose value shall be representable as an unsigned char or shall equal EOF. Because plain char is never negative in this edition, passing a char value directly is always valid:

if (isspace(text[i]))
{
	...
}

Difference: in ISO C99 a negative plain char passed to these functions is undefined, which is a classic defect on implementations where char is signed. Clause 6.2.6.3 removes the possibility.

An argument outside the permitted range causes a defined trap.

ISO C99 mapping: 7.4.


7.2.4 Errors <errno.h>

Defines errno, EDOM, ERANGE, and EILSEQ, and any additional macros the implementation documents. See clause 7.1.8.

ISO C99 mapping: 7.5.


7.2.5 Characteristics of Floating Types <float.h>

Defines the macros describing the target's floating-point characteristics, including FLT_RADIX, FLT_EVAL_METHOD, FLT_ROUNDS, and for each of FLT, DBL, and LDBL the macros _MANT_DIG, _DIG, _MIN_EXP, _MIN_10_EXP, _MAX_EXP, _MAX_10_EXP, _MAX, _MIN, and _EPSILON.

FLT_EVAL_METHOD shall be 0, 1, or 2, and shall describe what the implementation actually does. An implementation shall not report 0 while evaluating in a wider format.

ISO C99 mapping: 7.7.


7.2.6 Mathematics <math.h>

Declares the floating-point mathematical functions and defines the classification macros fpclassify, isfinite, isinf, isnan, isnormal, signbit, and the comparison macros isgreater, isgreaterequal, isless, islessequal, islessgreater, isunordered.

Defines HUGE_VAL, HUGE_VALF, HUGE_VALL, INFINITY, NAN, FP_CONTRACT, and the math_errhandling macro.

Error reporting.

A function shall report a domain error by returning a NaN and setting errno to EDOM, and shall report a range error by returning a suitably signed HUGE_VAL and setting errno to ERANGE. Where the implementation conforms to Annex F, it shall also raise the corresponding floating-point exception.

math_errhandling shall have the value MATH_ERRNO | MATH_ERREXCEPT on an implementation conforming to Annex F, and MATH_ERRNO otherwise. An implementation shall not report neither.

Difference: ISO C99 leaves it partly to the implementation whether errno is set at all. A caller that cannot tell whether an error was reported cannot handle errors, so this edition requires errno.

Contraction.

#pragma STDC FP_CONTRACT defaults to OFF. See clause 5.1.2.3 and clause 6.10.6.

ISO C99 mapping: 7.12.


7.2.7 Floating-Point Environment <fenv.h>

Declares fenv_t, fexcept_t, femode_t where provided, the exception macros FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW, FE_ALL_EXCEPT, the rounding direction macros FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD, and the functions feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag, fetestexcept, fegetround, fesetround, fegetenv, feholdexcept, fesetenv, feupdateenv.

An implementation that does not support a rounding direction shall not define its macro.

A program that accesses the floating-point environment shall enable #pragma STDC FENV_ACCESS. With the pragma off, an implementation may assume the default environment.

The rounding mode selected through fesetround applies to execution-time arithmetic. Translation-time constant folding uses the default rounding mode, and clause 6.6.3 requires the implementation to document any resulting difference.

ISO C99 mapping: 7.6.


7.2.8 Sizes of Integer Types <limits.h>

Defines CHAR_BIT, SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, CHAR_MIN, CHAR_MAX, MB_LEN_MAX, SHRT_MIN, SHRT_MAX, USHRT_MAX, INT_MIN, INT_MAX, UINT_MAX, LONG_MIN, LONG_MAX, ULONG_MAX, LLONG_MIN, LLONG_MAX, and ULLONG_MAX.

Fixed values in every conforming implementation:

CHAR_BIT   8
CHAR_MIN   0
CHAR_MAX   255

CHAR_MIN is zero because plain char is never negative. See clause 6.2.6.3.

Every signed limit macro shall have the exact two's-complement value for its width, so INT_MIN is -2147483648 on a 32-bit int rather than -2147483647.

ISO C99 mapping: 7.10.


7.2.9 Alternative Spellings <iso646.h>

This header is provided for source compatibility only. It defines and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, and xor_eq as macros for the corresponding operators.

Ocean Edition I source should use the operators. The header exists because existing C source includes it, and removing it would break that source for no benefit. See clause 5.2.1.1.

ISO C99 mapping: 7.9.


7.2.10 Localization <locale.h>

Declares struct lconv, defines LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, and declares setlocale and localeconv.

The initial locale is "C".

Difference: ISO C99 makes a large amount of library behavior locale-specific without cataloguing it. In Ocean Edition I, a facility whose behavior changes with the locale shall say so in its clause, and the implementation shall document the behavior of every locale it provides. Locale-specific behavior is a form of implementation-defined behavior and is listed in annex-c-implementation-defined-behavior.md clause C.8.

ISO C99 mapping: 7.11.


7.2.11 Format Conversion of Integer Types <inttypes.h>

Includes <stdint.h> and defines the printing and scanning format macros PRIdN, PRIiN, PRIoN, PRIuN, PRIxN, PRIXN and their SCN counterparts, for each provided exact-width, least-width, fast, pointer, and maximum-width type. Declares imaxabs, imaxdiv, strtoimax, strtoumax, wcstoimax, wcstoumax, and defines imaxdiv_t.

imaxdiv and every division helper follow the truncation rule of clause 6.5.5, and trap on a zero divisor rather than returning an unspecified result.

ISO C99 mapping: 7.8.


7.2.12 Nonlocal Jumps <setjmp.h>

Defines jmp_buf and declares setjmp and longjmp.

setjmp saves the calling environment and returns zero. longjmp restores it, and execution continues as though setjmp had returned the value given to longjmp, or 1 if that value was zero.

Constraints.

A setjmp invocation shall appear only as the entire controlling expression of a selection or iteration statement, as the entire expression of an expression statement, as one operand of a comparison whose other operand is an integer constant expression, or as the operand of ! in one of those positions.

longjmp shall not be called after the function that called the corresponding setjmp has returned. Doing so is unsafe memory behavior.

Object values after a jump.

An object with automatic storage duration, local to the function containing the setjmp, that was modified between the setjmp and the longjmp, has its last-stored value after the jump. It is not indeterminate.

Difference: ISO C99 makes such objects indeterminate unless they are volatile. Ocean Edition I has no indeterminate values, under clause 6.7.9.2, so the rule becomes a requirement on the implementation to spill what it must. A program that wants a guarantee of low cost may still declare such objects volatile.

ISO C99 mapping: 7.13.


7.2.13 Variable Arguments <stdarg.h>

Defines va_list and the macros va_start, va_arg, va_copy, and va_end.

int sum_all(int count, ...)
{
	va_list args;
	va_start(args, count);

	int total = 0;

	for (int i = 0; i < count; i++)
	{
		total += va_arg(args, int);
	}

	va_end(args);

	return total;
}

Arguments in the variadic tail undergo the default argument promotions of clause 6.3.1.8, so va_arg shall not request char, short, bool, or float. Requesting a type that does not match the promoted argument type causes a defined trap where the implementation can detect it, and is unsafe memory behavior otherwise.

Every va_start and va_copy shall be matched by a va_end in the same function.

ISO C99 mapping: 7.15.


7.2.14 Signal Handling <signal.h>

Defines sig_atomic_t, the macros SIG_DFL, SIG_ERR, SIG_IGN, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, and declares signal and raise.

What a handler may do.

A signal handler may:

A handler shall not call any other library function unless the implementation documents that function as handler-safe. An implementation shall publish the list of handler-safe functions it provides.

Difference: ISO C99 states the restriction and then leaves the safe set almost empty without saying what implementations actually provide. Requiring a published list turns folklore into documentation.

Returning from a handler for a signal raised by a defined trap does not resume the trapping operation. The behavior after such a return is implementation-defined and shall be documented.

ISO C99 mapping: 7.14.


7.2.15 Boolean Type <stdbool.h>

bool, true, and false are keywords of the language, under clause 6.4.1.3. This header is not needed to use them, and new code should not include it.

The header is provided for source compatibility, and defines exactly one macro:

#define __bool_true_false_are_defined 1

It shall not define bool, true, or false, because they are keywords and a macro definition of a keyword is a constraint violation under clause 6.10.3.3.

Existing C source that includes <stdbool.h> and then writes bool, true, and false compiles unchanged, which is the reason the header still exists.

Difference: ISO C99 defines all four macros here. Ocean Edition I promotes three of them to the language and leaves the fourth so that a conditional test on __bool_true_false_are_defined still works.

ISO C99 mapping: 7.16, mostly promoted to clause 6.4.1.3. Adopted from ISO/IEC 9899:2024.


7.2.16 Common Definitions <stddef.h>

Defines ptrdiff_t, size_t, wchar_t, null_t, nullptr_t, max_align_t, and offsetof.

This header does not define NULL. null and NULL are keywords under clause 6.4.1.2, so a program needs no header to write a null pointer, and clause 6.10.3.3 makes a macro definition of either a constraint violation.

int *pointer = null;

if (pointer == null)
{
	...
}

null_t is a typedef for the type of the null constants, described in clause 6.2.5.2. The name is provided here because a type needs a spelling for use in a declaration, while the constants themselves belong to the language.

nullptr_t is an alias for null_t, provided so that source written against ISO/IEC 9899:2024 declares the same type without modification.

Difference: ISO C99 defines NULL here as a macro expanding to 0 or to (void *)0. Clause 6.4.4.6 states what that cost and why the constant was promoted.

offsetof(type, member) yields the offset in bytes of the named member from the beginning of the structure, as a size_t constant expression. It shall be usable with any member of any complete structure type, including a member of array type and a nested member reached through the . operator.

max_align_t is an object type whose alignment is at least as strict as that of every scalar type the implementation supports.

ISO C99 mapping: 7.17, with max_align_t added.


7.2.17 Input and Output <stdio.h>

Declares FILE, fpos_t, size_t, and the macros _IOFBF, _IOLBF, _IONBF, BUFSIZ, EOF, FOPEN_MAX, FILENAME_MAX, L_tmpnam, SEEK_CUR, SEEK_END, SEEK_SET, TMP_MAX, stderr, stdin, stdout.

Declares the file operations remove, rename, tmpfile, tmpnam, fclose, fflush, fopen, freopen, setbuf, setvbuf; the formatted input and output functions fprintf, fscanf, printf, scanf, snprintf, sprintf, sscanf, vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, vsscanf; the character input and output functions fgetc, fgets, fputc, fputs, getc, getchar, putc, putchar, puts, ungetc; the direct input and output functions fread, fwrite; the file positioning functions fgetpos, fseek, fsetpos, ftell, rewind; and the error handling functions clearerr, feof, ferror, perror.

Differences from ISO C99.

gets is not provided. It cannot be called safely, since it has no way to know the size of its destination. Programs use fgets.

Format string checking. An implementation shall diagnose a mismatch between a format string and its arguments whenever the format string is a string literal at the call site. This is a required diagnostic rather than a recommended one, because the information is present and the failure mode is memory corruption.

Conversion specifier coverage. A conversion specifier that ISO C99 leaves undefined, such as an unrecognized specifier character, is a constraint violation when the format is a literal, and produces a defined trap at execution time when it is not.

snprintf truncation. snprintf always null-terminates when the size is greater than zero, and returns the number of characters that would have been written. A return value greater than or equal to the size means the output was truncated, and that is a defined result rather than an error.

Streams and text. The distinction between text streams and binary streams is retained, and an implementation shall document what its text mode changes. On an implementation where the two modes are identical, that fact shall be documented rather than implied.

Buffering at termination. Every open stream with buffered output is flushed at normal program termination. A stream is not flushed by a defined trap unless the implementation documents that it is.

ISO C99 mapping: 7.19.


7.2.18 General Utilities <stdlib.h>

Declares size_t, wchar_t, div_t, ldiv_t, lldiv_t, and defines EXIT_FAILURE, EXIT_SUCCESS, RAND_MAX, MB_CUR_MAX. It does not define NULL, which is a keyword under clause 6.4.1.2.

Declares the numeric conversion functions atof, atoi, atol, atoll, strtod, strtof, strtold, strtol, strtoll, strtoul, strtoull; the pseudo-random sequence functions rand, srand; the memory management functions calloc, free, malloc, realloc; the environment functions abort, atexit, exit, _Exit, getenv, system; the searching and sorting utilities bsearch, qsort; the integer arithmetic functions abs, labs, llabs, div, ldiv, lldiv; and the multibyte conversion functions mblen, mbtowc, wctomb, mbstowcs, wcstombs.

Differences from ISO C99.

Pseudo-random sequences.

rand produces the same sequence for a given seed, and the initial state is that of srand(1). An implementation shall document its generator, so that a program depending on the sequence can tell whether changing implementation will change its output.

This is an execution-time property. Annex K constrains translation, and says nothing about what a program computes when it runs.

Allocation.

malloc returns a pointer to allocated storage suitably aligned for any object whose size does not exceed the requested size, or a null pointer on failure.

malloc(0) returns a null pointer and sets errno to ERANGE. This is a definite choice, made because the ISO C99 alternative of returning either a null pointer or a unique unusable pointer forces every caller to handle both.

The contents of storage returned by malloc are not specified by this clause and are not required to be zero. Storing a valid representation into the storage establishes an object under clause 6.2.4.3. Reading the storage before storing anything reads bytes whose values are unspecified, and does not trap, because allocated storage is raw storage rather than an object.

calloc returns storage whose bytes are all zero.

realloc preserves the contents up to the lesser of the old and new sizes, returns a null pointer on failure, and leaves the original storage valid and unchanged when it fails.

realloc(p, 0) frees p and returns a null pointer without setting errno, since the operation succeeded. A caller distinguishes this from failure by the requested size rather than by the returned pointer, and a caller that may request zero should test the size before testing the result.

realloc(null, n) is equivalent to malloc(n).

free accepts a null pointer and does nothing. free of a pointer not obtained from an allocation function, or of a pointer already freed, is unsafe memory behavior, and an implementation providing the checked profile shall convert it into a defined trap.

Integer conversion failure.

atoi, atol, and atoll are provided for compatibility and have no way to report failure. Programs should use the strto family. An implementation should diagnose a call to the ato family under an optional warning.

The strto family reports failure by setting the end pointer equal to the start pointer, and reports overflow by returning the appropriate limit macro and setting errno to ERANGE.

Division helpers.

div, ldiv, lldiv, and their counterparts truncate toward zero, consistent with clause 6.5.5, and trap on a zero divisor.

abs, labs, and llabs applied to the minimum representable value of their argument type cause a defined trap, because the result has no representation. ISO C99 leaves this undefined.

Sorting and searching.

qsort and bsearch take a comparison function pointer, written explicitly:

qsort(&items[0], count, sizeof(items[0]), &compare_item);

A comparison function shall induce a total order on the elements presented, meaning that for the values a, b, and c actually passed to it:

A comparison function that violates any of these causes unsafe memory behavior in a naive implementation, because a sort may run past the end of the array while looking for an element that its comparisons imply must exist. An implementation should detect the violation and convert it into a defined trap, and shall do so under the checked profile of clause 4.6.4.

qsort is not required to be stable. An implementation should also provide a documented stable variant.

Termination.

exit flushes and closes open streams, removes temporary files, and calls functions registered with atexit in reverse order of registration. _Exit does none of that. abort causes a defined trap.

At least 32 functions can be registered with atexit.

ISO C99 mapping: 7.20.


7.2.19 String Handling <string.h>

Declares size_t and the copying functions memcpy, memmove, strcpy, strncpy, strncpy_padded; the concatenation functions strcat, strncat; the comparison functions memcmp, strcmp, strcoll, strncmp, strxfrm; the search functions memchr, strchr, strcspn, strpbrk, strrchr, strspn, strstr, strtok, strtok_r; and the miscellaneous functions memset, strerror, strerror_r, strlen.

char *strncpy_padded(char *dst, const char *src, size_t n);
char *strtok_r(char *s, const char *delimiters, char **state);
int strerror_r(int code, char *buffer, size_t size);

strncpy_padded has the behavior ISO C99 gives strncpy: it copies at most n characters, pads the remainder of the destination with null characters, and does not terminate when the source is at least n characters long.

strtok_r behaves as strtok with the hidden state held in the object state designates.

strerror_r writes the message for code into the buffer, always terminating when size is greater than zero, and returns zero on success or a nonzero value when the buffer was too small.

Differences from ISO C99.

Overlap is safe. memcpy provides the overlap-safe behavior traditionally associated with memmove, as clause 7.1.7.3 requires. memmove remains available and behaves identically. The copying and concatenation functions in this header are all overlap-safe.

For a copying function, the result is the one obtained as though every source byte were read before any destination byte were written.

For a concatenation function the operation has two steps, and the rule shall be stated for both, because the destination length is discovered rather than given:

  1. the length of the destination string is determined from its contents as they stand on entry,
  2. the source bytes, as they stand on entry, are written starting at that offset, followed by a terminating null character.

Both steps use the state on entry. Therefore strcat(&s[0], &s[0]) doubles the string rather than looping, and a source that overlaps the region about to be written produces the result the two steps describe.

char s[16] = "ab";

strcat(&s[0], &s[0]);      /* "abab" */

An implementation shall not require that source and destination be disjoint, and shall not produce a result that depends on the direction in which it happens to copy.

Note. The requirement has a cost when the regions overlap and the implementation cannot determine that they do not. An implementation may copy through a temporary in that case. The overlap-safe result is defined for every argument pair, and it is the implementation's problem to produce it.

Zero sizes. Every function taking a size accepts zero and does nothing, including when a pointer argument is null. memcpy(null, null, 0) is defined and has no effect. ISO C99 makes it undefined, which serves nobody.

strncpy always terminates. strncpy(dst, src, n) copies at most n - 1 characters and always writes a terminating null character when n is greater than zero. It no longer pads the remainder of the destination with null characters, and it no longer produces an unterminated result.

Difference: this changes the ISO C99 behavior of strncpy, which is the only case in the library where this edition changes a result rather than defining an undefined one. It is justified because the traditional behavior serves a fixed-width record format that almost no caller wants, and produces unterminated strings that almost every caller then mishandles. An implementation shall provide strncpy_padded with the traditional behavior for source that needs it, and shall diagnose the difference where it can determine that traditional behavior was expected.

strtok state. strtok keeps state between calls. That state is per-thread in an implementation providing threads. An implementation shall also provide strtok_r taking an explicit state pointer, and programs should use it.

strerror result. strerror returns a pointer to a string the program shall not modify and shall not free. A later call may overwrite it. Programs should prefer strerror_r, which writes into storage the caller supplies.

Element pointers at call sites. Because arrays do not convert, calls pass element pointers:

char buffer[64];

memset(&buffer[0], 0, sizeof(buffer));
strcpy(&buffer[0], "ready");

ISO C99 mapping: 7.21.


7.2.20 Integer Types <stdint.h>

Defines the exact-width types int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t; the minimum-width types int_leastN_t and uint_leastN_t; the fastest minimum-width types int_fastN_t and uint_fastN_t; the pointer-holding types intptr_t and uintptr_t; the greatest-width types intmax_t and uintmax_t; the corresponding limit macros; and the constant macros INTN_C, UINTN_C, INTMAX_C, UINTMAX_C.

Requirement. A hosted implementation shall provide the exact-width types for every width among 8, 16, 32, and 64 that the target supports, and shall provide intptr_t and uintptr_t. Because integers have no padding bits and use two's complement, the exact-width types exist whenever the target has a type of that width.

uintptr_t and intptr_t satisfy the round-trip guarantee of clause 6.3.2.5.

Portable programs use these types wherever width matters. This is already good C practice, and it is the recommended alternative to assuming anything about int or long. See syntax.md section 33.

ISO C99 mapping: 7.18.


7.2.21 Alignment <stdalign.h>

An implementation shall provide a way to query the alignment requirement of a type, and shall expose it through this header.

Defines alignof(type), yielding the alignment requirement of the named type as a size_t constant expression, and alignas(expression) where the implementation provides an alignment specifier.

Defines __alignas_is_defined and __alignof_is_defined as 1 where the corresponding facility is provided.

Note. Alignment is a real target property that a systems program needs to see, so a query is required. An alignment specifier is a new declaration form, so it is a recommended extension under clause 6.11.5 rather than a core feature.

ISO C99 mapping: new.


7.2.22 Type-Generic Mathematics <tgmath.h>

Includes <math.h>, and <complex.h> where complex arithmetic is provided, and defines type-generic macros that select among the float, double, and long double variants of the mathematical functions according to the argument types.

Where complex arithmetic is not provided, the type-generic macros select among the real variants only.

ISO C99 mapping: 7.22.


7.2.23 Date and Time <time.h>

Defines clock_t, time_t, struct tm, size_t, and CLOCKS_PER_SEC, and declares clock, difftime, mktime, time, asctime, ctime, gmtime, localtime, gmtime_r, localtime_r, strftime.

struct tm *gmtime_r(const time_t *timer, struct tm *result);
struct tm *localtime_r(const time_t *timer, struct tm *result);

The reentrant forms write into the caller's struct tm and return a pointer to it, or a null pointer on failure.

Differences from ISO C99.

time_t shall be a signed integer type of at least 64 bits, counting seconds. An implementation shall not provide a time_t that overflows in 2038.

gmtime and localtime return a pointer to a static object that a later call may overwrite. That object is per-thread in an implementation providing threads. Programs should prefer gmtime_r and localtime_r, which write into storage the caller supplies.

asctime and ctime produce a fixed-format string. Their behavior for a year outside the range they can format is a defined trap rather than undefined behavior. Programs should use strftime.

Note. These functions read the clock at execution time and are unaffected by Annex K, which constrains translation rather than execution. A program that wants the time its build declared reads __DATE__ and __TIME__ instead, under Annex K clause K.5.2.

ISO C99 mapping: 7.23.


7.2.24 Extended Multibyte and Wide Character Utilities <wchar.h>

Defines wchar_t, wint_t, mbstate_t, struct tm, size_t, WCHAR_MIN, WCHAR_MAX, and WEOF, and declares the wide-character counterparts of the formatted input and output functions, of the string handling functions, and of the multibyte conversion functions.

Encoding.

The default execution character set is UTF-8, matching the source character set of clause 5.2.1. Where the execution character set is UTF-8, the multibyte encoding is stateless, and mbstate_t objects track no shift state.

wchar_t shall be able to represent every ISO/IEC 10646 code point the implementation supports, and an implementation should make it 32 bits wide. An implementation whose wchar_t cannot represent every supported code point shall document the limitation and shall not define __STDC_ISO_10646__.

The wide-character string functions follow clause 7.1.7.3 for overlap, and wcsncpy follows the termination rule stated for strncpy in clause 7.2.19.

ISO C99 mapping: 7.24.


7.2.25 Wide Character Classification and Mapping <wctype.h>

Defines wint_t, wctrans_t, wctype_t, WEOF, and declares the wide-character classification functions, the extensible classification functions wctype and iswctype, and the extensible mapping functions wctrans and towctrans.

ISO C99 mapping: 7.25.


7.2.26 Future Library Directions

The following are recorded so that programs avoid them and so that implementations do not treat them as stable.

Reserved for future headers. The names <threads.h>, <stdatomic.h>, <stdckdint.h>, and <uchar.h> are reserved. An implementation may provide any of them as a documented extension, following the corresponding ISO C specification.

Deprecated interfaces.

Expected additions. A future edition is expected to add checked size-taking variants as core interfaces rather than as an implementation option, and to add a documented stable sort.

ISO C99 mapping: 7.26, and the future directions subclauses of each header.