Drizzled Public API Documentation

mf_loadpath.cc
1 /* Copyright (C) 2000 MySQL AB
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include <config.h>
17 
18 #include <drizzled/internal/my_sys.h>
19 #include <drizzled/internal/m_string.h>
20 
21 namespace drizzled
22 {
23 namespace internal
24 {
25 
26  /* Returns full load-path for a file. to may be = path */
27  /* if path is a hard-path return path */
28  /* if path starts with home-dir return path */
29  /* if path starts with current dir or parent-dir unpack path */
30  /* if there is no path, prepend with own_path_prefix if given */
31  /* else unpack path according to current dir */
32 
33 char * my_load_path(char * to, const char *path,
34  const char *own_path_prefix)
35 {
36  char buff[FN_REFLEN];
37  int is_cur;
38 
39  if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) ||
40  test_if_hard_path(path))
41  strcpy(buff,path);
42  else if ((is_cur=(path[0] == FN_CURLIB && path[1] == FN_LIBCHAR)) ||
43  (strncmp(path,FN_PARENTDIR, strlen(FN_PARENTDIR)) == 0) ||
44  ! own_path_prefix)
45  {
46  if (is_cur)
47  is_cur=2; /* Remove current dir */
48  if (! getcwd(buff,(uint32_t) (FN_REFLEN-strlen(path)+is_cur)))
49  strcat(buff,path+is_cur);
50  else
51  strcpy(buff,path); /* Return org file name */
52  }
53  else
54  snprintf(buff, sizeof(buff), "%s%s",own_path_prefix,path);
55  strcpy(to,buff);
56  return(to);
57 } /* my_load_path */
58 
59 } /* namespace internal */
60 } /* namespace drizzled */