3 |
andreas |
1 |
/*
|
21 |
andreas |
2 |
* Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
|
3 |
andreas |
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; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#include "tvalidatefile.h"
|
|
|
20 |
#include <sys/types.h>
|
|
|
21 |
#include <sys/stat.h>
|
|
|
22 |
#include "terror.h"
|
|
|
23 |
|
|
|
24 |
using std::string;
|
|
|
25 |
|
|
|
26 |
bool TValidateFile::isValidFile(const string& file)
|
|
|
27 |
{
|
|
|
28 |
DECL_TRACER("TValidateFile::isValid(const string& file)");
|
|
|
29 |
|
|
|
30 |
struct stat buffer;
|
|
|
31 |
|
|
|
32 |
if (stat (file.c_str(), &buffer) != 0)
|
|
|
33 |
{
|
|
|
34 |
MSG_ERROR("Error: File " << file << " doesn't exist or can't be opened!");
|
|
|
35 |
return false;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
return true;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
std::string &TValidateFile::makeFileName(const std::string& path, const std::string& name)
|
|
|
42 |
{
|
|
|
43 |
DECL_TRACER("TValidateFile::makeFileName(const std::string& path, const std::string& name)");
|
|
|
44 |
|
|
|
45 |
if (name.empty())
|
|
|
46 |
{
|
|
|
47 |
mFile.clear();
|
|
|
48 |
return mFile;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
if (path.empty())
|
|
|
52 |
mFile = "./";
|
|
|
53 |
else
|
|
|
54 |
mFile = path + "/";
|
|
|
55 |
|
|
|
56 |
mFile.append(name);
|
|
|
57 |
return mFile;
|
|
|
58 |
}
|
|
|
59 |
|