2 * Unix support routines
4 * Copyright (C) 2010, Broadcom Corporation
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 $
20 int getopt(int argc
, char **argv
, char *ostr
);
22 /* ****************************************** */
23 /* Some support functionality to match unix */
25 /* get option letter from argument vector */
28 int optopt
; /* character checked for validity */
29 char *optarg
; /* argument associated with option */
34 static char *place
= EMSG
; /* option letter processing */
40 place
= EMSG
; /* option letter processing */
43 int getopt(int argc
, char **argv
, char *ostr
)
45 register char *oli
; /* option letter list index */
48 /* update scanning pointer */
49 if (optind
>= argc
|| *(place
= argv
[optind
]) != '-' || !*++place
) {
59 /* option letter okay? */
60 if ((optopt
= (int)*place
++) == (int)':' ||
61 !(oli
= strchr(ostr
, optopt
))) {
65 printf("illegal option");
69 /* don't need argument */
74 /* need an argument */
76 optarg
= place
; /* no white space */
77 } else if (argc
<= ++optind
) {
80 printf("option requires an argument");
83 optarg
= argv
[optind
]; /* white space */
88 return optopt
; /* return option letter */