summaryrefslogtreecommitdiff
path: root/win/inspircd_win32wrapper.cpp
diff options
context:
space:
mode:
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2009-08-02 22:36:45 +0000
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2009-08-02 22:36:45 +0000
commit9b35fab3495a816a0d8fe48a0d7a22f2217f040d (patch)
treea80e8b538d630bd68b98fd6b2d31f180c53603ac /win/inspircd_win32wrapper.cpp
parent091e6e8bd9686f680fa72ab0844c7a2473233215 (diff)
Fix our getops implementation on windows. Have optind available, and make sure it always points to the next entry in the argv list as described by POSIX.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11466 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'win/inspircd_win32wrapper.cpp')
-rw-r--r--win/inspircd_win32wrapper.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp
index 0bff707db..9d75fd2ea 100644
--- a/win/inspircd_win32wrapper.cpp
+++ b/win/inspircd_win32wrapper.cpp
@@ -236,16 +236,17 @@ int printf_c(const char * format, ...)
return c;
}
-int arg_counter = 1;
+int optind = 1;
char optarg[514];
int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
{
// burlex todo: handle the shortops, at the moment it only works with longopts.
- if (___argc == 1 || arg_counter == ___argc) // No arguments (apart from filename)
+ if (___argc == 1 || optind == ___argc) // No arguments (apart from filename)
return -1;
- const char * opt = ___argv[arg_counter];
+ const char * opt = ___argv[optind];
+ optind++;
// if we're not an option, return an error.
if (strnicmp(opt, "--", 2) != 0)
@@ -262,18 +263,18 @@ int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts,
{
// woot, found a valid argument =)
char * par = 0;
- if ((arg_counter + 1) != ___argc)
+ if ((optind) != ___argc)
{
// grab the parameter from the next argument (if its not another argument)
- if (strnicmp(___argv[arg_counter+1], "--", 2) != 0)
+ if (strnicmp(___argv[optind], "--", 2) != 0)
{
- arg_counter++; // Trash this next argument, we won't be needing it.
- par = ___argv[arg_counter];
+// optind++; // Trash this next argument, we won't be needing it.
+ par = ___argv[optind-1];
}
}
// increment the argument for next time
- arg_counter++;
+// optind++;
// determine action based on type
if (__longopts[i].has_arg == required_argument && !par)