From c5b0e0b96b90403cd4bf950c03a19355289e2837 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 5 Sep 2020 20:47:40 +0300 Subject: [PATCH] LibC: Don't include things required for getopt_long in unistd.h Previously, we were including the whole of in . However according to the posix doesn't have to contain everything we had in . This fixes some symbol collisions that broke the git port. --- Libraries/LibC/getopt.cpp | 6 ++---- Libraries/LibC/getopt.h | 15 --------------- Libraries/LibC/unistd.cpp | 1 + Libraries/LibC/unistd.h | 17 ++++++++++++++++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Libraries/LibC/getopt.cpp b/Libraries/LibC/getopt.cpp index d28d0e3c05..a8142262d7 100644 --- a/Libraries/LibC/getopt.cpp +++ b/Libraries/LibC/getopt.cpp @@ -29,6 +29,7 @@ #include #include #include +#include int opterr = 1; int optopt = 0; @@ -41,7 +42,6 @@ char* optarg = nullptr; // processed". Well, this is how we do it. static size_t s_index_into_multioption_argument = 0; - static inline void report_error(const char* format, ...) { if (!opterr) @@ -101,7 +101,6 @@ OptionParser::OptionParser(int argc, char** argv, const StringView& short_option // extension that we support. m_stop_on_first_non_option = short_options.starts_with('+'); - // See if we should reset the internal state. if (optreset || optind == 0) { optreset = 0; @@ -149,7 +148,6 @@ int OptionParser::getopt() return res; } - bool OptionParser::lookup_short_option(char option, int& needs_value) const { Vector parts = m_short_options.split_view(option, true); @@ -325,7 +323,7 @@ void OptionParser::shift_argv() char* buffer[m_consumed_args]; memcpy(buffer, &m_argv[m_arg_index], sizeof(char*) * m_consumed_args); - memmove(&m_argv[optind + m_consumed_args], &m_argv[optind], sizeof(char *) * (m_arg_index - optind)); + memmove(&m_argv[optind + m_consumed_args], &m_argv[optind], sizeof(char*) * (m_arg_index - optind)); memcpy(&m_argv[optind], buffer, sizeof(char*) * m_consumed_args); } diff --git a/Libraries/LibC/getopt.h b/Libraries/LibC/getopt.h index df1974af46..5c422d414a 100644 --- a/Libraries/LibC/getopt.h +++ b/Libraries/LibC/getopt.h @@ -28,20 +28,6 @@ __BEGIN_DECLS -// If opterr is set (the default), print error messages to stderr. -extern int opterr; -// On errors, optopt is set to the erroneous *character*. -extern int optopt; -// Index of the next argument to process upon a getopt*() call. -extern int optind; -// If set, reset the internal state kept by getopt*(). You may also want to set -// optind to 1 in that case. Alternatively, setting optind to 0 is treated like -// doing both of the above. -extern int optreset; -// After parsing an option that accept an argument, set to point to the argument -// value. -extern char* optarg; - #define no_argument 0 #define required_argument 1 #define optional_argument 2 @@ -53,7 +39,6 @@ struct option { int val; }; -int getopt(int argc, char** argv, const char* short_options); int getopt_long(int argc, char** argv, const char* short_options, const struct option* long_options, int* out_long_option_index); __END_DECLS diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 22a8856751..4c7df9f0ce 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index cfbb07d3b1..0faa5f4397 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -37,7 +37,6 @@ #include #include #include -#include __BEGIN_DECLS @@ -191,4 +190,20 @@ struct crypt_data { char* crypt(const char* key, const char* salt); char* crypt_r(const char* key, const char* salt, struct crypt_data* data); +// If opterr is set (the default), print error messages to stderr. +extern int opterr; +// On errors, optopt is set to the erroneous *character*. +extern int optopt; +// Index of the next argument to process upon a getopt*() call. +extern int optind; +// If set, reset the internal state kept by getopt*(). You may also want to set +// optind to 1 in that case. Alternatively, setting optind to 0 is treated like +// doing both of the above. +extern int optreset; +// After parsing an option that accept an argument, set to point to the argument +// value. +extern char* optarg; + +int getopt(int argc, char** argv, const char* short_options); + __END_DECLS