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 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
42 #include <sys/types.h>
45 #include <sys/fcntl.h>
50 /* Final argument to _endopen depends on build environment */
51 #define ALWAYS_LARGE_OPEN 1
52 #define LARGE_OPEN (_FILE_OFFSET_BITS == 64)
55 _endopen(const char *file
, const char *mode
, FILE *iop
, int largefile
)
59 if (iop
== NULL
|| file
== NULL
|| file
[0] == '\0')
61 plus
= (mode
[1] == '+');
64 oflag
= (plus
? O_RDWR
: O_WRONLY
) | O_TRUNC
| O_CREAT
;
67 oflag
= (plus
? O_RDWR
: O_WRONLY
) | O_CREAT
;
70 oflag
= plus
? O_RDWR
: O_RDONLY
;
77 fd
= open64(file
, oflag
, 0666); /* mapped to open() for V9 */
79 fd
= open(file
, oflag
, 0666);
87 if (fd
<= _FILE_FD_MAX
) {
89 } else if (_file_set(iop
, fd
, mode
) != 0) {
90 /* errno set in _file_set() */
95 iop
->_flag
= plus
? _IORW
: (mode
[0] == 'r') ? _IOREAD
: _IOWRT
;
97 if ((lseek64(fd
, 0L, SEEK_END
)) < 0) {
102 iop
->_base
= iop
->_ptr
= NULL
;
104 * Sys5 does not support _bufsiz
112 fopen(const char *file
, const char *mode
)
118 rc
= _endopen(file
, mode
, iop
, LARGE_OPEN
);
119 if (rc
== NULL
&& iop
!= NULL
)
120 iop
->_flag
= 0; /* release iop */
125 * For _LP64, all fopen() calls are 64-bit calls, i.e., open64() system call.
126 * There should not be fopen64() calls.
127 * Similar for freopen64().
131 fopen64(const char *file
, const char *mode
)
137 rc
= _endopen(file
, mode
, iop
, ALWAYS_LARGE_OPEN
);
138 if (rc
== NULL
&& iop
!= NULL
)
139 iop
->_flag
= 0; /* release iop */
145 freopen(const char *file
, const char *mode
, FILE *iop
)
147 (void) fclose(iop
); /* doesn't matter if this fails */
148 return (_endopen(file
, mode
, iop
, LARGE_OPEN
));
153 freopen64(const char *file
, const char *mode
, FILE *iop
)
155 (void) fclose(iop
); /* doesn't matter if this fails */
156 return (_endopen(file
, mode
, iop
, ALWAYS_LARGE_OPEN
));