xref: /5.5.2/platform/include/platform/getopt.h (revision 56295be6)
1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2018 Couchbase, Inc.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17#pragma once
18
19/**
20 * This file contains a getopt implementation which is only used
21 * on Windows (but it is built on all platforms to make it easier
22 * to test ;)
23 */
24
25#include <platform/platform.h>
26
27namespace cb {
28namespace getopt {
29
30const int no_argument = 0;
31const int required_argument = 1;
32const int optional_argument = 2;
33
34struct option {
35    const char* name;
36    int has_arg;
37    int* flag;
38    int val;
39};
40
41PLATFORM_PUBLIC_API
42extern char* optarg;
43PLATFORM_PUBLIC_API
44extern int opterr;
45PLATFORM_PUBLIC_API
46extern int optind;
47PLATFORM_PUBLIC_API
48extern int optopt;
49
50PLATFORM_PUBLIC_API
51extern int getopt_long(int argc,
52                       char** argv,
53                       const char* optstring,
54                       const struct option* longopts,
55                       int* longindex);
56
57PLATFORM_PUBLIC_API
58extern int getopt(int argc, char** argv, const char* optstring);
59
60/**
61 * This is for unit tests only and used to reset the internal state
62 * of the library
63 */
64PLATFORM_PUBLIC_API
65void reset();
66} // namespace getopt
67} // namespace cb
68