Skip to content

Commit f8bd607

Browse files
timschumiADKaster
authored andcommitted
LibC: Make getopt available from getopt.h
1 parent aae106e commit f8bd607

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

Userland/Libraries/LibC/bits/getopt.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2023, the SerenityOS contributors.
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#include <sys/cdefs.h>
10+
11+
__BEGIN_DECLS
12+
13+
// If opterr is set (the default), print error messages to stderr.
14+
extern int opterr;
15+
// On errors, optopt is set to the erroneous *character*.
16+
extern int optopt;
17+
// Index of the next argument to process upon a getopt*() call.
18+
extern int optind;
19+
// If set, reset the internal state kept by getopt*(). You may also want to set
20+
// optind to 1 in that case.
21+
extern int optreset;
22+
// After parsing an option that accept an argument, set to point to the argument
23+
// value.
24+
extern char* optarg;
25+
26+
int getopt(int argc, char* const* argv, char const* short_options);
27+
int getsubopt(char** optionp, char* const* tokens, char** valuep);
28+
29+
__END_DECLS

Userland/Libraries/LibC/getopt.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#pragma once
88

9+
#include <bits/getopt.h>
910
#include <sys/cdefs.h>
1011

1112
__BEGIN_DECLS
@@ -21,11 +22,6 @@ struct option {
2122
int val;
2223
};
2324

24-
extern int opterr;
25-
extern int optopt;
26-
extern int optind;
27-
extern int optreset;
28-
extern char* optarg;
2925
int getopt_long(int argc, char* const* argv, char const* short_options, const struct option* long_options, int* out_long_option_index);
3026

3127
__END_DECLS

Userland/Libraries/LibC/unistd.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma once
1515

1616
#include <Kernel/API/POSIX/unistd.h>
17+
#include <bits/getopt.h>
1718
#include <fd_set.h>
1819
#include <limits.h>
1920
#include <sys/cdefs.h>
@@ -162,20 +163,4 @@ enum {
162163

163164
long sysconf(int name);
164165

165-
// If opterr is set (the default), print error messages to stderr.
166-
extern int opterr;
167-
// On errors, optopt is set to the erroneous *character*.
168-
extern int optopt;
169-
// Index of the next argument to process upon a getopt*() call.
170-
extern int optind;
171-
// If set, reset the internal state kept by getopt*(). You may also want to set
172-
// optind to 1 in that case.
173-
extern int optreset;
174-
// After parsing an option that accept an argument, set to point to the argument
175-
// value.
176-
extern char* optarg;
177-
178-
int getopt(int argc, char* const* argv, char const* short_options);
179-
int getsubopt(char** optionp, char* const* tokens, char** valuep);
180-
181166
__END_DECLS

0 commit comments

Comments
 (0)