~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_file.c

More cleanup, this time libmysql_r goes to the bitbucket

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