Beispiel #1
0
void PathUtils::concatPath(Firebird::PathName& result,
		const Firebird::PathName& first,
		const Firebird::PathName& second)
{
	if (second.length() == 0)
	{
		result = first;
		return;
	}
	if (first.length() == 0)
	{
		result = second;
		return;
	}

	if (first[first.length() - 1] != dir_sep &&
		second[0] != dir_sep)
	{
		result = first + dir_sep + second;
		return;
	}
	if (first[first.length() - 1] == dir_sep &&
		second[0] == dir_sep)
	{
		result = first;
		result.append(second, 1, second.length() - 1);
		return;
	}

	result = first + second;
}
Beispiel #2
0
// We don't work correctly with MBCS.
void PathUtils::ensureSeparator(Firebird::PathName& in_out)
{
	if (in_out.length() == 0)
		in_out = PathUtils::dir_sep;

	if (in_out[in_out.length() - 1] != PathUtils::dir_sep)
		in_out += PathUtils::dir_sep;
}
Beispiel #3
0
// moves DB path information (from limbo transaction) to another buffer
void getDbPathInfo(unsigned int& itemsLength, const unsigned char*& items,
	unsigned int& bufferLength, unsigned char*& buffer,
	Firebird::Array<unsigned char>& newItemsBuffer, const Firebird::PathName& dbpath)
{
	if (itemsLength && items)
	{
		const unsigned char* ptr = (const unsigned char*) memchr(items, fb_info_tra_dbpath, itemsLength);
		if (ptr)
		{
			newItemsBuffer.add(items, itemsLength);
			newItemsBuffer.remove(ptr - items);
			items = newItemsBuffer.begin();
			--itemsLength;

			unsigned int len = dbpath.length();
			if (len + 3 > bufferLength)
			{
				len = bufferLength - 3;
			}
			bufferLength -= (len + 3);
			*buffer++ = fb_info_tra_dbpath;
			*buffer++ = len;
			*buffer++ = len >> 8;
			memcpy(buffer, dbpath.c_str(), len);
			buffer += len;
		}
	}
}
Beispiel #4
0
void ModuleLoader::doctorModuleExtention(Firebird::PathName& name)
{
    Firebird::PathName::size_type pos = name.rfind(".dylib");
    if (pos != Firebird::PathName::npos && pos == name.length() - 6)
        return;		// No doctoring necessary
    name += ".dylib";
}
Beispiel #5
0
bool ModuleLoader::doctorModuleExtension(Firebird::PathName& name, int& step)
{
	if (name.isEmpty())
		return false;

	switch (step++)
	{
	case 0: // Step 0: append missing extension
		{
			Firebird::PathName::size_type pos = name.rfind("." SHRLIB_EXT);
			if (pos != name.length() - 3)
			{
				pos = name.rfind("." SHRLIB_EXT ".");
				if (pos == Firebird::PathName::npos)
				{
					name += "." SHRLIB_EXT;
					return true;
				}
			}
			step++; // instead of break
		}
	case 1: // Step 1: insert missing prefix
		{
			Firebird::PathName::size_type pos = name.rfind('/');
			pos = (pos == Firebird::PathName::npos) ? 0 : pos + 1;
			if (name.find("lib", pos) != pos)
			{
				name.insert(pos, "lib");
				return true;
			}
		}
	}
	return false;
}
Beispiel #6
0
bool PathUtils::isRelative(const Firebird::PathName& path)
{
	if (path.length() > 0)
	{
		char ds = path[0];
		if (path.length() > 2) {
			if (path[1] == ':' &&
				(('A' <= path[0] && path[0] <= 'Z') ||
				 ('a' <= path[0] && path[0] <= 'z')))
			{
				ds = path[2];
			}
		}
		return ds != PathUtils::dir_sep && ds != '/';
	}
	return true;
}
Beispiel #7
0
bool PathUtils::isRelative(const Firebird::PathName& path)
{
	if (path.length() > 0)
	{
		const char ds = hasDriveLetter(path) ? path[2] : path[0];
		return ds != PathUtils::dir_sep && ds != '/';
	}
	return true;
}
Beispiel #8
0
void ModuleLoader::doctorModuleExtension(Firebird::PathName& name)
{
	Firebird::PathName::size_type pos = name.rfind('/');
	pos = (pos == Firebird::PathName::npos) ? 0 : pos + 1;
	if (name.find("lib", pos) != pos)
	{
		name.insert(pos, "lib");
	}

	pos = name.rfind(".dylib");
	if (pos == name.length() - 6)
		return;
	name += ".dylib";
}
Beispiel #9
0
void PathUtils::splitLastComponent(Firebird::PathName& path, Firebird::PathName& file,
		const Firebird::PathName& orgPath)
{
	Firebird::PathName::size_type pos = orgPath.rfind(dir_sep);
	if (pos == Firebird::PathName::npos)
	{
		path = "";
		file = orgPath;
		return;
	}

	path.erase();
	path.append(orgPath, 0, pos);	// skip the directory separator
	file.erase();
	file.append(orgPath, pos + 1, orgPath.length() - pos - 1);
}
Beispiel #10
0
void ModuleLoader::doctorModuleExtension(Firebird::PathName& name)
{
	if (name.isEmpty())
		return;

	Firebird::PathName::size_type pos = name.rfind("." SHRLIB_EXT);
	if (pos != name.length() - 3)
	{
		name += "." SHRLIB_EXT;
	}
	pos = name.rfind('/');
	pos = (pos == Firebird::PathName::npos) ? 0 : pos + 1;
	if (name.find("lib", pos) != pos)
	{
		name.insert(pos, "lib");
	}
}
Beispiel #11
0
void PathUtils::splitLastComponent(Firebird::PathName& path, Firebird::PathName& file,
		const Firebird::PathName& orgPath)
{
	Firebird::PathName::size_type pos = orgPath.rfind(PathUtils::dir_sep);
	if (pos == Firebird::PathName::npos)
	{
		pos = orgPath.rfind('/');	// temp hack to make it work with paths,
									// not expanded by ISC_expand_filename
		if (pos == Firebird::PathName::npos)
		{
			path = "";
			file = orgPath;
			return;
		}
	}

	path.erase();
	path.append(orgPath, 0, pos);	// skip the directory separator
	file.erase();
	file.append(orgPath, pos + 1, orgPath.length() - pos - 1);
}
Beispiel #12
0
bool PathUtils::isRelative(const Firebird::PathName& path)
{
	if (path.length() > 0)
		return path[0] != dir_sep;
	return false;
}
Beispiel #13
0
static bool hasDriveLetter(const Firebird::PathName& path)
{
	return path.length() > 2 && path[1] == ':' &&
		(('A' <= path[0] && path[0] <= 'Z') ||
		 ('a' <= path[0] && path[0] <= 'z'));
}