From f8bd607733e989b936877ff3516f84f1d14fd55b Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 15 Jul 2023 18:51:44 +0200 Subject: [PATCH] LibC: Make `getopt` available from `getopt.h` --- Userland/Libraries/LibC/bits/getopt.h | 29 +++++++++++++++++++++++++++ Userland/Libraries/LibC/getopt.h | 6 +----- Userland/Libraries/LibC/unistd.h | 17 +--------------- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 Userland/Libraries/LibC/bits/getopt.h diff --git a/Userland/Libraries/LibC/bits/getopt.h b/Userland/Libraries/LibC/bits/getopt.h new file mode 100644 index 0000000000..217041f5b9 --- /dev/null +++ b/Userland/Libraries/LibC/bits/getopt.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, the SerenityOS contributors. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +__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. +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* const* argv, char const* short_options); +int getsubopt(char** optionp, char* const* tokens, char** valuep); + +__END_DECLS diff --git a/Userland/Libraries/LibC/getopt.h b/Userland/Libraries/LibC/getopt.h index f5fca0c682..1d7b689deb 100644 --- a/Userland/Libraries/LibC/getopt.h +++ b/Userland/Libraries/LibC/getopt.h @@ -6,6 +6,7 @@ #pragma once +#include #include __BEGIN_DECLS @@ -21,11 +22,6 @@ struct option { int val; }; -extern int opterr; -extern int optopt; -extern int optind; -extern int optreset; -extern char* optarg; int getopt_long(int argc, char* const* argv, char const* short_options, const struct option* long_options, int* out_long_option_index); __END_DECLS diff --git a/Userland/Libraries/LibC/unistd.h b/Userland/Libraries/LibC/unistd.h index ef29f6c969..d935f2e314 100644 --- a/Userland/Libraries/LibC/unistd.h +++ b/Userland/Libraries/LibC/unistd.h @@ -14,6 +14,7 @@ #pragma once #include +#include #include #include #include @@ -162,20 +163,4 @@ enum { long sysconf(int name); -// 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. -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* const* argv, char const* short_options); -int getsubopt(char** optionp, char* const* tokens, char** valuep); - __END_DECLS