~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_init.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 08:00:16 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713080016-8qtjv9ypt42azzr6
CRC32() as UDF

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 <mysys/mysys_err.h>
19
 
#include <mystrings/m_string.h>
20
 
#include <mystrings/m_ctype.h>
21
 
#include <stdio.h>
22
 
#include <stdlib.h>
 
18
#include "mysys_err.h"
 
19
#include <m_string.h>
 
20
#include <m_ctype.h>
 
21
#include <signal.h>
23
22
 
24
 
bool my_init_done= 0;
 
23
my_bool my_init_done= 0;
25
24
uint    mysys_usage_id= 0;              /* Incremented for each my_init() */
 
25
ulong   my_thread_stack_size= 65536;
26
26
 
27
 
static uint32_t atoi_octal(const char *str)
 
27
static ulong atoi_octal(const char *str)
28
28
{
29
29
  long int tmp;
30
 
  while (*str && my_isspace(&my_charset_utf8_general_ci, *str))
 
30
  while (*str && my_isspace(&my_charset_latin1, *str))
31
31
    str++;
32
32
  str2int(str,
33
33
          (*str == '0' ? 8 : 10),       /* Octalt or decimalt */
34
34
          0, INT_MAX, &tmp);
35
 
  return (uint32_t) tmp;
 
35
  return (ulong) tmp;
36
36
}
37
37
 
38
38
 
47
47
    1  Couldn't initialize environment
48
48
*/
49
49
 
50
 
bool my_init(void)
 
50
my_bool my_init(void)
51
51
{
52
52
  char * str;
53
53
  if (my_init_done)
64
64
  fastmutex_global_init();              /* Must be called early */
65
65
#endif
66
66
#if defined(HAVE_PTHREAD_INIT)
67
 
  pthread_init();
 
67
  pthread_init();                       /* Must be called before DBUG_ENTER */
68
68
#endif
69
69
  if (my_thread_global_init())
70
70
    return 1;
71
71
  sigfillset(&my_signals);              /* signals blocked by mf_brkhant */
72
72
  {
 
73
    DBUG_ENTER("my_init");
 
74
    DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
73
75
    if (!home_dir)
74
76
    {                                   /* Don't initialize twice */
75
77
      if ((home_dir=getenv("HOME")) != 0)
80
82
        /* Default creation of new dir's */
81
83
      if ((str=getenv("UMASK_DIR")) != 0)
82
84
        my_umask_dir=(int) (atoi_octal(str) | 0700);
 
85
      DBUG_PRINT("exit",("home: '%s'",home_dir));
83
86
    }
84
 
    return(0);
 
87
    DBUG_RETURN(0);
85
88
  }
86
89
} /* my_init */
87
90
 
95
98
    Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be
96
99
    optimized until this compiler is not in use anymore
97
100
  */
98
 
  FILE *info_file= stderr;
99
 
  bool print_info= 0;
 
101
  FILE *info_file= DBUG_FILE;
 
102
  my_bool print_info= (info_file != stderr);
 
103
  /*
 
104
    We do not use DBUG_ENTER here, as after cleanup DBUG is no longer
 
105
    operational, so we cannot use DBUG_RETURN.
 
106
  */
 
107
  DBUG_PRINT("info",("Shutting down: infoflag: %d  print_info: %d",
 
108
                     infoflag, print_info));
 
109
  if (!info_file)
 
110
  {
 
111
    info_file= stderr;
 
112
    print_info= 0;
 
113
  }
100
114
 
101
115
  if ((infoflag & MY_CHECK_ERROR) || print_info)
102
116
 
104
118
    if (my_file_opened | my_stream_opened)
105
119
    {
106
120
      sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
107
 
      /* TODO: Mark... look at replacement here
108
 
       * (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
109
 
       */
110
 
      (void) fflush(stdout);
111
 
      
 
121
      (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
 
122
      DBUG_PRINT("error",("%s",errbuff[0]));
112
123
      my_print_open_files();
113
124
    }
114
125
  }
115
126
  free_charsets();
116
127
  my_error_unregister_all();
 
128
  my_once_free();
117
129
 
118
130
  if ((infoflag & MY_GIVE_INFO) || print_info)
119
131
  {
121
133
    struct rusage rus;
122
134
#ifdef HAVE_purify
123
135
    /* Purify assumes that rus is uninitialized after getrusage call */
124
 
    memset(&rus, 0, sizeof(rus));
 
136
    bzero((char*) &rus, sizeof(rus));
125
137
#endif
126
138
    if (!getrusage(RUSAGE_SELF, &rus))
127
139
      fprintf(info_file,"\n\
146
158
    TERMINATE(stderr, 0);               /* Print memory leaks on screen */
147
159
  }
148
160
 
 
161
  if (!(infoflag & MY_DONT_FREE_DBUG))
 
162
  {
 
163
    DBUG_END();                /* Must be done before my_thread_end */
 
164
  }
149
165
  my_thread_end();
150
166
  my_thread_global_end();
151
167
#if defined(SAFE_MUTEX)
153
169
    Check on destroying of mutexes. A few may be left that will get cleaned
154
170
    up by C++ destructors
155
171
  */
156
 
  safe_mutex_end();
157
 
 
 
172
  safe_mutex_end((infoflag & (MY_GIVE_INFO | MY_CHECK_ERROR)) ? stderr :
 
173
                 (FILE *) 0);
158
174
#endif /* defined(SAFE_MUTEX) */
159
175
 
160
176
  my_init_done=0;