toupper(3)
โจ toupper(3) โจ the get-your-letters-swole (or smol) manual
okay bestie, so this is a page from the Library Functions Manual, and it's all about toupper(3) โ her whole friend group is here: toupper, tolower, toupper_l, tolower_l. ๐
Let's get into it.
๐ธ NAME ๐ธ
toupper, tolower, toupper_l, tolower_l โ convert uppercase or lowercase
Bestie. The name literally tells you the whole vibe: these functions flip your letters between big and little. That's the job. That's the era. ๐
๐ LIBRARY ๐
Standard C library (libc, -lc)
โจ SYNOPSIS โจ
#include <ctype.h>
int toupper(int c);
int tolower(int c);
int toupper_l(int c, locale_t locale);
int tolower_l(int c, locale_t locale);
๐ฆ Feature Test Macro Requirements for glibc ๐ฆ
(pssst โ see feature_test_macros(7) if you wanna know the lore)
toupper_l(), tolower_l():
- Since glibc 2.10:
_XOPEN_SOURCE >= 700
- Before glibc 2.10:
_GNU_SOURCE
๐ DESCRIPTION ๐
So like, the whole point: these functions convert lowercase letters to uppercase, and vice versa. Both directions, one page, no cap. ๐ฅ
If c is a lowercase letter, toupper() returns its uppercase equivalent โ if an uppercase representation exists in the current locale. Otherwise it just hands you back c, unchanged, no drama. And toupper_l()? Same task, but it uses the locale referred to by the locale handle locale. So it's the "I brought my own locale" version. ๐
If c is an uppercase letter, tolower() returns its lowercase equivalent โ if a lowercase representation exists in the current locale. Otherwise, again, it returns c. And tolower_l() does the same task but uses the locale referred to by the locale handle locale.
๐จ WARNING, and I mean it: ifcis neither an unsigned char value norEOF, the behavior of these functions is undefined. Not "a little weird". Undefined. Do not test her.
๐จ And another one: the behavior oftoupper_l()andtolower_l()is undefined iflocaleis the special locale objectLC_GLOBAL_LOCALE(seeduplocale(3)) or is not a valid locale object handle. So pls, keep your locale handles valid, I'm begging. ๐
โญ RETURN VALUE โญ
The value returned is that of the converted letter, or c if the conversion was not possible. Simple. She either glows you up or leaves you exactly as you were. Iconic behavior honestly. ๐
๐ ATTRIBUTES ๐
For the full explanation of the terms used in this section, go peek at attributes(7). Here's the tea:
- Interface:
toupper(),tolower(),toupper_l(),tolower_l()โ Attribute: Thread safety โ Value:MT-Safe
That's it bestie, whole squad is MT-Safe, so they can hang out with all your threads at once. ๐ซถ
๐ง STANDARDS ๐ง
toupper()tolower()- C11, POSIX.1-2008.
toupper_l()tolower_l()- POSIX.1-2008.
๐ HISTORY ๐
toupper()tolower()- C89, 4.3BSD, POSIX.1-2001.
toupper_l()tolower_l()- POSIX.1-2008.
๐ธ NOTES ๐ธ
The standards require that the argument c for these functions is either EOF or a value that is representable in the type unsigned char. So if your argument c is of type char, it must be cast to unsigned char, like this:
char c;
...
res = toupper((unsigned char) c);
Why though? Because char may be the equivalent of signed char, in which case a byte where the top bit is set would be sign extended when converting to int, yielding a value that is outside the range of unsigned char. So yeah โ that cast is not optional, it's the moment. โจ
The details of what constitutes an uppercase or lowercase letter depend on the locale. For example, the default "C" locale does not know about umlauts, so no conversion is done for them. She simply doesn't know them. ๐ญ
And in some non-English locales, there are lowercase letters with no corresponding uppercase equivalent โ the German sharp s is one example. Some letters truly live alone. Respect it. ๐
๐ฆ SEE ALSO ๐ฆ
isalpha(3), newlocale(3), setlocale(3), towlower(3), towupper(3), uselocale(3), locale(7)
okay that's the whole page, you ate it, you understood it, I'm so proud of you ๐
this has been brought to you by Linux man-pages 6.20, dated 2026-02-08, and yes, toupper(3) said it herself. mwah. ๐
โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- Copyright 2014, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms