aboutsummaryrefslogtreecommitdiff
path: root/lib/compat/getopt_long.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 11:21:30 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 13:51:49 +0100
commitcdccc69c62579b0c13b35fad0728079652b8f3c9 (patch)
tree9fa54c710f73c5e08a9c8466e7a712eb63ee07ac /lib/compat/getopt_long.c
parent2182129c8f359c4fa1390eaba7a65b595ccd4182 (diff)
Move library source into src sub-directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/compat/getopt_long.c')
-rw-r--r--lib/compat/getopt_long.c95
1 files changed, 0 insertions, 95 deletions
diff --git a/lib/compat/getopt_long.c b/lib/compat/getopt_long.c
deleted file mode 100644
index 58354c3..0000000
--- a/lib/compat/getopt_long.c
+++ /dev/null
@@ -1,95 +0,0 @@
-#include "compat.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <getopt.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifndef HAVE_GETOPT_LONG
-static void permute(char *const *argv, int dest, int src)
-{
- char **av = (char **)argv;
- char *tmp = av[src];
- int i;
- for (i=src; i>dest; i--)
- av[i] = av[i-1];
- av[dest] = tmp;
-}
-
-int getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
-{
- optarg = 0;
- if (longopts && argv[optind][0] == '-' &&
- (argv[optind][1] == '-' && argv[optind][2]))
- {
- int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
- int i, cnt, match;
- char *arg, *opt, *start = argv[optind]+1;
- for (cnt=i=0; longopts[i].name; i++) {
- const char *name = longopts[i].name;
- opt = start;
- if (*opt == '-') opt++;
- while (*opt && *opt != '=' && *opt == *name)
- name++, opt++;
- if (*opt && *opt != '=') continue;
- arg = opt;
- match = i;
- if (!*name) {
- cnt = 1;
- break;
- }
- cnt++;
- }
- if (cnt==1) {
- i = match;
- opt = arg;
- optind++;
- if (*opt == '=') {
- if (!longopts[i].has_arg) {
- optopt = longopts[i].val;
- if (colon || !opterr)
- return '?';
- __getopt_msg(argv[0],
- ": option does not take an argument: ",
- longopts[i].name,
- strlen(longopts[i].name));
- return '?';
- }
- optarg = opt+1;
- } else if (longopts[i].has_arg == required_argument) {
- if (!(optarg = argv[optind])) {
- optopt = longopts[i].val;
- if (colon) return ':';
- if (!opterr) return '?';
- __getopt_msg(argv[0],
- ": option requires an argument: ",
- longopts[i].name,
- strlen(longopts[i].name));
- return '?';
- }
- optind++;
- }
- if (idx) *idx = i;
- if (longopts[i].flag) {
- *longopts[i].flag = longopts[i].val;
- return 0;
- }
- return longopts[i].val;
- }
- if (argv[optind][1] == '-') {
- optopt = 0;
- if (!colon && opterr)
- __getopt_msg(argv[0], cnt ?
- ": option is ambiguous: " :
- ": unrecognized option: ",
- argv[optind]+2,
- strlen(argv[optind]+2));
- optind++;
- return '?';
- }
- }
- return getopt(argc, argv, optstring);
-}
-#endif