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 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 /* Copyright (c) 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
33 * This routine is a special case, in that it is aware of
34 * both small and large file interfaces. It must be built
35 * in the small compilation environment.
41 #include <sys/types.h>
52 * open UNIX file name, associate with iop
56 _endopen(const char *name
, const char *type
, FILE *iop
, int largefile
)
58 int oflag
, fd
, fflag
, eflag
, plusflag
, xflag
;
72 oflag
= O_WRONLY
| O_TRUNC
| O_CREAT
;
76 oflag
= O_WRONLY
| O_APPEND
| O_CREAT
;
84 for (echr
= type
+ 1; *echr
!= '\0'; echr
++) {
86 /* UNIX ignores 'b' and treats text and binary the same */
101 /* Subsequent to a mode flag, 'e' indicates O_CLOEXEC */
102 oflag
= oflag
| O_CLOEXEC
;
105 oflag
= (oflag
& ~(O_RDONLY
| O_WRONLY
)) | O_RDWR
;
112 /* select small or large file open based on flag */
114 fd
= open64(name
, oflag
, 0666);
116 fd
= open(name
, oflag
, 0666);
121 /* As long as we make sure _flag stays != 0, we don't need to lock */
124 iop
->_flag
= (iop
->_flag
& ~0377) | fflag
;
126 if (fd
<= _FILE_FD_MAX
) {
128 } else if (_file_set(iop
, fd
, type
) != 0) {
129 /* errno set in _file_set() */
136 if (oflag
== (O_WRONLY
| O_APPEND
| O_CREAT
)) { /* type == "a" */
137 if (lseek64(fd
, (off64_t
)0, SEEK_END
) < (off64_t
)0) {