2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1998-2009 Oracle. All rights reserved.
15 * Open a file, using BREW open flags.
18 __os_openhandle(env, name, flags, mode, fhpp)
31 FILE_MANAGER_CREATE(env, pIFileMgr, ret);
36 * Allocate the file handle and copy the file name. We generally only
37 * use the name for verbose or error messages, but on systems where we
38 * can't unlink temporary files immediately, we use the name to unlink
39 * the temporary file when the file handle is closed.
41 if ((ret = __os_calloc(env, 1, sizeof(DB_FH), &fhp)) != 0)
43 if ((ret = __os_strdup(env, name, &fhp->name)) != 0)
47 * Test the file before opening. BREW doesn't want to see the
48 * _OFM_CREATE flag if the file already exists, and it doesn't
49 * want to see any other flag if the file doesn't exist.
51 f_exists = IFILEMGR_Test(pIFileMgr, name) == SUCCESS ? 1 : 0;
53 LF_CLR(_OFM_CREATE); /* Clear _OFM_CREATE. */
55 LF_CLR(~_OFM_CREATE); /* Leave only _OFM_CREATE. */
58 IFILEMGR_OpenFile(pIFileMgr, name, (OpenFileMode)flags)) == NULL) {
60 pIFileMgr, name, "IFILEMGR_OpenFile", ret);
65 IFILEMGR_Release(pIFileMgr);
67 F_SET(fhp, DB_FH_OPENED);
71 err: if (pIFile != NULL)
72 IFILE_Release(pIFile);
73 IFILEMGR_Release(pIFileMgr);
76 (void)__os_closehandle(env, fhp);
85 __os_closehandle(env, fhp)
89 /* Discard any underlying system file reference. */
90 if (F_ISSET(fhp, DB_FH_OPENED))
91 (void)IFILE_Release(fhp->ifp);
93 /* Unlink the file if we haven't already done so. */
94 if (F_ISSET(fhp, DB_FH_UNLINK))
95 (void)__os_unlink(env, fhp->name, 0);
97 if (fhp->name != NULL)
98 __os_free(env, fhp->name);