4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
35 #include <stdio_ext.h>
40 #define _FILE_FD_MAX 255
43 * This 32-bit only preloadable library enables extended fd FILE's.
46 #pragma init(init_STDIO_bad_fd)
49 init_STDIO_bad_fd(void)
51 int action
= -1; /* default signal */
52 int closed_fd
= -1; /* default fd */
58 * user specified badfd
60 if ((ptr
= getenv("_STDIO_BADFD")) != NULL
) {
61 closed_fd
= atoi(ptr
);
62 if (closed_fd
< 3 || closed_fd
> _FILE_FD_MAX
) {
63 (void) fprintf(stderr
, "File descriptor must be"
64 " in the range 3-%d inclusive.\n", _FILE_FD_MAX
);
70 * user specified action
72 if ((ptr
= getenv("_STDIO_BADFD_SIGNAL")) != NULL
) {
73 /* accept numbers or symbolic names */
74 if (strncmp(ptr
, "SIG", 3) == 0) /* begins with "SIG"? */
76 retval
= str2sig(ptr
, &signal
);
78 (void) fprintf(stderr
,
79 "Invalid signal name or number.\n");
85 if ((closed_fd
= enable_extended_FILE_stdio(closed_fd
, action
)) == -1) {
86 perror("enable_extended_FILE_stdio(3C)");