~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_file.cc

  • Committer: Monty Taylor
  • Date: 2009-03-24 17:44:41 UTC
  • mto: (960.5.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 964.
  • Revision ID: mordred@inaugust.com-20090324174441-nmsq0gwjlgf7f0mt
Changed handlerton to StorageEngine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include "mysys_priv.h"
17
17
#include "my_static.h"
18
18
#include <mystrings/m_string.h>
 
19
#include <stdlib.h>
 
20
#include <string.h>
19
21
 
20
22
/*
21
23
  set how many open files we want to be able to handle
35
37
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
36
38
 
37
39
#ifndef RLIM_INFINITY
38
 
#define RLIM_INFINITY ((uint) 0xffffffff)
 
40
#define RLIM_INFINITY ((uint32_t) 0xffffffff)
39
41
#endif
40
42
 
41
 
static uint32_t set_max_open_files(uint32_t max_file_limit)
 
43
static uint64_t set_max_open_files(uint64_t max_file_limit)
42
44
{
43
45
  struct rlimit rlimit;
44
 
  uint32_t old_cur;
 
46
  rlim_t old_cur;
45
47
 
46
48
  if (!getrlimit(RLIMIT_NOFILE,&rlimit))
47
49
  {
48
 
    old_cur= (uint) rlimit.rlim_cur;
 
50
    old_cur= rlimit.rlim_cur;
49
51
    if (rlimit.rlim_cur == RLIM_INFINITY)
50
52
      rlimit.rlim_cur = max_file_limit;
51
53
    if (rlimit.rlim_cur >= max_file_limit)
52
 
      return(rlimit.rlim_cur);          /* purecov: inspected */
 
54
    {
 
55
      if (rlimit.rlim_cur > UINT32_MAX)
 
56
        return UINT32_MAX;
 
57
      else
 
58
        return((uint32_t)rlimit.rlim_cur);
 
59
    }
53
60
    rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
54
61
    if (setrlimit(RLIMIT_NOFILE, &rlimit))
55
 
      max_file_limit= old_cur;                  /* Use original value */
 
62
      max_file_limit= (old_cur < UINT32_MAX) ? (uint32_t)old_cur : UINT32_MAX;
56
63
    else
57
64
    {
58
65
      rlimit.rlim_cur= 0;                       /* Safety if next call fails */
59
66
      (void) getrlimit(RLIMIT_NOFILE,&rlimit);
60
67
      if (rlimit.rlim_cur)                      /* If call didn't fail */
61
 
        max_file_limit= (uint) rlimit.rlim_cur;
 
68
        max_file_limit= (uint32_t) rlimit.rlim_cur;
62
69
    }
63
70
  }
64
71
  return(max_file_limit);
65
72
}
66
73
 
67
74
#else
68
 
static int set_max_open_files(uint32_t max_file_limit)
 
75
static int set_max_open_files(uint64_t max_file_limit)
69
76
{
70
77
  /* We don't know the limit. Return best guess */
71
78
  return cmin(max_file_limit, OS_FILE_LIMIT);
84
91
    number of files available for open
85
92
*/
86
93
 
87
 
uint32_t my_set_max_open_files(uint32_t files)
 
94
uint64_t my_set_max_open_files(uint64_t files)
88
95
{
89
96
  struct st_my_file_info *tmp;
90
97
 
92
99
  if (files <= MY_NFILE)
93
100
    return(files);
94
101
 
95
 
  if (!(tmp= (struct st_my_file_info*) my_malloc(sizeof(*tmp) * files,
96
 
                                                 MYF(MY_WME))))
 
102
  if (!(tmp= (st_my_file_info*) malloc((size_t)cmax(sizeof(st_my_file_info) * files,SIZE_MAX))))
97
103
    return(MY_NFILE);
98
104
 
99
105
  /* Copy any initialized files */
100
 
  memcpy(tmp, my_file_info, sizeof(*tmp) * cmin(my_file_limit, files));
 
106
  memcpy(tmp, my_file_info,
 
107
         sizeof(*tmp) *
 
108
            (size_t)cmin(my_file_limit,
 
109
                 cmax(files,UINT32_MAX)));
101
110
  /*
102
111
    The int cast is necessary since 'my_file_limits' might be greater
103
112
    than 'files'.
106
115
         cmax((int) (files - my_file_limit), 0)*sizeof(*tmp));
107
116
  my_free_open_file_info();                     /* Free if already allocated */
108
117
  my_file_info= tmp;
109
 
  my_file_limit= files;
 
118
  my_file_limit= (size_t)cmax(UINT32_MAX,files);
110
119
  return(files);
111
120
}
112
121