gets(3)

πŸ’– gets(3) πŸ’–

okay bestie, gather round, because we need to talk about gets(3) β€” that's section 3 of the Library Functions Manual, aka the C library pages. she's famous. she's iconic. she is also literally the reason your computer got hacked. let's get into it 🫢


✨ NAME ✨

gets β€” grab a string off standard input (DEPRECATED, babes. like, so deprecated.)


πŸ“š LIBRARY πŸ“š

Standard C library (libc, link with -lc). yeah she's in the main character library, unfortunately πŸ’…


🌸 SYNOPSIS 🌸

#include <stdio.h>

[[deprecated]] char *gets(char *s);

see that [[deprecated]]? that's the compiler version of me side-eyeing you. πŸ‘€


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so, first line of the description, direct from the source, no notes:

Never use this function.

periodt. πŸ’€

but if you insist on knowing what she does: gets() reads a line from stdin into the buffer that s points at, going until it hits either a terminating newline or EOF. when it finds one, it swaps that thing out for a null byte ('\0'). and here's the ✨fun✨ part β€” there is no check for buffer overrun performed. none. zero. not a vibe check in sight. (more on that in BUGS below, because oh girl there is so much more) 😭


πŸ”₯ RETURN VALUE πŸ”₯

on success, gets() returns s. on error, or when end of file happens while literally no characters have been read, it returns NULL.

However β€” and this is the part where we all sit down β€” given the total lack of buffer overrun checking, there can be no guarantees that the function will even return. like. she might just keep going. forever. into your other variables. into your stack. into your soul. πŸ™ˆ


πŸ‘‘ ATTRIBUTES πŸ‘‘

for the explanation of the terms used in this section, go check out attributes(7) (iykyk).

  • gets() β€” Thread safety: MT-Safe ✨

πŸŽ€ STANDARDS πŸŽ€

POSIX.1-2008. yes bestie, that's the whole section.


🌈 HISTORY 🌈

  • C89, POSIX.1-2001.
  • LSB deprecates gets().
  • POSIX.1-2008 marks gets() obsolescent.
  • ISO C11 removes the specification of gets() from the C language entirely. gone. deleted. no longer invited to the function party. πŸ’€
  • and since glibc 2.16, the glibc header files don't even expose the function declaration if the _ISOC11_SOURCE feature test macro is defined. she's literally hidden from you for your own protection.

πŸ’€ BUGS πŸ’€

Never use gets().

saying it again because it matters, bestie.

here's why: it is impossible to tell β€” without knowing the data in advance β€” how many characters gets() is going to read. and because gets() will just keep on storing characters past the end of the buffer, it is extremely dangerous to use. it has been used to break computer security. like, actually. real breaches. real chaos.

use fgets() instead. she would never do this to you. 🫢

for more info, see CWE-242 (aka "Use of Inherently Dangerous Function") at http://cwe.mitre.org/data/definitions/242.html.


🧚 SEE ALSO 🧚

read(2), write(2), ferror(3), fgetc(3), fgets(3), fgetwc(3), fgetws(3), fopen(3), fread(3), fseek(3), getline(3), getwchar(3), puts(3), scanf(3), ungetwc(3), unlocked_stdio(3), feature_test_macros(7)


that's the whole page, bestie ✨ this edition comes to you straight from Linux man-pages 6.20, dated 2026-02-08 β€” so like, even the manual is out here in the future still begging you not to call gets(). stay safe, use fgets(), and never let a function write past your buffer. 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms