--- pgp/src/getopt.c 2018/04/24 16:38:32 1.1.1.2 +++ pgp/src/getopt.c 2018/04/24 16:42:09 1.1.1.5 @@ -19,19 +19,15 @@ */ #include +#include +#include "getopt.h" /*LINTLIBRARY*/ #ifndef NULL #define NULL 0 #endif #define EOF (-1) -#define ERR(s, c) if(opterr){\ - extern int write();\ - char errbuf[2];\ - errbuf[0] = c; errbuf[1] = '\n';\ - (void) write(2, argv[0], (unsigned)strlen(argv[0]));\ - (void) write(2, s, (unsigned)strlen(s));\ - (void) write(2, errbuf, 2);} +#define ERR(str, chr) (opterr ? fprintf(stderr, "%s%s%c\n", argv[0], str, chr) : 0) int opterr = 1; int optind = 1; @@ -39,9 +35,7 @@ int optopt = 0; char *optarg = 0; int -getopt(argc, argv, opts) -int argc; -char **argv, *opts; +pgp_getopt(int argc, char **argv, char *opts) { static int sp = 1; register int c; @@ -50,10 +44,10 @@ char **argv, *opts; if(sp == 1) { if(optind >= argc || (argv[optind][0] != '+' && argv[optind][0] != '-') || argv[optind][1] == '\0') - return(EOF); + return EOF; else if(strcmp(argv[optind], "--") == 0) { optind++; - return(EOF); + return EOF; } /* '+' for config options, '+' should not be in the opts list */ if (argv[optind][0] == '+') { @@ -68,7 +62,7 @@ char **argv, *opts; optind++; sp = 1; } - return('\0'); + return '\0'; } if(*++cp == ':') { if(argv[optind][sp+1] != '\0') @@ -76,7 +70,7 @@ char **argv, *opts; else if(++optind >= argc) { ERR(": option requires an argument -- ", c); sp = 1; - return('\0'); + return '\0'; } else optarg = argv[optind++]; sp = 1; @@ -87,6 +81,6 @@ char **argv, *opts; } optarg = NULL; } - return(c); + return c; }