1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:48:11 +00:00

LibC: Don't include things required for getopt_long in unistd.h

Previously, we were including the whole of <getopt.h> in <unistd.h>.
However according to the posix <unistd.h> doesn't have to contain
everything we had in <getopt.h>.

This fixes some symbol collisions that broke the git port.
This commit is contained in:
Itamar 2020-09-05 20:47:40 +03:00 committed by Andreas Kling
parent efac3d27d2
commit c5b0e0b96b
4 changed files with 19 additions and 20 deletions

View file

@ -29,6 +29,7 @@
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
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<StringView> 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);
}