2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2006-2009 Oracle. All rights reserved.
16 * PUBLIC: #ifndef HAVE_FOPEN
17 * PUBLIC: FILE *fopen __P((const char *, const char *));
22 const char *filename, *mode;
27 int f_exists, ret, update_flag;
30 * Note: files are created with read/write privilege.
32 * Upon successful completion, fopen() returns a pointer to the
33 * object controlling the stream. Otherwise, NULL is returned,
34 * and errno is set to indicate the error.
36 DB_ASSERT(NULL, filename != NULL && mode != NULL);
38 FILE_MANAGER_CREATE(NULL, pIFileMgr, ret);
45 * The argument mode points to a string beginning with one of the
46 * following sequences:
48 * Open file for reading.
50 * Truncate to zero length or create file for writing.
52 * Append; open or create file for writing at end-of-file.
54 * Open file for update (reading and writing).
56 * Truncate to zero length or create file for update.
58 * Append; open or create file for update, writing at end-of-file.
61 update_flag = strchr(mode, '+') ? 1 : 0;
63 case 'a': /* append mode */
64 flags = _OFM_APPEND | _OFM_CREATE;
66 case 'r': /* read mode */
67 flags = update_flag ? _OFM_READWRITE : _OFM_READ;
69 case 'w': /* write mode */
70 flags = _OFM_READWRITE | _OFM_CREATE;
74 f_exists = IFILEMGR_Test(pIFileMgr, filename) == SUCCESS ? 1 : 0;
76 LF_CLR(_OFM_CREATE); /* Clear _OFM_CREATE. */
78 LF_CLR(~_OFM_CREATE); /* Leave only _OFM_CREATE. */
80 if ((pIFile = IFILEMGR_OpenFile(
81 pIFileMgr, filename, (OpenFileMode)flags)) == NULL) {
82 FILE_MANAGER_ERR(NULL,
83 pIFileMgr, filename, "IFILEMGR_OpenFile", ret);
87 IFILEMGR_Release(pIFileMgr);