8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / extendedFILE / common / extendedFILE.c
blob68397bae348fef550b4a87fe912d61a10debe520
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <limits.h>
33 #include <signal.h>
34 #include <stdio.h>
35 #include <stdio_ext.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.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)
48 void
49 init_STDIO_bad_fd(void)
51 int action = -1; /* default signal */
52 int closed_fd = -1; /* default fd */
53 char *ptr;
54 int signal;
55 int retval;
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);
65 exit(1);
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"? */
75 ptr = ptr + 3;
76 retval = str2sig(ptr, &signal);
77 if (retval == -1) {
78 (void) fprintf(stderr,
79 "Invalid signal name or number.\n");
80 exit(1);
82 action = signal;
85 if ((closed_fd = enable_extended_FILE_stdio(closed_fd, action)) == -1) {
86 perror("enable_extended_FILE_stdio(3C)");
87 exit(1);