MySQL 5.6.14 Source Code Document
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
NDBT_Find.cpp
1
/*
2
Copyright 2009 Sun Microsystems, Inc.
3
4
All rights reserved. Use is subject to license terms.
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; version 2 of the License.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
21
#include <NDBT_Find.hpp>
22
23
void
24
NDBT_find_binary(
BaseString
&
name
,
const
char
* binary_name,
25
const
char
* first_path, ...)
26
{
27
28
Vector<BaseString>
paths;
29
30
// Push all the different paths to a list
31
const
char
* str = first_path;
32
va_list args;
33
va_start(args, first_path);
34
do
35
{
36
BaseString
path;
37
path.
assfmt
(
"%s"
, str);
38
paths.push_back(path);
39
}
while
((str = va_arg(args,
const
char
*)) != NULL);
40
va_end(args);
41
42
// Loop the list of paths and see if the binary exists
43
for
(
unsigned
i
= 0;
i
< paths.size();
i
++)
44
{
45
BaseString
path;
46
path.
assfmt
(
"%s/%s"
, paths[
i
].c_str(), binary_name);
47
if
(access(path.
c_str
(), F_OK) == 0)
48
{
49
// Sucess, found the binary. Convert path to absolute and return it
50
char
realpath_buf[PATH_MAX];
51
#ifndef _WIN32
52
if
(realpath(path.
c_str
(), realpath_buf) == NULL)
53
{
54
fprintf(stderr,
"Could not convert '%s' to realpath\n"
, path.
c_str
());
55
abort();
56
}
57
#else
58
int
ret
= GetFullPathName(path.
c_str
(),
sizeof
(realpath_buf),
59
realpath_buf, NULL);
60
if
(ret == 0 || ret >=
sizeof
(realpath_buf))
61
{
62
fprintf(stderr,
"Could not convert '%s' with GetFullPathName\n"
,
63
path.
c_str
());
64
abort();
65
}
66
#endif
67
68
name.
assign
(realpath_buf);
69
return
;
70
}
71
}
72
73
// Failed to find the binary in any of the supplied paths
74
BaseString
searched;
75
searched.
append
(paths,
", "
);
76
fprintf(stderr,
"Could not find '%s' in '%s'\n"
,
77
binary_name, searched.
c_str
());
78
abort();
79
}
80
81
void
82
NDBT_find_ndb_mgmd(
BaseString
& path)
83
{
84
NDBT_find_binary(path,
"ndb_mgmd"
,
85
"../../src/mgmsrv"
,
86
"../storage/ndb/src/mgmsrv/"
,
87
NULL);
88
}
89
storage
ndb
test
src
NDBT_Find.cpp
Generated on Sat Nov 9 2013 01:28:35 for MySQL 5.6.14 Source Code Document by
1.8.1.2