2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid[] = "@(#)os_open.c 10.19 (Sleepycat) 10/28/97";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
26 * Open a file descriptor.
28 * PUBLIC: int __db_open __P((const char *, int, int, int, int *));
31 __db_open(name, arg_flags, ok_flags, mode, fdp)
33 int arg_flags, ok_flags, mode, *fdp;
37 if (arg_flags & ~ok_flags)
41 if (arg_flags & DB_CREATE)
44 if (arg_flags & DB_EXCL)
47 if (arg_flags & DB_RDONLY)
54 if (arg_flags & DB_SEQUENTIAL)
55 flags |= _O_SEQUENTIAL;
59 if (arg_flags & DB_TEMPORARY)
60 flags |= _O_TEMPORARY;
62 flags |= O_BINARY | O_NOINHERIT;
65 if (arg_flags & DB_TRUNCATE)
69 if ((fd = __os_open(name, flags, mode)) == -1)
73 /* Delete any temporary file; done for Win32 by _O_TEMPORARY. */
74 if (arg_flags & DB_TEMPORARY)
75 (void)__os_unlink(name);
78 #if !defined(_WIN32) && !defined(macintosh)
80 * Deny access to any child process; done for Win32 by O_NOINHERIT,
81 * MacOS has neither child processes nor fd inheritance.
83 if (fcntl(fd, F_SETFD, 1) == -1) {
96 * Close a file descriptor.
98 * PUBLIC: int __db_close __P((int));
104 return (__os_close(fd) ? errno : 0);