ucspi-ssl  0.99e
TLS encryption for IPv6 communication
sgetopt.c
Go to the documentation of this file.
1 /* Public domain. */
2 
3 /* sgetopt.c, sgetopt.h: (yet another) improved getopt clone, outer layer
4 D. J. Bernstein, djb@pobox.com.
5 Depends on subgetopt.h, buffer.h.
6 No system requirements.
7 19991219: Switched to buffer.h.
8 19970208: Cleanups.
9 931201: Baseline.
10 No known patent problems.
11 
12 Documentation in sgetopt.3.
13 */
14 
15 #include "buffer.h"
16 #define SGETOPTNOSHORT
17 #include "sgetopt.h"
18 #define SUBGETOPTNOSHORT
19 #include "subgetopt.h"
20 
21 #define getopt sgetoptmine
22 #define optind subgetoptind
23 #define opterr sgetopterr
24 #define optproblem subgetoptproblem
25 #define optprogname sgetoptprogname
26 
27 int opterr = 1;
28 const char *optprogname = 0;
29 
30 int getopt(int argc,char * const *argv,const char *opts)
31 {
32  int c;
33  const char *s;
34 
35  if (!optprogname) {
36  optprogname = *argv;
37  if (!optprogname) optprogname = "";
38  for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1;
39  }
40  c = subgetopt(argc,argv,opts);
41  if (opterr)
42  if (c == '?') {
43  char chp[2]; chp[0] = optproblem; chp[1] = '\n';
45  if (argv[optind] && (optind < argc))
46  buffer_puts(buffer_2,": illegal option -- ");
47  else
48  buffer_puts(buffer_2,": option requires an argument -- ");
49  buffer_put(buffer_2,chp,2);
51  }
52  return c;
53 }
#define optind
Definition: sgetopt.c:22
int buffer_puts(buffer *, const char *)
Definition: buffer_put.c:82
int buffer_put(buffer *, const char *, unsigned int)
Definition: buffer_put.c:49
buffer * buffer_2
Definition: buffer_2.c:7
int subgetopt(int, char *const *, const char *)
#define opterr
Definition: sgetopt.c:23
#define optproblem
Definition: sgetopt.c:24
#define getopt
Definition: sgetopt.c:21
#define optprogname
Definition: sgetopt.c:25
int buffer_flush(buffer *)
Definition: buffer_put.c:25