16 #include "mysys_priv.h"
25 my_bool init_tmpdir(
MY_TMPDIR *tmpdir,
const char *pathlist)
29 DBUG_ENTER(
"init_tmpdir");
30 DBUG_PRINT(
"enter", (
"pathlist: %s", pathlist ? pathlist :
"NULL"));
33 if (my_init_dynamic_array(&tmpdir->full_list,
sizeof(
char*), 1, 5))
35 if (!pathlist || !pathlist[0])
38 pathlist=getenv(
"TMPDIR");
41 pathlist=getenv(
"TEMP");
43 pathlist=getenv(
"TMP");
45 if (!pathlist || !pathlist[0])
46 pathlist=(
char*) P_tmpdir;
51 end=strcend(pathlist, DELIM);
52 strmake(buff, pathlist, (uint) (end-pathlist));
53 length= cleanup_dirname(buff, buff);
54 if (!(copy= my_strndup(buff, length, MYF(MY_WME))) ||
55 insert_dynamic(&tmpdir->full_list, ©))
60 freeze_size(&tmpdir->full_list);
61 tmpdir->list=(
char **)tmpdir->full_list.buffer;
62 tmpdir->max=tmpdir->full_list.elements-1;
67 delete_dynamic(&tmpdir->full_list);
77 return tmpdir->list[0];
79 dir=tmpdir->list[tmpdir->cur];
80 tmpdir->cur= (tmpdir->cur == tmpdir->max) ? 0 : tmpdir->cur+1;
88 if (!tmpdir->full_list.elements)
90 for (i=0; i<=tmpdir->max; i++)
91 my_free(tmpdir->list[i]);
92 delete_dynamic(&tmpdir->full_list);