commit 9620ff2d6f16ccd16e027bcb5ada961d9d0b8fc0
parent 54b77bb078333ecf576a6b59ba9b26354d855d09
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Sat, 21 Jan 2023 15:25:30 +0000
QoL: subgetopt should return ? on --long
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat:
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/libstddjb/subgetopt.c b/src/libstddjb/subgetopt.c
@@ -16,19 +16,18 @@ int subgetopt_r (int argc, char const *const *argv, char const *opts, subgetopt
if (!o->pos)
{
+ char c ;
if (argv[o->ind][0] != '-') return -1 ;
- else
+ o->pos++ ;
+ c = argv[o->ind][1] ;
+ if (c == '-')
{
- char c ;
- o->pos++ ;
- c = argv[o->ind][1] ;
- if (c == '-') o->ind++ ;
- if (!c || (c == '-'))
- {
- o->pos = 0 ;
- return -1 ;
- }
+ if (argv[o->ind][2]) return o->problem = '-', '?' ;
+ o->ind++ ;
+ o->pos = 0 ;
+ return -1 ;
}
+ if (!c || c == '-') return o->pos = 0, -1 ;
}
{
char c = argv[o->ind][o->pos++] ;