getopt_long_only(3)

πŸ’– getopt_long_only(3) β€” like, the manual page, bestie πŸ’–

okay so this is getopt_long_only, straight outta the Library Functions Manual (yep, section 3, that's the "C library functions" section, iykyk). she parses long command-line options and she does it differently than her sister. let's get into it 🌸


✨ NAME ✨

getopt_long_only β€” parse long command-line options πŸ‘‘


πŸŽ€ LIBRARY πŸŽ€

Standard C library, aka libc, link it with -lc. she's literally built in, no third-party nonsense πŸ’…


🌈 SYNOPSIS 🌈

#define _GNU_SOURCE
#include <getopt.h>

int getopt_long_only(int argc, char *argv[],
           const char *optstring,
           const struct option *longopts, int *longindex);
⚠️ bestie look at that #define _GNU_SOURCE β€” you need it, she's a GNU girl, she does not show up without it πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

so getopt_long_only() is basically getopt_long(3)'s twin sister, but with one chaotic little twist: both - AND -- can signal a long option. that's it, that's the whole plot. main character behavior honestly ✨

and here's the fine print: if an option starts with just a single - (so, not --) and it doesn't match a long option, but it does match a short one? then she goes "oh ok, we're doing short options now" and parses it as a short option instead. flexible queen 🫢


πŸ’œ ATTRIBUTES πŸ’œ

for the deets on what these words even mean, go read attributes(7). no cap.

  • Interface: getopt_long_only()
  • Attribute: Thread safety
  • Value: MT-Unsafe race:getopt env
😭 ok so translate that: she is MT-Unsafe, there's literally a race on getopt, and she touches env. multiple threads + this function = messy. don't do it. not her fault, that's just the vibe πŸ’€

⭐ STANDARDS ⭐

GNU. (of course. she's got that GNU energy, that's literally the whole point 🧚)


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie, you ate it πŸ’…βœ¨

this was brought to you by Linux man-pages 6.20, dated 2025-12-07 β€” mwah, love you, now go write some --long-options πŸ“πŸ’–πŸŽ€

πŸ“¦ 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