~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_tempdir.c

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <mystrings/m_string.h>
 
17
#include <m_string.h>
18
18
 
19
19
#define DELIM ':'
20
20
 
21
 
bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
 
21
my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
22
22
{
23
 
  const char *end;
24
 
  char *copy;
 
23
  char *end, *copy;
25
24
  char buff[FN_REFLEN];
 
25
  DBUG_ENTER("init_tmpdir");
 
26
  DBUG_PRINT("enter", ("pathlist: %s", pathlist ? pathlist : "NULL"));
26
27
 
27
28
  pthread_mutex_init(&tmpdir->mutex, MY_MUTEX_INIT_FAST);
28
29
  if (my_init_dynamic_array(&tmpdir->full_list, sizeof(char*), 1, 5))
34
35
    if (!pathlist || !pathlist[0])
35
36
      pathlist=(char*) P_tmpdir;
36
37
  }
37
 
  do {
38
 
    uint32_t length;
39
 
    end= strrchr(pathlist, DELIM);
40
 
    if (end == NULL)
41
 
      end= pathlist+strlen(pathlist);
 
38
  do
 
39
  {
 
40
    uint length;
 
41
    end=strcend(pathlist, DELIM);
42
42
    strmake(buff, pathlist, (uint) (end-pathlist));
43
43
    length= cleanup_dirname(buff, buff);
44
44
    if (!(copy= my_strndup(buff, length, MYF(MY_WME))) ||
45
 
        insert_dynamic(&tmpdir->full_list, (unsigned char*) &copy))
46
 
      return(true);
 
45
        insert_dynamic(&tmpdir->full_list, (uchar*) &copy))
 
46
      DBUG_RETURN(TRUE);
47
47
    pathlist=end+1;
48
 
  } while (*end != '\0');
 
48
  }
 
49
  while (*end);
49
50
  freeze_size(&tmpdir->full_list);
50
51
  tmpdir->list=(char **)tmpdir->full_list.buffer;
51
52
  tmpdir->max=tmpdir->full_list.elements-1;
52
53
  tmpdir->cur=0;
53
 
  return(false);
 
54
  DBUG_RETURN(FALSE);
54
55
 
55
56
err:
56
57
  delete_dynamic(&tmpdir->full_list);           /* Safe to free */
57
58
  pthread_mutex_destroy(&tmpdir->mutex);
58
 
  return(true);
 
59
  DBUG_RETURN(TRUE);
59
60
}
60
61
 
61
62
 
73
74
 
74
75
void free_tmpdir(MY_TMPDIR *tmpdir)
75
76
{
76
 
  uint32_t i;
 
77
  uint i;
77
78
  for (i=0; i<=tmpdir->max; i++)
78
 
    free(tmpdir->list[i]);
 
79
    my_free(tmpdir->list[i], MYF(0));
79
80
  delete_dynamic(&tmpdir->full_list);
80
81
  pthread_mutex_destroy(&tmpdir->mutex);
81
82
}