Mail Archives: djgpp-workers/2001/05/28/13:05:32
getopt currently doesn't follow the posix standard because it returns '?'
when a missing argument is encountered instead of ':'. The patch below fixes
this:
Index: getopt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/getopt.c,v
retrieving revision 1.1
diff -c -p -r1.1 getopt.c
*** getopt.c 1995/06/13 04:47:58 1.1
--- getopt.c 2001/05/28 17:01:43
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
***************
*** 8,14 ****
int opterr = 1, optind = 1, optopt = 0;
char *optarg = 0;
! #define BADCH (int)'?'
#define EMSG ""
int
--- 9,16 ----
int opterr = 1, optind = 1, optopt = 0;
char *optarg = 0;
! #define BADOPT (int)'?'
! #define BADARG (int)':'
#define EMSG ""
int
*************** getopt(int nargc, char *const nargv[], c
*** 52,58 ****
++p;
fprintf(stderr, "%s: illegal option -- %c\n", p, optopt);
}
! return BADCH;
}
if (*++oli != ':')
{ /* don't need argument */
--- 54,60 ----
++p;
fprintf(stderr, "%s: illegal option -- %c\n", p, optopt);
}
! return BADOPT;
}
if (*++oli != ':')
{ /* don't need argument */
*************** getopt(int nargc, char *const nargv[], c
*** 74,80 ****
if (opterr)
fprintf(stderr, "%s: option requires an argument -- %c\n",
p, optopt);
! return BADCH;
}
else /* white space */
optarg = nargv[optind];
--- 76,82 ----
if (opterr)
fprintf(stderr, "%s: option requires an argument -- %c\n",
p, optopt);
! return BADARG;
}
else /* white space */
optarg = nargv[optind];
- Raw text -