2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)os_open.c 10.33 (Sleepycat) 10/12/98";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
28 * Open a file descriptor.
30 * PUBLIC: int __db_open __P((const char *, u_int32_t, u_int32_t, int, int *));
33 __db_open(name
, arg_flags
, ok_flags
, mode
, fdp
)
35 u_int32_t arg_flags
, ok_flags
;
38 #if !defined(_WIN32) && defined(HAVE_SIGFILLSET)
43 if (arg_flags
& ~ok_flags
)
49 * DB requires the semantic that two files opened at the same time
50 * with O_CREAT and O_EXCL set will return failure in at least one.
52 if (arg_flags
& DB_CREATE
)
55 if (arg_flags
& DB_EXCL
)
58 if (arg_flags
& DB_RDONLY
)
63 #if defined(_WIN32) || defined(WIN16)
65 if (arg_flags
& DB_SEQUENTIAL
)
66 flags
|= _O_SEQUENTIAL
;
70 if (arg_flags
& DB_TEMPORARY
)
71 flags
|= _O_TEMPORARY
;
73 flags
|= O_BINARY
| O_NOINHERIT
;
76 if (arg_flags
& DB_TRUNCATE
)
79 #if !defined(_WIN32) && defined(HAVE_SIGFILLSET)
81 * We block every signal we can get our hands on so that the temporary
82 * file isn't left around if we're interrupted at the wrong time. Of
83 * course, if we drop core in-between the calls we'll hang forever, but
84 * that's probably okay. ;-)
86 if (arg_flags
& DB_TEMPORARY
) {
87 (void)sigfillset(&set
);
88 (void)sigprocmask(SIG_BLOCK
, &set
, &oset
);
93 if ((ret
= __os_open(name
, flags
, mode
, fdp
)) != 0)
97 /* Delete any temporary file; done for Win32 by _O_TEMPORARY. */
98 if (arg_flags
& DB_TEMPORARY
) {
99 (void)__os_unlink(name
);
100 #if defined(HAVE_SIGFILLSET)
101 (void)sigprocmask(SIG_SETMASK
, &oset
, NULL
);
106 #if !defined(_WIN32) && !defined(WIN16) && !defined(VMS)
108 * Deny access to any child process.
109 * VMS: does not have fd inheritance.
110 * Win32: done by O_NOINHERIT.
112 if (fcntl(*fdp
, F_SETFD
, 1) == -1) {
115 (void)__os_close(*fdp
);
126 * PUBLIC: int __os_open __P((const char *, int, int, int *));
129 __os_open(name
, flags
, mode
, fdp
)
131 int flags
, mode
, *fdp
;
133 *fdp
= __db_jump
.j_open
!= NULL
?
134 __db_jump
.j_open(name
, flags
, mode
) : open(name
, flags
, mode
);
135 return (*fdp
== -1 ? errno
: 0);
140 * Close a file descriptor.
142 * PUBLIC: int __os_close __P((int));
150 ret
= __db_jump
.j_close
!= NULL
? __db_jump
.j_close(fd
) : close(fd
);
151 return (ret
== 0 ? 0 : errno
);