/usr/include/BALL/SYSTEM/directory.iC is in libball1.4-dev 1.4.3~beta1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: directory.iC,v 1.17 2005/12/23 17:02:06 amoll Exp $
//
BALL_INLINE
String Directory::getcwd_()
{
char* buffer;
#ifdef BALL_COMPILER_MSVC
buffer = ::_getcwd(NULL, MAX_PATH_LENGTH);
#else
buffer = ::getcwd(NULL, MAX_PATH_LENGTH);
#endif
String result(buffer);
free (buffer);
return result;
}
BALL_INLINE
int Directory::chdir_(const String& new_dir)
{
#ifdef BALL_COMPILER_MSVC
return ::_chdir(new_dir.c_str());
#else
return ::chdir(new_dir.c_str());
#endif
}
BALL_INLINE
void Directory::synchronize_()
{
String cwd = getcwd_();
String canonical_path(directory_path_);
// We need to ensure that trailing slashes are handled correctly!
cwd+=FileSystem::PATH_SEPARATOR;
canonical_path+=FileSystem::PATH_SEPARATOR;
FileSystem::canonizePath(cwd);
FileSystem::canonizePath(canonical_path);
if (cwd != canonical_path)
{
backup_path_ = cwd;
chdir_(directory_path_);
}
}
BALL_INLINE
bool Directory::desynchronize_(bool result1)
{
if (backup_path_ == "")
{
return result1;
}
bool result2 = (chdir_(backup_path_) == 0);
backup_path_ = "";
return (result1 && result2);
}
BALL_INLINE
void Directory::clear()
{
#ifdef BALL_OS_WINDOWS
if (dirent_ != INVALID_HANDLE_VALUE) FindClose(dirent_);
if (dir_ != INVALID_HANDLE_VALUE) CloseHandle(dir_);
#else
if (dir_ != 0)
{
::closedir(dir_);
}
#endif
dir_ = INVALID_HANDLE_VALUE;
dirent_ = INVALID_HANDLE_VALUE;
directory_path_ = "";
}
BALL_INLINE
void Directory::destroy()
{
clear();
}
BALL_INLINE
void Directory::set(const Directory& directory)
{
clear();
directory_path_ = directory.directory_path_;
backup_path_ = "";
}
BALL_INLINE
Directory& Directory::operator = (const Directory& directory)
{
set(directory);
return *this;
}
BALL_INLINE
void Directory::get(Directory& directory) const
{
directory.set(*this);
}
BALL_INLINE
const String& Directory::getPath() const
{
return directory_path_;
}
BALL_INLINE
bool Directory::rename(String old_path, String new_path)
{
synchronize_();
FileSystem::canonizePath(old_path);
FileSystem::canonizePath(new_path);
return desynchronize_((::rename(old_path.c_str(), new_path.c_str()) == 0));
}
BALL_INLINE
bool Directory::setCurrent(String directory_path)
{
FileSystem::canonizePath(directory_path);
#ifdef BALL_OS_WINDOWS
return (::_chdir(directory_path.c_str()) == 0);
#else
return (::chdir(directory_path.c_str()) == 0);
#endif
}
BALL_INLINE
bool Directory::setCurrent()
{
return Directory::setCurrent(directory_path_);
}
BALL_INLINE
bool Directory::create(String directory_path, const mode_t& mode)
{
#ifdef BALL_COMPILER_MSVC
if(!isValid()) return false;
FileSystem::canonizePath(directory_path);
if ((directory_path[0] == FileSystem::PATH_SEPARATOR) || (directory_path[1] == ':' && directory_path[2] == FileSystem::PATH_SEPARATOR))
{
return (::_mkdir(directory_path.c_str()) ==0);
}
synchronize_();
return desynchronize_(::_mkdir(directory_path.c_str()) ==0);
#else
FileSystem::canonizePath(directory_path);
if (directory_path[0] == FileSystem::PATH_SEPARATOR)
{
return (::mkdir(directory_path.c_str(), mode) == 0);
}
synchronize_();
return desynchronize_((::mkdir(directory_path.c_str(), mode) == 0));
#endif
}
BALL_INLINE
bool Directory::remove(String directory_path)
{
synchronize_();
FileSystem::canonizePath(directory_path);
#ifdef BALL_COMPILER_MSVC
// get alsolute path
char* buffer = ::_getcwd(NULL, MAX_PATH_LENGTH);
String old_dir(buffer);
free(buffer);
if(::_chdir(directory_path.c_str()) == 0)
{ // determine absolute path
buffer = ::_getcwd(NULL,MAX_PATH_LENGTH);
directory_path = buffer;
free(buffer);
::_chdir(old_dir.c_str());
}
else
{
// cannot change to dir...return
return desynchronize_(false);
}
bool ok = desynchronize_((::_rmdir(directory_path.c_str()) == 0));
#else
bool ok = desynchronize_((::rmdir(directory_path.c_str()) == 0));
#endif
if (directory_path == directory_path_)
{
clear();
}
return ok;
}
BALL_INLINE
bool Directory::isEmpty()
{
return (countItems() == 0);
}
BALL_INLINE
bool Directory::operator == (const Directory& directory) const
{
return (directory_path_ == directory.directory_path_);
}
BALL_INLINE
bool Directory::operator != (const Directory& directory) const
{
return (directory_path_ != directory.directory_path_);
}
|