summaryrefslogtreecommitdiffstats
path: root/include/getopt.h
blob: 4f48ba8fd9b2a4c33e2fa75b3f680fe3c7b548de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * getopt.h - a simple getopt(3) implementation.
 *
 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __GETOPT_H
#define __GETOPT_H

extern int opterr;
extern int optind;
extern int optopt;
extern char *optarg;

/*
 * Simple getopt(3) implementation.
 * This version of getopt does not take long options but should
 * otherwise behave like one expects.
 *
 * - It takes ':' in optstring for required arguments and '::'
 *   for optional arguments.
 * - arguments can be followed directly by optargs (like -loptarg)
 *   or in the next argv[] element (like -l optarg).
 * - arguments can be grouped together (like ls -alR)
 * - options can be mixed with nonoptions (like ls /bin -R)
 */

int getopt(int argc, char *argv[], const char *optstring);

struct getopt_context {
	int opterr;
	int optind;
	int optopt;
	int nonopts;
	int optindex;
	char *optarg;
};

/*
 * We do not start a new process for each getopt() run, so we
 * need this function to save and restore the context.
 */
void getopt_context_store(struct getopt_context *ctx);
void getopt_context_restore(struct getopt_context *ctx);

#endif /* __GETOPT_H */