| 55 | */ |
| 56 | |
| 57 | File create_temp_file(char *to, const char *dir, const char *prefix, |
| 58 | int mode __attribute__((unused)), |
| 59 | myf MyFlags __attribute__((unused))) |
| 60 | { |
| 61 | File file= -1; |
| 62 | #ifdef __WIN__ |
| 63 | TCHAR path_buf[MAX_PATH-14]; |
| 64 | #endif |
| 65 | |
| 66 | DBUG_ENTER("create_temp_file"); |
| 67 | DBUG_PRINT("enter", ("dir: %s, prefix: %s", dir, prefix)); |
| 68 | #if defined (__WIN__) |
| 69 | |
| 70 | /* |
| 71 | Use GetTempPath to determine path for temporary files. |
| 72 | This is because the documentation for GetTempFileName |
| 73 | has the following to say about this parameter: |
| 74 | "If this parameter is NULL, the function fails." |
| 75 | */ |
| 76 | if (!dir) |
| 77 | { |
| 78 | if(GetTempPath(sizeof(path_buf), path_buf) > 0) |
| 79 | dir = path_buf; |
| 80 | } |
| 81 | /* |
| 82 | Use GetTempFileName to generate a unique filename, create |
| 83 | the file and release it's handle |
| 84 | - uses up to the first three letters from prefix |
| 85 | */ |
| 86 | if (GetTempFileName(dir, prefix, 0, to) == 0) |
| 87 | DBUG_RETURN(-1); |
| 88 | |
| 89 | DBUG_PRINT("info", ("name: %s", to)); |
| 90 | |
| 91 | /* |
| 92 | Open the file without the "open only if file doesn't already exist" |
| 93 | since the file has already been created by GetTempFileName |
| 94 | */ |
| 95 | if ((file= my_open(to, (mode & ~O_EXCL), MyFlags)) < 0) |
| 96 | { |
| 97 | /* Open failed, remove the file created by GetTempFileName */ |
| 98 | int tmp= my_errno; |
| 99 | (void) my_delete(to, MYF(0)); |
| 100 | my_errno= tmp; |
| 101 | } |
| 102 | |
| 103 | #elif defined(HAVE_MKSTEMP) |
| 104 | { |
| 105 | char prefix_buff[30]; |
| 106 | uint pfx_len; |
| 107 | File org_file; |
| 108 | |
| 109 | pfx_len= (uint) (strmov(strnmov(prefix_buff, |
| 110 | prefix ? prefix : "tmp.", |
| 111 | sizeof(prefix_buff)-7),"XXXXXX") - |
| 112 | prefix_buff); |
| 113 | if (!dir && ! (dir =getenv("TMPDIR"))) |
| 114 | dir= DEFAULT_TMPDIR; |
no test coverage detected