/src/server/mysys/mf_loadpath.c
Line | Count | Source (jump to first uncovered line) |
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-1335 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 | | |
27 | | char * my_load_path(char * to, const char *path, |
28 | | const char *own_path_prefix) |
29 | 0 | { |
30 | 0 | char buff[FN_REFLEN+1]; |
31 | 0 | const char *from= buff; |
32 | 0 | int is_cur; |
33 | 0 | DBUG_ENTER("my_load_path"); |
34 | 0 | DBUG_PRINT("enter",("path: %s prefix: %s",path, |
35 | 0 | own_path_prefix ? own_path_prefix : "")); |
36 | |
|
37 | 0 | if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) || |
38 | 0 | test_if_hard_path(path)) |
39 | 0 | from= path; |
40 | 0 | else if ((is_cur=(path[0] == FN_CURLIB && path[1] == FN_LIBCHAR)) || |
41 | 0 | (is_prefix(path,FN_PARENTDIR)) || |
42 | 0 | ! own_path_prefix) |
43 | 0 | { |
44 | 0 | if (is_cur) |
45 | 0 | is_cur=2; /* Remove current dir */ |
46 | 0 | if (! my_getwd(buff,(uint) (FN_REFLEN-strlen(path)+is_cur),MYF(0))) |
47 | 0 | { |
48 | 0 | size_t length= strlen(buff); |
49 | 0 | (void) strmake(buff + length, path+is_cur, FN_REFLEN - length); |
50 | 0 | } |
51 | 0 | else |
52 | 0 | from= path; /* Return org file name */ |
53 | 0 | } |
54 | 0 | else |
55 | 0 | (void) strxnmov(buff, FN_REFLEN, own_path_prefix, path, NullS); |
56 | 0 | strmake(to, from, FN_REFLEN-1); |
57 | 0 | DBUG_PRINT("exit",("to: %s",to)); |
58 | 0 | DBUG_RETURN(to); |
59 | 0 | } /* my_load_path */ |