1 #ifndef INCLUDED_GETOPT_H
2 #define INCLUDED_GETOPT_H
3 /* vim: set ts=8 sts=4 sw=4 tw=80 noet: */
4 /*======================================================================
5 Copyright (C) 2004,2005,2009 Walter Doekes <walter+tthsum@wjd.nu>
6 This file is part of tthsum.
7 
8 tthsum is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 tthsum is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with tthsum.  If not, see <http://www.gnu.org/licenses/>.
20 ======================================================================*/
21 
22 /**
23  * A portable getopt implementation, selecting the native version if
24  * available.
25  */
26 
27 #if defined(USE_MY_GETOPT)
28     /* We'll use mine */
29 #elif defined(_WIN32)
30 #   define USE_MY_GETOPT
31 #elif defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
32 #   define USE_BSD_GETOPT
33 #elif _POSIX_C_SOURCE < 200112
34 #   define USE_MY_GETOPT
35 #elif defined(POSIXLY_CORRECT)
36 #   define USE_BSD_GETOPT
37 #endif
38 
39 
40 #ifdef USE_MY_GETOPT
41 
42 #include "types.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * A simplified getopt, works just like POSIX getopt, and implements
50  * the GNU double-colon for optional arguments.
51  */
52 int getopt(int argc, char* const argv[], const char* optstring);
53 
54 /**
55  * Option argument for argument-having options. Do not try to modify
56  * this string as it should be (const char*) but isn't because we try
57  * to be compatible with POSIX getopt.
58  */
59 extern char *optarg;
60 
61 /**
62  * External getopt globals: non-option index, enable/disable errors
63  * on stderr, invalid option character.
64  */
65 extern int optind, opterr, optopt;
66 
67 #ifdef __cplusplus
68 } /* extern "C" */
69 #endif /* __cplusplus */
70 
71 #else /* !USE_MY_GETOPT */
72 
73 #include <unistd.h>
74 
75 #endif /* !USE_MY_GETOPT */
76 
77 #endif /* INCLUDED_GETOPT_H */
78