1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
30 #if !defined(open) || !defined(_ast_O_LOCAL)
38 extern int open(const char*, int, ...);
48 _ast_open(const char* path
, int op
, ...)
58 mode
= (op
& O_CREAT
) ? va_arg(ap
, int) : S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
|S_IWOTH
;
60 if (op
& ~(_ast_O_LOCAL
-1))
68 if ((op
& O_EXCL
) && !access(path
, F_OK
))
73 if ((fd
= creat(path
, (op
& O_EXCL
) ? 0 : mode
)) < 0)
77 if (fstat(fd
, &st
) || (st
.st_mode
& S_IPERM
))
84 if (mode
&& fchmod(fd
, mode
))
86 if (mode
&& chmod(path
, mode
))
90 if ((op
& O_ACCMODE
) == O_RDWR
)
93 op
&= ~(O_CREAT
|O_TRUNC
);
97 else if ((fd
= open(path
, op
& (_ast_O_LOCAL
-1), mode
)) < 0)
106 else if ((op
& O_APPEND
) && lseek(fd
, 0L, SEEK_END
) == -1L)
109 if ((op
& O_NOCTTY
) && ioctl(fd
, TIOCNOTTY
, 0))
115 else fd
= open(path
, op
, mode
);