#include <getopt.h>

getopt.h

$NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $
includes: sys/cdefs.h, _bounds.h, unistd.h
5 macros · 5 variables · 3 functions · 1 struct

macrono_argument

GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension. getopt() is declared here too for GNU programs.
#define no_argument 0

macrorequired_argument

#define required_argument 1

macrooptional_argument

#define optional_argument 2

structoption

size 32, align 8
const char *namename of long option
inthas_argone of no_argument, required_argument, and optional_argument: whether option takes an argument
int *flagif not NULL, set *flag to val when option found
intvalif flag not NULL, value to set *flag to; else return value

functiongetopt_long

int getopt_long(
	int __argc,
	char *_LIBC_CSTR const *_LIBC_COUNT(__argc),
	const char *,
	const struct option *,
	int *
)
man page · December 24, 2022
getopt_long(3) — get long options from command line argument list

functiongetopt_long_only

int getopt_long_only(
	int __argc,
	char * const *_LIBC_COUNT(__argc),
	const char *,
	const struct option *,
	int *
)
man page · December 24, 2022
getopt_long_only(3) — get long options from command line argument list

macro_GETOPT

#define _GETOPT 

functiongetopt

__DARWIN_ALIAS(getopt)
int getopt(int __argc, char *_LIBC_CSTR const [_LIBC_COUNT(__argc)], const char *)
man page · June 5, 2014
getopt(3) — get option character from command line argument list

variableoptarg

extern char *_LIBC_CSTR optarg
getopt(3) external variables

variableoptind

extern int optind

variableopterr

extern int optind, opterr

variableoptopt

extern int optind, opterr, optopt

macro_OPTRESET

#define _OPTRESET 

variableoptreset

extern int optreset
getopt(3) external variable