Drizzled Public API Documentation

mf_loadpath.cc

00001 /* Copyright (C) 2000 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 <drizzled/internal/m_string.h>
00020 
00021 namespace drizzled
00022 {
00023 namespace internal
00024 {
00025 
00026   /* Returns full load-path for a file. to may be = path */
00027   /* if path is a hard-path return path */
00028   /* if path starts with home-dir return path */
00029   /* if path starts with current dir or parent-dir unpack path */
00030   /* if there is no path, prepend with own_path_prefix if given */
00031   /* else unpack path according to current dir */
00032 
00033 char * my_load_path(char * to, const char *path,
00034            const char *own_path_prefix)
00035 {
00036   char buff[FN_REFLEN];
00037   int is_cur;
00038 
00039   if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) ||
00040       test_if_hard_path(path))
00041     strcpy(buff,path);
00042   else if ((is_cur=(path[0] == FN_CURLIB && path[1] == FN_LIBCHAR)) ||
00043      (strncmp(path,FN_PARENTDIR, strlen(FN_PARENTDIR)) == 0) ||
00044      ! own_path_prefix)
00045   {
00046     if (is_cur)
00047       is_cur=2;         /* Remove current dir */
00048     if (! getcwd(buff,(uint32_t) (FN_REFLEN-strlen(path)+is_cur)))
00049       strcat(buff,path+is_cur);
00050     else
00051       strcpy(buff,path);      /* Return org file name */
00052   }
00053   else
00054     snprintf(buff, sizeof(buff), "%s%s",own_path_prefix,path);
00055   strcpy(to,buff);
00056   return(to);
00057 } /* my_load_path */
00058 
00059 } /* namespace internal */
00060 } /* namespace drizzled */