8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / stdio / common / fdopen.c
bloba225c02b45d34886b63d8bfd9386222f8ca041f6
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.4 */
32 /*LINTLIBRARY*/
34 * Unix routine to do an "fopen" on file descriptor
35 * The mode has to be repeated because you can't query its
36 * status
39 #include <stdio.h>
40 #include <sys/errno.h>
42 extern int errno;
43 extern long lseek();
44 extern FILE *_findiop();
46 FILE *
47 fdopen(fd, mode)
48 int fd;
49 register char *mode;
51 static int nofile = -1;
52 register FILE *iop;
54 if(nofile < 0)
55 nofile = getdtablesize();
57 if(fd < 0 || fd >= nofile) {
58 errno = EINVAL;
59 return(NULL);
62 if((iop = _findiop()) == NULL)
63 return(NULL);
65 iop->_cnt = 0;
66 iop->_file = fd;
67 iop->_base = iop->_ptr = NULL;
68 iop->_bufsiz = 0;
69 switch(*mode) {
71 case 'r':
72 iop->_flag = _IOREAD;
73 break;
74 case 'a':
75 (void) lseek(fd, 0L, 2);
76 /* No break */
77 case 'w':
78 iop->_flag = _IOWRT;
79 break;
80 default:
81 errno = EINVAL;
82 return(NULL);
85 if(mode[1] == '+')
86 iop->_flag = _IORW;
88 return(iop);