aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/posix_getopt.h
blob: 8a8891a1f6437caa3b72e7c0f468ab15a81efd1b (plain) (blame)
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
#pragma once

// implementation of posix getopt using last getopt for demonstration purposes

#include "last_getopt.h"

namespace NLastGetopt {
    extern char* optarg;
    extern int optind;
    extern int optopt;
    extern int opterr;
    extern int optreset;

    enum {
        no_argument = NO_ARGUMENT,
        required_argument = REQUIRED_ARGUMENT,
        optional_argument = OPTIONAL_ARGUMENT,
    };

    struct option {
        const char* name;
        int has_arg;
        int* flag;
        int val;
    };

    int getopt(int argc, char* const* argv, const char* optstring);
    int getopt_long(int argc, char* const* argv, const char* optstring, 
                    const struct option* longopts, int* longindex); 
    int getopt_long_only(int argc, char* const* argv, const char* optstring,
                         const struct option* longopts, int* longindex); 
}