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_info.h>
00023 #include <drizzled/charset.h>
00024 #include <cstdio>
00025 #include <cstdlib>
00026 
00027 namespace drizzled
00028 {
00029 namespace internal
00030 {
00031 
00032 bool my_init_done= 0;
00033 uint  mysys_usage_id= 0;              /* Incremented for each my_init() */
00034 
00035 static uint32_t atoi_octal(const char *str)
00036 {
00037   long int tmp;
00038   while (*str && my_isspace(&my_charset_utf8_general_ci, *str))
00039     str++;
00040   tmp= strtol(str, NULL, (*str == '0' ? 8 : 10));
00041   return (uint32_t) tmp;
00042 }
00043 
00044 
00045 /*
00046   Init my_sys functions and my_sys variabels
00047 
00048   SYNOPSIS
00049     my_init()
00050 
00051   RETURN
00052     0  ok
00053     1  Couldn't initialize environment
00054 */
00055 
00056 bool my_init(void)
00057 {
00058   char * str;
00059   if (my_init_done)
00060     return 0;
00061   my_init_done=1;
00062   mysys_usage_id++;
00063   my_umask= 0660;                       /* Default umask for new files */
00064   my_umask_dir= 0700;                   /* Default umask for new directories */
00065 #if defined(HAVE_PTHREAD_INIT)
00066   pthread_init();
00067 #endif
00068   if (my_thread_global_init())
00069     return 1;
00070   sigfillset(&my_signals);    /* signals blocked by mf_brkhant */
00071   {
00072     if (!home_dir)
00073     {         /* Don't initialize twice */
00074       if ((home_dir=getenv("HOME")) != 0)
00075   home_dir=intern_filename(home_dir_buff,home_dir);
00076       /* Default creation of new files */
00077       if ((str=getenv("UMASK")) != 0)
00078   my_umask=(int) (atoi_octal(str) | 0600);
00079   /* Default creation of new dir's */
00080       if ((str=getenv("UMASK_DIR")) != 0)
00081   my_umask_dir=(int) (atoi_octal(str) | 0700);
00082     }
00083     return(0);
00084   }
00085 } /* my_init */
00086 
00087 
00088   /* End my_sys */
00089 
00090 void my_end()
00091 {
00092   free_charsets();
00093 
00094   my_thread_end();
00095   my_thread_global_end();
00096 
00097   my_init_done=0;
00098 } /* my_end */
00099 
00100 } /* namespace internal */
00101 } /* namespace drizzled */