1 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
6 (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
17 using namespace std;
18
19 #include "../config.h"
20
21 #include <string>
22
23 #include "smack.h"
24 #include "die.h"
25
26 const char* datadir = SMACK_DATADIR;
27
mk_data_path(char * buf,const char * file)28 char* mk_data_path(char* buf, const char* file)
29 {
30 if(datadir && *file != '/')
31 {
32 int datadir_len = strlen(datadir);
33 if(datadir_len > MAX_PATH - 3)
34 {
35 die(0, "datadir is too long ");
36 }
37 memcpy(buf, datadir, datadir_len);
38 char* p = buf + datadir_len - 1;
39 if(*p != '/')
40 *++p = '/';
41 strncpy(p + 1, file, MAX_PATH - datadir_len - 1);
42 file = buf;
43 }
44
45 return (char*)file;
46 }
47
populate_data_file(const char * file,const char * cmd)48 int populate_data_file(const char* file, const char* cmd)
49 {
50 string shell_cmd = cmd;
51 cout << "Populating data file '" << file << "' with shell command '" <<
52 cmd << "'" << endl;
53 shell_cmd += " > ";
54 shell_cmd += file;
55 return system(shell_cmd.c_str());
56 }
57
58