Skip to content

Commit d83f859

Browse files
Merge pull request #1184 from jan-cerny/move_getopt
Move fallback implementation of getopt to utils
2 parents fe9b0ff + d83de7b commit d83f859

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

compat/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ if(NOT HAVE_STRPTIME)
99
list(APPEND COMPAT_SOURCES "strptime.c")
1010
endif()
1111

12-
if(NOT HAVE_GETOPT_H)
13-
list(APPEND COMPAT_SOURCES "getopt.c")
14-
endif()
15-
1612
# dev_to_tty is used in the process and process58 probes that are UNIX only
1713
if(NOT HAVE_DEV_TO_TTY AND UNIX)
1814
list(APPEND COMPAT_SOURCES "dev_to_tty.c")

compat/compat.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,6 @@ typedef SSIZE_T ssize_t;
5757

5858
#endif
5959

60-
#ifndef HAVE_GETOPT_H
61-
62-
#define __getopt_argv_const const
63-
#define no_argument 0
64-
#define required_argument 1
65-
#define optional_argument 2
66-
67-
OSCAP_API extern char *optarg;
68-
OSCAP_API extern int optind;
69-
OSCAP_API extern int opterr;
70-
OSCAP_API extern int optopt;
71-
72-
struct option
73-
{
74-
const char *name;
75-
int has_arg;
76-
int *flag;
77-
int val;
78-
};
79-
80-
OSCAP_API int getopt_long(int ___argc, char *__getopt_argv_const *___argv,
81-
const char *__shortopts,
82-
const struct option *__longopts, int *__longind);
83-
84-
#endif
85-
8660
#if !defined(HAVE_DEV_TO_TTY) && !defined(OS_WINDOWS)
8761
#include <sys/types.h>
8862
#define ABBREV_DEV 1 /* remove /dev/ */

utils/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
if(ENABLE_OSCAP_UTIL)
22
file(GLOB UTILS_SOURCES "*.c")
3+
if(HAVE_GETOPT_H)
4+
list(REMOVE_ITEM UTILS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/getopt.c")
5+
endif()
36
add_executable(oscap ${UTILS_SOURCES})
47
target_link_libraries(oscap openscap)
58
if(WIN32)

compat/getopt.c renamed to utils/getopt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include <config.h>
2626
#endif
2727

28+
#ifndef HAVE_GETOPT_H
29+
2830
#include <stdio.h>
2931
#include <stdlib.h>
3032
#include <string.h>
3133

32-
#include "compat.h"
34+
#include "oscap-tool.h"
3335

3436

3537
#ifdef _LIBC
@@ -770,4 +772,6 @@ getopt_long(int argc, char *__getopt_argv_const *argv, const char *options,
770772
{
771773
return _getopt_internal(argc, (char **)argv, options, long_options,
772774
opt_index, 0, 0);
773-
}
775+
}
776+
777+
#endif

utils/oscap-tool.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,28 @@ extern struct oscap_module OSCAP_CVRF_MODULE;
199199
extern struct oscap_module OSCAP_CPE_MODULE;
200200
extern struct oscap_module OSCAP_INFO_MODULE;
201201

202+
#ifndef HAVE_GETOPT_H
203+
204+
#define __getopt_argv_const const
205+
#define no_argument 0
206+
#define required_argument 1
207+
#define optional_argument 2
208+
209+
extern char *optarg;
210+
extern int optind;
211+
extern int opterr;
212+
extern int optopt;
213+
214+
struct option
215+
{
216+
const char *name;
217+
int has_arg;
218+
int *flag;
219+
int val;
220+
};
221+
222+
getopt_long(int ___argc, char *__getopt_argv_const *___argv,
223+
const char *__shortopts,
224+
const struct option *__longopts, int *__longind);
225+
226+
#endif

0 commit comments

Comments
 (0)