| 34 | |
| 35 | |
| 36 | File my_create(const char *FileName, int CreateFlags, int access_flags, |
| 37 | myf MyFlags) |
| 38 | { |
| 39 | int fd, rc; |
| 40 | DBUG_ENTER("my_create"); |
| 41 | DBUG_PRINT("my",("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %d", |
| 42 | FileName, CreateFlags, access_flags, MyFlags)); |
| 43 | #if defined(_WIN32) |
| 44 | fd= my_win_open(FileName, access_flags | O_CREAT); |
| 45 | #else |
| 46 | fd= open((char *) FileName, access_flags | O_CREAT, |
| 47 | CreateFlags ? CreateFlags : my_umask); |
| 48 | #endif |
| 49 | |
| 50 | if ((MyFlags & MY_SYNC_DIR) && (fd >=0) && |
| 51 | my_sync_dir_by_file(FileName, MyFlags)) |
| 52 | { |
| 53 | my_close(fd, MyFlags); |
| 54 | fd= -1; |
| 55 | } |
| 56 | |
| 57 | rc= my_register_filename(fd, FileName, FILE_BY_CREATE, |
| 58 | EE_CANTCREATEFILE, MyFlags); |
| 59 | /* |
| 60 | my_register_filename() may fail on some platforms even if the call to |
| 61 | *open() above succeeds. In this case, don't leave the stale file because |
| 62 | callers assume the file to not exist if my_create() fails, so they don't |
| 63 | do any cleanups. |
| 64 | */ |
| 65 | if (unlikely(fd >= 0 && rc < 0)) |
| 66 | { |
| 67 | int tmp= my_errno; |
| 68 | my_close(fd, MyFlags); |
| 69 | my_delete(FileName, MyFlags); |
| 70 | my_errno= tmp; |
| 71 | } |
| 72 | |
| 73 | DBUG_RETURN(rc); |
| 74 | } /* my_create */ |
no test coverage detected