| 23 | #endif |
| 24 | |
| 25 | my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist) |
| 26 | { |
| 27 | char *end, *copy; |
| 28 | char buff[FN_REFLEN]; |
| 29 | DBUG_ENTER("init_tmpdir"); |
| 30 | DBUG_PRINT("enter", ("pathlist: %s", pathlist ? pathlist : "NULL")); |
| 31 | |
| 32 | mysql_mutex_init(key_TMPDIR_mutex, &tmpdir->mutex, MY_MUTEX_INIT_FAST); |
| 33 | if (my_init_dynamic_array(key_memory_MY_TMPDIR_full_list, &tmpdir->full_list, |
| 34 | sizeof(char*), 1, 5, MYF(0))) |
| 35 | goto err; |
| 36 | if (!pathlist || !pathlist[0]) |
| 37 | { |
| 38 | /* Get default temporary directory */ |
| 39 | pathlist=getenv("TMPDIR"); /* Use this if possible */ |
| 40 | #if defined(_WIN32) |
| 41 | if (!pathlist) |
| 42 | pathlist=getenv("TEMP"); |
| 43 | if (!pathlist) |
| 44 | pathlist=getenv("TMP"); |
| 45 | #endif |
| 46 | if (!pathlist || !pathlist[0]) |
| 47 | pathlist= DEFAULT_TMPDIR; |
| 48 | } |
| 49 | do |
| 50 | { |
| 51 | size_t length; |
| 52 | end=strcend(pathlist, DELIM); |
| 53 | strmake(buff, pathlist, (uint) (end-pathlist)); |
| 54 | length= cleanup_dirname(buff, buff); |
| 55 | if (!(copy= my_strndup(key_memory_MY_TMPDIR_full_list, buff, length, MYF(MY_WME))) || |
| 56 | insert_dynamic(&tmpdir->full_list, (uchar*) ©)) |
| 57 | DBUG_RETURN(TRUE); |
| 58 | pathlist=end+1; |
| 59 | } |
| 60 | while (*end); |
| 61 | freeze_size(&tmpdir->full_list); |
| 62 | tmpdir->list=(char **)tmpdir->full_list.buffer; |
| 63 | tmpdir->max=tmpdir->full_list.elements-1; |
| 64 | tmpdir->cur=0; |
| 65 | DBUG_RETURN(FALSE); |
| 66 | |
| 67 | err: |
| 68 | delete_dynamic(&tmpdir->full_list); /* Safe to free */ |
| 69 | mysql_mutex_destroy(&tmpdir->mutex); |
| 70 | DBUG_RETURN(TRUE); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | char *my_tmpdir(MY_TMPDIR *tmpdir) |
no test coverage detected