allow coexistance of N build and AC build.
[tomato.git] / release / src-rt / wl / nas / unix.c
bloba966bab9f8e57bc1650268a9066eff0a37918852
1 /*
2 * Unix support routines
4 * Copyright (C) 2010, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: unix.c 241388 2011-02-18 03:33:22Z stakita $
15 #include <typedefs.h>
16 #include <stdio.h>
17 #include <string.h>
19 void initopt(void);
20 int getopt(int argc, char **argv, char *ostr);
22 /* ****************************************** */
23 /* Some support functionality to match unix */
25 /* get option letter from argument vector */
26 int opterr = 1;
27 int optind = 1;
28 int optopt; /* character checked for validity */
29 char *optarg; /* argument associated with option */
31 #define EMSG ""
32 #define BADCH ('?')
34 static char *place = EMSG; /* option letter processing */
36 void initopt(void)
38 opterr = 1;
39 optind = 1;
40 place = EMSG; /* option letter processing */
43 int getopt(int argc, char **argv, char *ostr)
45 register char *oli; /* option letter list index */
47 if (!*place) {
48 /* update scanning pointer */
49 if (optind >= argc || *(place = argv[optind]) != '-' || !*++place) {
50 return EOF;
52 if (*place == '-') {
53 /* found "--" */
54 ++optind;
55 return EOF;
59 /* option letter okay? */
60 if ((optopt = (int)*place++) == (int)':' ||
61 !(oli = strchr(ostr, optopt))) {
62 if (!*place) {
63 ++optind;
65 printf("illegal option");
66 return BADCH;
68 if (*++oli != ':') {
69 /* don't need argument */
70 optarg = NULL;
71 if (!*place)
72 ++optind;
73 } else {
74 /* need an argument */
75 if (*place) {
76 optarg = place; /* no white space */
77 } else if (argc <= ++optind) {
78 /* no arg */
79 place = EMSG;
80 printf("option requires an argument");
81 return BADCH;
82 } else {
83 optarg = argv[optind]; /* white space */
85 place = EMSG;
86 ++optind;
88 return optopt; /* return option letter */