Drizzled Public API Documentation

my_init.cc
00001 /* Copyright (C) 2000-2003 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include <config.h>
00017 
00018 #include <drizzled/internal/my_sys.h>
00019 #include "my_static.h"
00020 #include <drizzled/error.h>
00021 #include <drizzled/internal/m_string.h>
00022 #include <drizzled/charset.h>
00023 #include <cstdio>
00024 #include <cstdlib>
00025 
00026 namespace drizzled {
00027 namespace internal {
00028 
00029 static bool my_init_done= 0;
00030 
00031 static uint32_t atoi_octal(const char *str)
00032 {
00033   long int tmp;
00034   while (*str && my_charset_utf8_general_ci.isspace(*str))
00035     str++;
00036   tmp= strtol(str, NULL, (*str == '0' ? 8 : 10));
00037   return (uint32_t) tmp;
00038 }
00039 
00040 
00041 /*
00042   Init my_sys functions and my_sys variabels
00043 
00044   SYNOPSIS
00045     my_init()
00046 
00047   RETURN
00048     0  ok
00049     1  Couldn't initialize environment
00050 */
00051 
00052 void my_init()
00053 {
00054   if (my_init_done)
00055     return;
00056   my_init_done= true;
00057   my_umask= 0660;                       /* Default umask for new files */
00058   my_umask_dir= 0700;                   /* Default umask for new directories */
00059 #if defined(HAVE_PTHREAD_INIT)
00060   pthread_init();
00061 #endif
00062   my_thread_init();
00063   sigfillset(&my_signals);    /* signals blocked by mf_brkhant */
00064     if (!home_dir)
00065     {         /* Don't initialize twice */
00066       if ((home_dir=getenv("HOME")) != 0)
00067   home_dir=intern_filename(home_dir_buff,home_dir);
00068       /* Default creation of new files */
00069       if (const char* str= getenv("UMASK"))
00070   my_umask=(int) (atoi_octal(str) | 0600);
00071   /* Default creation of new dir's */
00072       if (const char* str= getenv("UMASK_DIR"))
00073   my_umask_dir=(int) (atoi_octal(str) | 0700);
00074     }
00075 } /* my_init */
00076 
00077 
00078   /* End my_sys */
00079 
00080 void my_end()
00081 {
00082   free_charsets();
00083   my_init_done= false;
00084 } /* my_end */
00085 
00086 } /* namespace internal */
00087 } /* namespace drizzled */