2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
// $Id: FileUtil.cc 3864 2005-01-24 18:02:34Z mathias $
24
#include "FileUtil.hh"
39
time_t FileUtil::getLastStatusChangeTimestamp(const char* filename) {
41
if (filename && !stat(filename, &buf)) {
47
bool FileUtil::isDirectory(const char* filename) {
49
if (!filename || stat(filename, &buf))
52
return S_ISDIR(buf.st_mode);
55
bool FileUtil::isRegularFile(const char* filename) {
57
if (!filename || stat(filename, &buf))
60
return S_ISREG(buf.st_mode);
63
bool FileUtil::isExecutable(const char* filename) {
65
if (!filename || stat(filename, &buf))
68
return buf.st_mode & S_IXUSR ||
69
buf.st_mode & S_IXGRP ||
70
buf.st_mode & S_IXOTH;
73
bool FileUtil::copyFile(const char* from, const char* to) {
74
ifstream from_file(from);
78
cerr << "Can't write file '"<<to<<"'."<<endl;
79
else if (from_file.good()) {
80
to_file<<from_file.rdbuf();
83
cerr << "Can't copy from '"<<from<<"' to '"<<to<<"'."<<endl;
88
Directory::Directory(const char *dir):m_dir(0),
94
Directory::~Directory() {
98
void Directory::rewind() {
103
struct dirent *Directory::read() {
107
return readdir(m_dir);
110
std::string Directory::readFilename() {
111
dirent *ent = read();
114
return (ent->d_name ? ent->d_name : "");
117
void Directory::close() {
127
bool Directory::open(const char *dir) {
134
m_dir = opendir(dir);
135
if (m_dir == 0) // successfull loading?
140
// get number of entries
144
rewind(); // go back to start
150
}; // end namespace FbTk