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