4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.7 */
41 /* incr doesn't include a null termination */
42 #define ALLOC_BUFMEM(buf, size, incr) \
44 size_t len = strlen(buf); \
45 if ((len + incr) >= size) { \
46 size = len + incr + 1; \
47 if ((buf = (char *)realloc((void *)buf, size)) \
50 gettext("getopt: Out of memory\n"), stderr); \
57 main(int argc
, char **argv
)
66 (void) setlocale(LC_ALL
, "");
67 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
68 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
70 (void) textdomain(TEXT_DOMAIN
);
73 (void) fputs(gettext("usage: getopt legal-args $*\n"), stderr
);
83 if ((outstr
= (char *)malloc(bufsize
)) == NULL
) {
84 (void) fputs(gettext("getopt: Out of memory\n"), stderr
);
89 while ((c
= getopt(argc
, argv
, goarg
)) != EOF
) {
100 /* If the buffer is full, expand it as appropriate */
101 ALLOC_BUFMEM(outstr
, bufsize
, 3);
103 (void) strcat(outstr
, tmpstr
);
105 if (*(strchr(goarg
, c
)+1) == ':') {
106 ALLOC_BUFMEM(outstr
, bufsize
, strlen(optarg
)+1)
107 (void) strcat(outstr
, optarg
);
108 (void) strcat(outstr
, " ");
116 ALLOC_BUFMEM(outstr
, bufsize
, 3)
117 (void) strcat(outstr
, "-- ");
118 while (optind
< argc
) {
119 ALLOC_BUFMEM(outstr
, bufsize
, strlen(argv
[optind
])+1)
120 (void) strcat(outstr
, argv
[optind
++]);
121 (void) strcat(outstr
, " ");
124 (void) printf("%s\n", outstr
);