1 /* *****************************************************************
2 *
3 * Copyright 2016 Microsoft
4 *
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ******************************************************************/
19 
20 #include "getopt.h"
21 #include <windows.h>
22 
23 char* optarg = NULL;
24 int optind = 1;
25 
getopt(int argc,char * const argv[],const char * optstring)26 int getopt(int argc, char *const argv[], const char *optstring)
27 {
28     if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0))
29     {
30         return -1;
31     }
32 
33     int opt = argv[optind][1];
34     const char *p = strchr(optstring, opt);
35 
36     if (p == NULL)
37     {
38         return '?';
39     }
40     if (p[1] == ':')
41     {
42         optind++;
43         if (optind >= argc)
44         {
45             return '?';
46         }
47         optarg = argv[optind];
48         optind++;
49     }
50     return opt;
51 }
52 
53