~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_file.c

  • Committer: Monty Taylor
  • Date: 2008-08-16 21:06:22 UTC
  • Revision ID: monty@inaugust.com-20080816210622-zpnn13unyinqzn72
Updated po files.

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>
21
19
 
22
20
/*
23
21
  set how many open files we want to be able to handle
40
38
#define RLIM_INFINITY ((uint) 0xffffffff)
41
39
#endif
42
40
 
43
 
static uint32_t set_max_open_files(uint32_t max_file_limit)
 
41
static uint set_max_open_files(uint max_file_limit)
44
42
{
45
43
  struct rlimit rlimit;
46
 
  rlim_t old_cur;
 
44
  uint old_cur;
47
45
 
48
46
  if (!getrlimit(RLIMIT_NOFILE,&rlimit))
49
47
  {
50
 
    old_cur= rlimit.rlim_cur;
 
48
    old_cur= (uint) rlimit.rlim_cur;
51
49
    if (rlimit.rlim_cur == RLIM_INFINITY)
52
50
      rlimit.rlim_cur = max_file_limit;
53
51
    if (rlimit.rlim_cur >= max_file_limit)
54
 
    {
55
 
      if (rlimit.rlim_cur > UINT32_MAX)
56
 
        return UINT32_MAX;
57
 
      else
58
 
        return((uint32_t)rlimit.rlim_cur);
59
 
    }
 
52
      return(rlimit.rlim_cur);          /* purecov: inspected */
60
53
    rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
61
54
    if (setrlimit(RLIMIT_NOFILE, &rlimit))
62
 
      max_file_limit= (old_cur < UINT32_MAX) ? (uint32_t)old_cur : UINT32_MAX;
 
55
      max_file_limit= old_cur;                  /* Use original value */
63
56
    else
64
57
    {
65
58
      rlimit.rlim_cur= 0;                       /* Safety if next call fails */
66
59
      (void) getrlimit(RLIMIT_NOFILE,&rlimit);
67
60
      if (rlimit.rlim_cur)                      /* If call didn't fail */
68
 
        max_file_limit= (uint32_t) rlimit.rlim_cur;
 
61
        max_file_limit= (uint) rlimit.rlim_cur;
69
62
    }
70
63
  }
71
64
  return(max_file_limit);
72
65
}
73
66
 
74
67
#else
75
 
static int set_max_open_files(uint32_t max_file_limit)
 
68
static int set_max_open_files(uint max_file_limit)
76
69
{
77
70
  /* We don't know the limit. Return best guess */
78
 
  return cmin(max_file_limit, OS_FILE_LIMIT);
 
71
  return min(max_file_limit, OS_FILE_LIMIT);
79
72
}
80
73
#endif
81
74
 
91
84
    number of files available for open
92
85
*/
93
86
 
94
 
uint32_t my_set_max_open_files(uint32_t files)
 
87
uint my_set_max_open_files(uint files)
95
88
{
96
89
  struct st_my_file_info *tmp;
97
90
 
98
 
  files= set_max_open_files(cmin(files, OS_FILE_LIMIT));
 
91
  files= set_max_open_files(min(files, OS_FILE_LIMIT));
99
92
  if (files <= MY_NFILE)
100
93
    return(files);
101
94
 
102
 
  if (!(tmp= (st_my_file_info*) malloc(sizeof(st_my_file_info) * files)))
 
95
  if (!(tmp= (struct st_my_file_info*) my_malloc(sizeof(*tmp) * files,
 
96
                                                 MYF(MY_WME))))
103
97
    return(MY_NFILE);
104
98
 
105
99
  /* Copy any initialized files */
106
 
  memcpy(tmp, my_file_info, sizeof(*tmp) * cmin(my_file_limit, files));
 
100
  memcpy(tmp, my_file_info, sizeof(*tmp) * min(my_file_limit, files));
107
101
  /*
108
102
    The int cast is necessary since 'my_file_limits' might be greater
109
103
    than 'files'.
110
104
  */
111
105
  memset(tmp + my_file_limit, 0,
112
 
         cmax((int) (files - my_file_limit), 0)*sizeof(*tmp));
 
106
         max((int) (files - my_file_limit), 0)*sizeof(*tmp));
113
107
  my_free_open_file_info();                     /* Free if already allocated */
114
108
  my_file_info= tmp;
115
109
  my_file_limit= files;
124
118
    /* Copy data back for my_print_open_files */
125
119
    memcpy(my_file_info_default, my_file_info,
126
120
           sizeof(*my_file_info_default)* MY_NFILE);
127
 
    free((char*) my_file_info);
 
121
    my_free((char*) my_file_info, MYF(0));
128
122
    my_file_info= my_file_info_default;
129
123
    my_file_limit= MY_NFILE;
130
124
  }