Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
224 commits
Select commit Hold shift + click to select a range
ec24819
Set up port of glibc 2.43
tom42 Jun 8, 2026
6ff607e
Add argp-fmtstream.c
tom42 Jun 8, 2026
ff63668
Replace call to __vsnprintf_internal with call to vsnprintf
tom42 Jun 8, 2026
c09d1ec
Add argp-fs-xinl.c
tom42 Jun 8, 2026
7a34d38
Add more sources (argp-pv.c, argp-pvh.c and argp-xinl.c)
tom42 Jun 9, 2026
0c195cf
Comment out __restrict to get build with MSVC working
tom42 Jun 9, 2026
6e2beb1
Add argp-help.c
tom42 Jun 9, 2026
eefc493
Include <stdint.h> to get uint8_t. Required for MSVC.
tom42 Jun 9, 2026
3a8aca9
Comment out attribute. Will have to figure out what to do with these.
tom42 Jun 9, 2026
c3d95db
Fix strerror_r usage in argp-help.c
tom42 Jun 9, 2026
0f1d481
Add argp-parse.c
tom42 Jun 9, 2026
ef8a12c
Conditionally include <unistd.h>
tom42 Jun 9, 2026
154bdef
Add getopt headers, but prefixed with argp-
tom42 Jun 9, 2026
1ce6cee
Comment out features.h and see what happens
tom42 Jun 9, 2026
c651f9e
Add even more getopt headers and include them
tom42 Jun 9, 2026
1c00df6
Comment out stuff that does not build
tom42 Jun 9, 2026
5a96873
Include compatibility header
tom42 Jun 9, 2026
eb1261b
Adsd note on __restrict
tom42 Jun 9, 2026
c040eac
Fix for compilers that do not support void pointer arithmetics
tom42 Jun 9, 2026
353e435
Get program_invocation_short_name and program_invocation_name
tom42 Jun 9, 2026
bde1a94
Fix when compiling with glibc
tom42 Jun 9, 2026
e215ca9
Rename args so that they do not clash with MSCV macros of same name
tom42 Jun 9, 2026
e2bed1a
Add test subdirectory for 2.43
tom42 Jun 9, 2026
befd469
Add argp-test
tom42 Jun 9, 2026
89c15df
Add replacements for random and asprintf
tom42 Jun 9, 2026
f160e9f
Change code to use asprintf and not xasprintf
tom42 Jun 9, 2026
c44dc72
Link to correct argp version
tom42 Jun 9, 2026
736b206
add argp-compat.ch
tom42 Jun 10, 2026
400c527
Define alloca() for Win32
tom42 Jun 10, 2026
9d9fa05
Fix argp-xinl.c to resolve linker errors related to extern inlines
tom42 Jun 10, 2026
377eac6
Add note regarding -fnu89-inline usage
tom42 Jun 10, 2026
0592f6e
Fix another odd linker error
tom42 Jun 10, 2026
caed926
Add getopt1.c
tom42 Jun 10, 2026
4510bcd
Fix getopt1.c, include replacement getopt headers
tom42 Jun 10, 2026
eeb67ee
Add getopt.c
tom42 Jun 10, 2026
97d7fe0
Fixing getopt.c
tom42 Jun 10, 2026
47432b8
Suppress MSVC security warnings
tom42 Jun 10, 2026
c710405
Fix macOS
tom42 Jun 10, 2026
7c2ab5c
Fix licensing information
tom42 Jun 10, 2026
63ac129
Reindent/reformat
tom42 Jun 10, 2026
5a68ce2
Reapply fixes done to __argp_short_program_name
tom42 Jun 10, 2026
4900bec
Add license and copyright info
tom42 Jun 10, 2026
9082a97
Fix BSDs: need to declare __progname
tom42 Jun 10, 2026
3986373
-fgnu89-inline is still necessary
tom42 Jun 10, 2026
4bc51e1
Temporarily fix warning when building with Cygwin gcc and/or newlib
tom42 Jun 11, 2026
a4a80a2
Comment out conflicting declarations of global getopt variables.
tom42 Jun 11, 2026
a6bfb24
Try getting mingw building
tom42 Jun 11, 2026
c0d3124
Try next fix for mingw
tom42 Jun 11, 2026
9e145f4
Add some notes [skip ci]
tom42 Jun 12, 2026
93d8810
Delete the entire old 2.24 code
tom42 Jun 12, 2026
5ffcc35
Rename 2.43 source trees to their normal names
tom42 Jun 12, 2026
9cd8394
Fix up directories so that stuff builds again
tom42 Jun 12, 2026
f41457d
Add unity 2.6.1 again
tom42 Jun 12, 2026
203b680
Rename argp-standalone243 to argp-standalone
tom42 Jun 12, 2026
783e904
Rename argp-standalone243 to argp-standalone
tom42 Jun 12, 2026
6b8b14f
Enable warnings on argp-test
tom42 Jun 12, 2026
83c1325
Merge branch '4-update-to-glibc-243' of https://github.com/tom42/argp…
tom42 Jun 12, 2026
2f714eb
Suppress warning for gcc again
tom42 Jun 12, 2026
66e1287
Remove duplicate license tag [skip ci]
tom42 Jun 12, 2026
7f68657
Reformat [skip ci]
tom42 Jun 12, 2026
cb381d0
Add argp-compat-test
tom42 Jun 12, 2026
30549a8
Add argp-failure-test
tom42 Jun 12, 2026
0abb3c1
Add tst-argp1.c (does not build)
tom42 Jun 12, 2026
35a6dae
Add SPDX license tag
tom42 Jun 12, 2026
63585a7
Get tst-argp1.c compiling and running
tom42 Jun 15, 2026
4c1c406
Get tst-argp2.c compiling and running
tom42 Jun 15, 2026
d3de979
Remove todo item: library has been renamed
tom42 Jun 15, 2026
c244cb5
Tick off tests
tom42 Jun 15, 2026
9d4dcdb
Add tst-ldbl-argp
tom42 Jun 16, 2026
ee5fe41
Get tst-ldbl-argp.c compiling
tom42 Jun 16, 2026
09a1eb4
Actually fix tst-ldbl-argp
tom42 Jun 16, 2026
5ef783b
Trying to get tst-ldbl-argp up and runnin
tom42 Jun 16, 2026
1f8db56
Add SPDX license tag [skip ci]
tom42 Jun 16, 2026
312f61a
Get tst-ldbl-argp-error working
tom42 Jun 16, 2026
657629b
Clean up [skip ci]
tom42 Jun 16, 2026
98bf8bf
Clean up [skip ci]
tom42 Jun 16, 2026
90361fd
Decision: do not keep bug-argp1.c and bug-argp2.c
tom42 Jun 17, 2026
88af69e
Tick off tst-ldbl-argp.c, it's done
tom42 Jun 17, 2026
a7b8040
Probe for xasprintf not asprintf
tom42 Jun 17, 2026
5359bea
Undo most changes done to argp-test.c
tom42 Jun 17, 2026
0e2f3e6
Add missing <stdio.h>
tom42 Jun 17, 2026
01744c8
Handle negative return value from vsnprintf
tom42 Jun 17, 2026
6467933
Handle if malloc returns NULL
tom42 Jun 17, 2026
f76765a
Add xvsnprintf helper function
tom42 Jun 17, 2026
e16357f
Introduce xmalloc() helper function
tom42 Jun 17, 2026
00b191e
bufsiz can be const
tom42 Jun 17, 2026
d119e10
Pass correct buffer size
tom42 Jun 17, 2026
eeb6707
Remove remnants of old asprintf implementation
tom42 Jun 17, 2026
5ea5a93
xsnprintf: always terminate buffer in case snprintf is buggy
tom42 Jun 18, 2026
a07c569
Fix function names in error messages
tom42 Jun 18, 2026
ec24913
Reformat comment
tom42 Jun 18, 2026
23789d5
More detailed comment
tom42 Jun 18, 2026
d5ccdb7
Remove todo, function is good, to the best of my knowledge
tom42 Jun 18, 2026
0983a4d
Remove suppression of -Wunused-result
tom42 Jun 18, 2026
e1698c3
Tick off stuff
tom42 Jun 22, 2026
cec9451
Remove old stuff from main CMakeLists.txt
tom42 Jun 22, 2026
0cd1c51
Add TODO: also test compilation with C++ [skip ci]
tom42 Jun 22, 2026
e6a151b
Include <stdarg.h> in test_support.h
tom42 Jun 22, 2026
2b83b14
Remove shorter argp.h header
tom42 Jun 22, 2026
7ac798d
Enable compiler warnings for argp-failure-test
tom42 Jun 23, 2026
c167c62
Reindent argp-compat.c [skip ci]
tom42 Jun 24, 2026
fbc750b
Enable C++ and see what happens on the build server
tom42 Jun 24, 2026
56c40a5
Cygwin: install g++
tom42 Jun 24, 2026
731bafc
Add C++ compilation test
tom42 Jun 24, 2026
71242c5
Link to argp-standalone
tom42 Jun 24, 2026
22dd7eb
Add extern "C" when compiling with C++
tom42 Jun 24, 2026
856291d
Add note [skip ci]
tom42 Jun 24, 2026
2309495
Also include argp-fmtstream.h
tom42 Jun 28, 2026
c815aa9
Remove obsolete/pointless TODO items
tom42 Jun 28, 2026
bb49344
Fix argp-cpp-test for windows
tom42 Jun 28, 2026
6d11efd
Get release builds with g++ working
tom42 Jun 29, 2026
7fc32f5
Move definition of __THROW and __NTH to where it originally was
tom42 Jun 29, 2026
4c6456a
Remove obsolete TODO items
tom42 Jun 29, 2026
a329ffe
Add getopt compilation test
tom42 Jun 29, 2026
f4f1a75
Remove TODO items regarding annotations.
tom42 Jun 29, 2026
ecbf08c
Remove TODO item: already calling something from argp-getopt_core.h
tom42 Jun 29, 2026
8a1e281
C++ compilation test: also cover argp-getopt_ext.h
tom42 Jun 29, 2026
2bd4870
More recognizable error message
tom42 Jun 29, 2026
5265630
Also run argp-cpp-test, don't just compile it
tom42 Jun 29, 2026
7568fe6
Explain what this test does and remove remaining TODO items.
tom42 Jun 29, 2026
bab166c
Remove TODO item regarding annotation.
tom42 Jun 29, 2026
9bbc85b
Remove TODO items regarding _GL_UNUSED.
tom42 Jun 29, 2026
1614ce7
Remove TODO items regarding annotations
tom42 Jun 30, 2026
9a8dfb7
Enable C++ only when testing is enabled
tom42 Jun 30, 2026
a80305c
Remove todo item regarding annotation
tom42 Jun 30, 2026
848db9e
Remove TODO item regarding long double stuff
tom42 Jun 30, 2026
2db4ca3
Decision: do not include <getopt.h> from <argp.h>
tom42 Jun 30, 2026
092075c
Shorten comment
tom42 Jun 30, 2026
141b955
Remove todo item
tom42 Jun 30, 2026
07c65a8
Add back __attribute__ stuff
tom42 Jun 30, 2026
dc6145a
Remove todo item regarding annotation
tom42 Jul 1, 2026
3ceccdd
Add back __restrict stuff in argp.h
tom42 Jul 1, 2026
381d24a
Format comment
tom42 Jul 1, 2026
8bbe419
Add note on how to get <unistd.h>
tom42 Jul 1, 2026
836489f
Try fixing github builds for MinGW
tom42 Jul 1, 2026
4d25922
Try fixing github builds for MinGW
tom42 Jul 1, 2026
53bcd16
Test
tom42 Jul 1, 2026
b83f9bc
Test
tom42 Jul 1, 2026
827f8cb
Test
tom42 Jul 1, 2026
f311aa1
Undo experiments
tom42 Jul 1, 2026
0f60dad
Add missing return statement
tom42 Jul 1, 2026
e502425
Also specify CXX compiler in all presets that specify the C compiler
tom42 Jul 3, 2026
e24b11a
Clarify comment (what is 'here'?) [skip ci]
tom42 Jul 3, 2026
fae0452
Include __attribute__ again in argp-fmtstream.h
tom42 Jul 3, 2026
24a6a3b
Try getting rid of MinGW specific warnings
tom42 Jul 3, 2026
8964aca
Try getting rid of MinGW specific warnings
tom42 Jul 3, 2026
e81c224
Try getting rid of MinGW specific warnings
tom42 Jul 3, 2026
1b97422
Try getting rid of MinGW specific warnings
tom42 Jul 3, 2026
4d2c3ca
Try getting rid of MinGW specific warnings
tom42 Jul 3, 2026
2f4a329
Get rid of warnings from MinGW when compiling tst-ldbl-argp.
tom42 Jul 3, 2026
8d9794e
Add note on how to fix MinGW -Wformat warnings [skip ci]
tom42 Jul 3, 2026
30c9c24
Define attribute_hidden as no op if it does not exist.
tom42 Jul 3, 2026
14b52e7
Implement -Wformat warnings when MinGW-w64 is being used
tom42 Jul 4, 2026
9f14953
Implement -Wformat warnings correctly for MinGW-w64
tom42 Jul 4, 2026
5ca05d7
Verified: change from __vsnprintf_internal to vsnprintf is fine [skip…
tom42 Jul 4, 2026
edc6dab
Remove TODO regarding _alloca on Win32
tom42 Jul 4, 2026
ad6207a
getopt: reimplement throw stuff
tom42 Jul 4, 2026
f784ca3
Use __THROW, now that it exists
tom42 Jul 4, 2026
fef4e38
Ensure config.h is included before trying to include unistd.h
tom42 Jul 4, 2026
bfc7c7c
Fix build for Cygwin: should not actually include unistd.h on Cygwin.
tom42 Jul 4, 2026
50a04c4
Fix build: need to supply non-null for some arguments.
tom42 Jul 4, 2026
26e2e5b
Fix test for good
tom42 Jul 4, 2026
0c56e92
Define and use __nonnull if it does not exist
tom42 Jul 4, 2026
b7eb4c9
Decision: remove __nonnull altogether
tom42 Jul 4, 2026
04a8604
Remove TODO item regarding strerror_r [skip ci]
tom42 Jul 4, 2026
23966b4
Document why declarations of global getopt variables are removed [ski…
tom42 Jul 4, 2026
a58d754
Include argp-getopt.h instead of getopt.h
tom42 Jul 4, 2026
c133e50
Comment out attribute always_inline without replacement.
tom42 Jul 4, 2026
d5353e8
Verified void pointer arithmetic replacement
tom42 Jul 4, 2026
7385493
Removed TODO item - we'll keep argp-xinl.c [skip ci]
tom42 Jul 4, 2026
efc0859
Replace TODO with explanatory comment [skip ci]
tom42 Jul 4, 2026
474a40c
Remove todo item regarding uses-callbacks Make variable
tom42 Jul 4, 2026
7834dfe
Remove TODO: reviewed all CMakeLists.txt
tom42 Jul 4, 2026
4202e8c
Add note regarding cleaning up header checks [skip ci]
tom42 Jul 4, 2026
d524ce5
Format comment correctly [skip ci]
tom42 Jul 4, 2026
d3b3b9d
Remove checks for headers that are not used anymore
tom42 Jul 5, 2026
0e89614
Define weak aliases if weak_alias is defined. Because, hey, why not.
tom42 Jul 5, 2026
f454636
Undo hack and see what's going to break
tom42 Jul 5, 2026
5a3dfca
Annotate changed code
tom42 Jul 5, 2026
1548561
Trying to fix argp-xinl.c
tom42 Jul 6, 2026
9ff7c23
Reviewed _option_is_short, no change there [skip ci]
tom42 Jul 6, 2026
8a61c1c
Check function signature [skip ci]
tom42 Jul 8, 2026
9f9fe73
Use argp-xinl.c from glibc 2.37
tom42 Jul 17, 2026
202d245
Add back SPDX license tag, it got lost somewhen
tom42 Jul 17, 2026
e4c9b72
Add list of files that originate from glibc and that we're going to
tom42 Jul 17, 2026
d6314f8
Tick off all argp-compat related files. They don't need diffing.
tom42 Jul 20, 2026
9cbe65c
Tick off all unity related files. They don't need diffing.
tom42 Jul 20, 2026
781710d
Tick off argp-fs-xinl.c: only difference is the SPDX license tag
tom42 Jul 20, 2026
ae3b730
Tick off argp-pvh.c: only difference is the SPDX license tag
tom42 Jul 20, 2026
adc203e
Tick off test_support.h: this is not glibc code
tom42 Jul 20, 2026
5a773ee
Tick off argp-pv.c: only difference is the SPDX license tag [skip ci]
tom42 Jul 20, 2026
be6d934
Annotate and tick off argp-test.c [skip ci]
tom42 Jul 20, 2026
6568fb6
Tick off argp-failure-test.c: not from glibc
tom42 Jul 21, 2026
086bb32
Tick off argp-ba.c: no changes (except license tag)
tom42 Jul 21, 2026
515b476
Annotate argp-eexst.c [skip ci]
tom42 Jul 21, 2026
0f22d6c
Annotate tst-ldbl-argp.c [skip ci]
tom42 Jul 21, 2026
96ab038
Annotate tst-argp2.c [skip ci]
tom42 Jul 21, 2026
10c3cde
Annotate tst-argp1.c [skip ci]
tom42 Jul 22, 2026
3bfe105
Simplify annotation, finish annotating argp-namefrob.h [skip ci]
tom42 Jul 22, 2026
9be3e82
Annotate argp-fmtstream.c [skip ci]
tom42 Jul 22, 2026
3fd268c
Annotate getopt1.c [skip ci]
tom42 Jul 22, 2026
5caa233
Annotate argp-getopt.h [skip ci]
tom42 Jul 23, 2026
b8dbcf2
Annotated getopt.c
tom42 Jul 23, 2026
638561e
Annotated argp-getopt_core.h
tom42 Jul 23, 2026
a498f2b
Annotated argp-getopt_ext.h
tom42 Jul 23, 2026
bb8ef6c
Annotate argp-getopt_int.h [skip ci]
tom42 Jul 24, 2026
eb3c7b8
Annotate argp-fmtstream.h [skip ci]
tom42 Jul 26, 2026
cbede95
Annotate argp-fmtstream.h
tom42 Jul 26, 2026
3455026
Undo unnecessary formatting (unnecessary difference from original code)
tom42 Jul 26, 2026
870573d
Annotate argp-parse.c [skip ci]
tom42 Jul 26, 2026
4eaa1fc
Annotate argp-help.c (not yet complete) [skip ci]
tom42 Jul 26, 2026
e72fbf8
Finish annotating argp-help.c [skip ci]
tom42 Jul 27, 2026
db6d25a
Use argp-xinl.c 2.42 (last version before it completely changed) [ski…
tom42 Jul 28, 2026
4b0575c
Annotate argp-xinl.c [skip ci]
tom42 Jul 29, 2026
fce6b80
Fix annotation [skip ci]
tom42 Jul 30, 2026
1796e53
Fix annotation [skip ci]
tom42 Jul 30, 2026
9add90b
Merge branch '4-update-to-glibc-243' of https://github.com/tom42/argp…
tom42 Jul 30, 2026
a1c1932
Note that we have different definitions of __THROW
tom42 Jul 30, 2026
7831797
Annotate __NTH
tom42 Jul 30, 2026
5715bd4
argp.h: use definition of __THROW from <getopt.h>, not <argp.h>
tom42 Jul 30, 2026
8a7ccbb
Annotate argp.h
tom42 Jul 30, 2026
fa6761e
Annotate argp.h [skip ci]
tom42 Jul 30, 2026
a119503
Annotate argp.h
tom42 Jul 31, 2026
902fa66
Annotate argp.h, done annotating things [skip ci]
tom42 Jul 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ jobs:
- name: Install Cygwin
uses: cygwin/cygwin-install-action@v6
with:
packages: cmake gcc-core ninja
packages: cmake gcc-core gcc-g++ ninja

- name: Configure CMake
run: >
Expand Down
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option(argp_standalone_ENABLE_WARNINGS "Build argp-standalone with warnings enab

if(argp_standalone_BUILD_TESTING)
enable_testing()
enable_language(CXX)
endif()


Expand All @@ -39,10 +40,6 @@ cmake_push_check_state()
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)

# Check for headers
check_include_file(mempcpy.h HAVE_MEMPCPY_H)
check_include_file(strcase.h HAVE_STRCASE_H)
check_include_file(strchrnul.h HAVE_STRCHRNUL_H)
check_include_file(strndup.h HAVE_STRNDUP_H)
check_include_file(sysexits.h HAVE_SYSEXITS_H)
check_include_file(unistd.h HAVE_UNISTD_H)

Expand All @@ -67,7 +64,7 @@ check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
cmake_pop_check_state()

# Check for miscellaneous functions
check_symbol_exists(asprintf stdio.h HAVE_ASPRINTF)
check_function_exists(xasprintf HAVE_XASPRINTF)
check_symbol_exists(mempcpy string.h HAVE_MEMPCPY)
check_symbol_exists(random stdlib.h HAVE_RANDOM)
check_symbol_exists(sleep unistd.h HAVE_SLEEP)
Expand Down
8 changes: 6 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@
"name": "dev-linux-clang",
"inherits": "dev-linux",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang"
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"name": "dev-linux-gcc",
"inherits": "dev-linux",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc"
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"name": "dev-linux-mingw-32",
"inherits": "dev-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "i686-w64-mingw32-gcc",
"CMAKE_CXX_COMPILER": "i686-w64-mingw32-g++",
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_CROSSCOMPILING_EMULATOR": "wine"
}
Expand All @@ -47,6 +50,7 @@
"inherits": "dev-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "x86_64-w64-mingw32-gcc",
"CMAKE_CXX_COMPILER": "x86_64-w64-mingw32-g++",
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_CROSSCOMPILING_EMULATOR": "wine"
}
Expand Down
6 changes: 1 addition & 5 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
argp-standalone - standalone version of glibc's argp functions. */

/* Headers */
#cmakedefine01 HAVE_MEMPCPY_H
#cmakedefine01 HAVE_STRCASE_H
#cmakedefine01 HAVE_STRCHRNUL_H
#cmakedefine01 HAVE_STRNDUP_H
#cmakedefine01 HAVE_SYSEXITS_H
#cmakedefine01 HAVE_UNISTD_H

Expand All @@ -22,7 +18,7 @@
#cmakedefine01 HAVE_DECL_STRERROR_S

/* Miscellaneous functions */
#cmakedefine01 HAVE_ASPRINTF
#cmakedefine01 HAVE_XASPRINTF
#cmakedefine01 HAVE_MEMPCPY
#cmakedefine01 HAVE_RANDOM
#cmakedefine01 HAVE_SLEEP
Expand Down
75 changes: 57 additions & 18 deletions include/argp-standalone/argp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* Hierarchial argument parsing, layered over getopt.
Copyright (C) 1995-2016 Free Software Foundation, Inc.
/* Hierarchical argument parsing, layered over getopt.
Copyright (C) 1995-2026 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.

Expand All @@ -16,25 +16,39 @@

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
<https://www.gnu.org/licenses/>. */

#ifndef _ARGP_H
#define _ARGP_H

#include <stdio.h>
#include <ctype.h>
/* argp-standalone: do not include getopt.h in public header,
since it may not be available. */
/*#include <getopt.h>*/
#include <limits.h>

#define __need_error_t
#include <errno.h>

/* argp-standalone: define __THROW. Taken from older version of <getopt.h> */
#ifndef __THROW
# define __THROW
# ifndef __GNUC_PREREQ
# define __GNUC_PREREQ(maj, min) (0)
# endif
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# else
# define __THROW
# endif
#endif

/* argp-standalone: define __NTH. Taken from older version of <argp.h> */
#ifndef __NTH
# define __NTH(fct) fct __THROW
#endif

/* argp-standalone: more recent versions of glibc do not define __attribute__
here anymore but in some non-standard header that we might not have.
Add an own definition of __attribute__ from an older version of argp. */
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \
Expand All @@ -50,6 +64,9 @@
# endif
#endif

/* argp-standalone: more recent versions of glibc do not define __restrict
here anymore but in some non-standard header that we might not have.
Add an own definition of __restrict from an older version of argp. */
/* GCC 2.95 and later have "__restrict"; C99 compilers have
"restrict", and "configure" may have defined "restrict". */
#ifndef __restrict
Expand All @@ -62,15 +79,28 @@
# endif
#endif

#ifndef __error_t_defined
typedef int error_t;
# define __error_t_defined
/* argp-standalone: implement -Wformat warnings correctly when using MinGW-w64.
See https://stackoverflow.com/a/79974346/17365470. */
#ifdef __MINGW32__
# define argp_attribute_format(argp_format, argp_args) \
__attribute__ ((__format__ (__MINGW_PRINTF_FORMAT, argp_format, argp_args)))
#else
# define argp_attribute_format(argp_format, argp_args) \
__attribute__ ((__format__ (__printf__, argp_format, argp_args)))
#endif


/* argp-standalone: we do not have __BEGIN_DECLS/__END_DECLS. */
#ifdef __cplusplus
extern "C" {
#endif

/* error_t may or may not be available from errno.h, depending on the
operating system. */
#ifndef __error_t_defined
# define __error_t_defined 1
typedef int error_t;
#endif

/* A description of a particular option. A pointer to an array of
these is passed in the OPTIONS field of an argp structure. Each option
entry can correspond to one long option and/or one short option; more
Expand Down Expand Up @@ -269,7 +299,7 @@ struct argp
};

/* Possible KEY arguments to a help filter function. */
#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */
#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceding options. */
#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation;
Expand Down Expand Up @@ -404,10 +434,12 @@ struct argp_state
returned. This function may also call exit unless the ARGP_NO_HELP flag
is set. INPUT is a pointer to a value to be passed in to the parser. */
extern error_t argp_parse (const struct argp *__restrict __argp,
/* argp-standalone: __argc and __argv are macros in MSVC. */
int argc, char **__restrict argv,
unsigned __flags, int *__restrict __arg_index,
void *__restrict __input);
extern error_t __argp_parse (const struct argp *__restrict __argp,
/* argp-standalone: __argc and __argv are macros in MSVC. */
int argc, char **__restrict argv,
unsigned __flags, int *__restrict __arg_index,
void *__restrict __input);
Expand Down Expand Up @@ -483,7 +515,7 @@ extern void __argp_help (const struct argp *__restrict __argp,
parsing routine (thus taking an argp_state structure as the first
argument). They may or may not print an error message and exit, depending
on the flags in STATE -- in any case, the caller should be prepared for
them *not* to exit, and should return an appropiate error after calling
them *not* to exit, and should return an appropriate error after calling
them. [argp_usage & argp_error should probably be called argp_state_...,
but they're used often enough that they should be short] */

Expand All @@ -505,10 +537,10 @@ extern void __argp_usage (const struct argp_state *__state);
message, then exit (1). */
extern void argp_error (const struct argp_state *__restrict __state,
const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
argp_attribute_format (2, 3); /* argp-standalone: use own attribute. */
extern void __argp_error (const struct argp_state *__restrict __state,
const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
argp_attribute_format (2, 3); /* argp-standalone: use own attribute. */

/* Similar to the standard gnu error-reporting function error(), but will
respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
Expand All @@ -521,11 +553,11 @@ extern void __argp_error (const struct argp_state *__restrict __state,
extern void argp_failure (const struct argp_state *__restrict __state,
int __status, int __errnum,
const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 4, 5)));
argp_attribute_format (4, 5); /* argp-standalone: use own attribute. */
extern void __argp_failure (const struct argp_state *__restrict __state,
int __status, int __errnum,
const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 4, 5)));
argp_attribute_format (4, 5); /* argp-standalone: use own attribute. */

/* Returns true if the option OPT is a valid short option. */
extern int _option_is_short (const struct argp_option *__opt) __THROW;
Expand All @@ -547,13 +579,14 @@ extern void *__argp_input (const struct argp *__restrict __argp,

#ifdef __USE_EXTERN_INLINES

# if !_LIBC
# if !(defined _LIBC && _LIBC)
# define __argp_usage argp_usage
# define __argp_state_help argp_state_help
# define __option_is_short _option_is_short
# define __option_is_end _option_is_end
# endif

/* argp-standalone: needed for old argp-xinl.c from glibc 2.42 we're using. */
# ifndef ARGP_EI
# define ARGP_EI __extern_inline
# endif
Expand Down Expand Up @@ -582,14 +615,20 @@ __NTH (__option_is_end (const struct argp_option *__opt))
return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
}

# if !_LIBC
# if !(defined _LIBC && _LIBC)
# undef __argp_usage
# undef __argp_state_help
# undef __option_is_short
# undef __option_is_end
# endif
#endif /* Use extern inlines. */

/* argp-standalone: do not implement glibc's long double redirection. */
/*#include <bits/floatn.h>
#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
# include <bits/argp-ldbl.h>
#endif*/

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# argp-standalone - standalone version of glibc's argp functions.

set(
SOURCES
add_library(
argp-standalone
argp-ba.c
argp-compat.c
argp-eexst.c
Expand All @@ -17,15 +17,14 @@ set(
getopt.c
getopt1.c)

add_library(argp-standalone ${SOURCES})

target_compile_definitions(argp-standalone PRIVATE HAVE_CONFIG_H)
argp_standalone_target_enable_warnings(argp-standalone)

target_include_directories(
argp-standalone
PRIVATE
"${PROJECT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}"
PUBLIC
../include/argp-standalone)

Expand Down
4 changes: 2 additions & 2 deletions src/argp-ba.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
Copyright (C) 1996-2016 Free Software Foundation, Inc.
Copyright (C) 1996-2026 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.

Expand All @@ -16,7 +16,7 @@

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
<https://www.gnu.org/licenses/>. */

/* If set by the user program, it should point to string that is the
bug-reporting address for the program. It will be printed by argp_help if
Expand Down
4 changes: 2 additions & 2 deletions src/argp-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#if defined(HAVE_MEMPCPY) && !HAVE_MEMPCPY
void* argp_compat_mempcpy(void* out, const void* in, size_t n)
{
memcpy(out, in, n);
return (char*)out + n;
memcpy(out, in, n);
return (char*)out + n;
}
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/argp-eexst.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* Default definition for ARGP_ERR_EXIT_STATUS
Copyright (C) 1997-2016 Free Software Foundation, Inc.
Copyright (C) 1997-2026 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.

Expand All @@ -16,12 +16,13 @@

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
<https://www.gnu.org/licenses/>. */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

/* argp-standalone: use EXIT_FAILURE if <sysexits.h> is not available. */
#if defined(HAVE_SYSEXITS_H) && HAVE_SYSEXITS_H
# include <sysexits.h>
#else
Expand All @@ -33,6 +34,7 @@
/* The exit status that argp will use when exiting due to a parsing error.
If not defined or set by the user program, this defaults to EX_USAGE from
<sysexits.h>. */
/* argp-standalone: use EXIT_FAILURE if <sysexits.h> is not available. */
error_t argp_err_exit_status =
#if defined(HAVE_SYSEXITS_H) && HAVE_SYSEXITS_H
EX_USAGE;
Expand Down
Loading