Example #1
0
/*static*/ void MassStorage::CombineName(const StringRef& outbuf, const char* directory, const char* fileName)
{
	outbuf.Clear();
	size_t outIndex = 0;
	size_t inIndex = 0;

	// DC 2015-11-25 Only prepend the directory if the filename does not have an absolute path or volume specifier
	if (directory != nullptr && fileName[0] != '/' && (strlen(fileName) < 2 || !isdigit(fileName[0]) || fileName[1] != ':'))
	{
		while (directory[inIndex] != 0 && directory[inIndex] != '\n')
		{
			outbuf.Pointer()[outIndex] = directory[inIndex];
			inIndex++;
			outIndex++;
			if (outIndex >= outbuf.Capacity())
			{
				reprap.GetPlatform().MessageF(ErrorMessage, "CombineName() buffer overflow");
				outbuf.copy("?????");
				return;
			}
		}

		if (inIndex > 0 && directory[inIndex - 1] != '/')
		{
			outbuf.Pointer()[outIndex] = '/';
			outIndex++;
		}
		inIndex = 0;
	}

	while (fileName[inIndex] != 0 && fileName[inIndex] != '\n')
	{
		if (outIndex >= outbuf.Capacity())
		{
			reprap.GetPlatform().Message(ErrorMessage, "file name too long");
			outbuf.copy("?????");
			return;
		}
		outbuf.Pointer()[outIndex] = fileName[inIndex];
		inIndex++;
		outIndex++;
	}
	outbuf.Pointer()[outIndex] = 0;
}