~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_file.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

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