Quick : move code for wingetopt into opensea-common.#33
Open
sharma-nidhi wants to merge 5 commits into
Open
Conversation
vonericsen
requested changes
Jul 13, 2026
| * POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| #ifndef __GETOPT_H__ |
Contributor
There was a problem hiding this comment.
We should change this header ifdef block to #pragma once that we use in other files
| * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| */ | ||
|
|
||
| #define __GETOPT_H__ // NOLINT |
Contributor
There was a problem hiding this comment.
After changing to #pragma once we can delete this line
| } | ||
| #endif | ||
|
|
||
| #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */ |
Contributor
There was a problem hiding this comment.
After changing to #pragma once I think we can delete this line
Signed-off-by: Nidhi Sharma <nidhi.sharma@seagate.com>
vonericsen
reviewed
Jul 15, 2026
| @@ -0,0 +1,124 @@ | |||
| /* SPDX-License-Identifier: BSD-2-Clause */ | |||
Contributor
There was a problem hiding this comment.
put and MPL-2.0 on this line
vonericsen
reviewed
Jul 15, 2026
| @@ -0,0 +1,141 @@ | |||
| // SPDX-License-Identifier: MPL-2.0 | |||
|
|
|||
| //! \file wingetopt_utils.h | |||
Contributor
There was a problem hiding this comment.
change to program_name_utils.h
vonericsen
reviewed
Jul 15, 2026
| @@ -0,0 +1,153 @@ | |||
| // SPDX-License-Identifier: MPL-2.0 | |||
|
|
|||
| //! \file winCMDLINE_utils.h | |||
Contributor
There was a problem hiding this comment.
change to warning_utils.h
vonericsen
reviewed
Jul 15, 2026
| @@ -0,0 +1,673 @@ | |||
| /* SPDX-License-Identifier: 0BSD AND BSD-2-Clause */ | |||
Contributor
There was a problem hiding this comment.
add AND MPL-2.0 to this line
… banner. Signed-off-by: Nidhi Sharma <nidhi.sharma@seagate.com>
Signed-off-by: Nidhi Sharma <nidhi.sharma@seagate.com>
… is not available on windows by-default. Signed-off-by: Nidhi Sharma <nidhi.sharma@seagate.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move getopt implementation from wingetopt into opensea-common; remove wingetopt dependency
Summary
This PR consolidates the getopt/getopt_long/getopt_long_only implementation from an external
wingetoptdependency directly intoopensea-common. The migration eliminates external dependencies while hardening the codebase with comprehensive compiler attributes (nullability, access patterns, printf-style checking) and security-focused I/O functions.Motivation
Previously, command-line parsing relied on a separate
wingetoptlibrary. By bringing the implementation in-tree:Changes
Command-line Utilities
include/cmdline_utils.h | src/cmdline_utils.c
Full implementation of POSIX getopt API (derived from OpenBSD/NetBSD sources):
Public interfaces (
getopt,getopt_long,getopt_long_only) fully annotated with:M_NODISCARD)M_NULL_TERM_STRING)M_PARAM_RO,M_PARAM_RW,M_PARAM_WO)Parameter semantics correctly distinguished:
nargvread-only ingetopt(no permutation)nargvread-write ingetopt_long/getopt_long_only(may permute argv)Internal helper functions (
getopt_internal,parse_long_options,permute_args):M_CONST_FUNC,M_PURE_FUNC)M_NONNULL_PARAM_LIST)Platform-aware environment variable access:
getenv_son MSVC/Windowssecure_getenvor__secure_getenvon Unix-like systemsgetenvon unsupported platformsWarning and Error Handling
include/warning_utils.h (new file)
Portable command-line error reporting:
eCMDLineErrorMessage) avoids compiler warnings about non-const format stringswarnx/vwarnxfrom<err.h>with portable alternativesfprintf_s,vfprintf_s) when availableSecurity Improvements
fprintf_s/vfprintf_s) on MSVC and modern C11-compliant systemssecure_getenv/__secure_getenv) where supportedM_NODISCARDon all public API entry pointsTesting
wingetoptremains unchanged