~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright (C) 2000-2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */

#include <config.h>

#include <drizzled/internal/my_sys.h>
#include "my_static.h"
#include <drizzled/error.h>
#include <drizzled/internal/m_string.h>
#include <drizzled/charset.h>
#include <cstdio>
#include <cstdlib>

namespace drizzled {
namespace internal {

static bool my_init_done= 0;

static uint32_t atoi_octal(const char *str)
{
  long int tmp;
  while (*str && my_charset_utf8_general_ci.isspace(*str))
    str++;
  tmp= strtol(str, NULL, (*str == '0' ? 8 : 10));
  return (uint32_t) tmp;
}


/*
  Init my_sys functions and my_sys variabels

  SYNOPSIS
    my_init()

  RETURN
    0  ok
    1  Couldn't initialize environment
*/

void my_init()
{
  if (my_init_done)
    return;
  my_init_done= true;
  my_umask= 0660;                       /* Default umask for new files */
  my_umask_dir= 0700;                   /* Default umask for new directories */
#if defined(HAVE_PTHREAD_INIT)
  pthread_init();
#endif
  my_thread_init();
  sigfillset(&my_signals);		/* signals blocked by mf_brkhant */
    if (!home_dir)
    {					/* Don't initialize twice */
      if ((home_dir=getenv("HOME")) != 0)
	home_dir=intern_filename(home_dir_buff,home_dir);
      /* Default creation of new files */
      if (const char* str= getenv("UMASK"))
	my_umask=(int) (atoi_octal(str) | 0600);
	/* Default creation of new dir's */
      if (const char* str= getenv("UMASK_DIR"))
	my_umask_dir=(int) (atoi_octal(str) | 0700);
    }
} /* my_init */


	/* End my_sys */

void my_end()
{
  free_charsets();
  my_init_done= false;
} /* my_end */

} /* namespace internal */
} /* namespace drizzled */