1 /* Our own convenience getopt. Public Domain. */
5 #if !defined(HAVE_GETOPT) && !defined(HAVE_GETOPT_H)
11 #define GETOPT_ERR(s, c) \
17 (void) write(2, argv[0], strlen(argv[0])); \
18 (void) write(2, s, strlen(s)); \
19 (void) write(2, errbuf, 2); \
23 int getopt(int argc, char * const *argv, const char *optstring)
31 argv[optind][0] != '-' || argv[optind][1] == '\0') {
33 } else if (strcmp(argv[optind], "--") == 0) {
38 optopt = c = argv[optind][sp];
40 if (c == ':' || (cp=strchr(optstring, c)) == NULL) {
41 GETOPT_ERR(": illegal option -- ", c);
42 if (argv[optind][++sp] == '\0') {
50 if (argv[optind][sp+1] != '\0')
51 optarg = &argv[optind++][sp+1];
52 else if (++optind >= argc) {
53 GETOPT_ERR(": option requires an argument -- ", c);
57 optarg = argv[optind++];
60 if (argv[optind][++sp] == '\0') {
69 #endif /* !HAVE_GETOPT && !HAVE_GETOPT_H */
70 #endif /* !SILC_SYMBIAN */