Exemplo n.º 1
0
// native fwrite(file, data, mode);
static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	cell   data = params[2];
	size_t size = params[3];

	switch (size)
	{
		case BLOCK_CHAR:
		{
			char value = static_cast<char>(data);
			return fp->Write(&value, sizeof(value));
		}
		case BLOCK_SHORT:
		{
			short value = static_cast<short>(data);
			return fp->Write(&value, sizeof(value));
		}
		case BLOCK_INT:
		{
			int value = static_cast<int>(data);
			return fp->Write(&value, sizeof(value));
		}
	}

	return 0;
}
Exemplo n.º 2
0
// native fwrite_blocks(file, const data[], blocks, mode);
static cell AMX_NATIVE_CALL amx_fwrite_blocks(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	cell* data  = get_amxaddr(amx, params[2]);
	cell blocks = params[3];
	cell size   = params[4];

	size_t read = 0;

	switch (size)
	{
		case BLOCK_CHAR:
		{
			for (cell i = 0; i < blocks; ++i)
			{
				char value = data[i];

				if (fp->Write(&value, sizeof(value)) != sizeof(value))
				{
					break;
				}

				read += sizeof(value);
			}
			break;
		}
		case BLOCK_SHORT:
		{
			for (cell i = 0; i < blocks; ++i)
			{
				short value = data[i];

				if (fp->Write(&value, sizeof(value)) != sizeof(value))
				{
					break;
				}

				read += sizeof(value);
			}
			break;
		}
		case BLOCK_INT:
		{
			read = fp->Write(data, sizeof(cell) * blocks);
			break;
		}
		default:
		{
			return 0;
		}
	}

	return read / size;
}
Exemplo n.º 3
0
// native fwrite_raw(file, const stream[], blocksize, mode);
static cell AMX_NATIVE_CALL amx_fwrite_raw(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	cell* data = get_amxaddr(amx, params[2]);

	return fp->Write(&data, params[3] * params[4]);
}
Exemplo n.º 4
0
static cell File_WriteTyped(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	T value = static_cast<T>(params[2]);

	return !!(fp->Write(&value, sizeof(value)) == sizeof(value));
}
Exemplo n.º 5
0
//native fputc(file, data);
static cell AMX_NATIVE_CALL amx_fputc(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	uint8_t val = static_cast<uint8_t>(params[2]);

	if (fp->Write(&val, sizeof(val)) != sizeof(val))
	{
		return -1;
	}

	return val;
}
Exemplo n.º 6
0
// native fputs(file, const text[], bool:null_term = false);
static cell AMX_NATIVE_CALL amx_fputs(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	int length;
	char *string = get_amxstring(amx, params[2], 0, length);

	if (*params / sizeof(cell) >= 3 && params[3] > 0)
	{
		++length;
	}

	if (fp->Write(string, length) != length)
	{
		return -1;
	}

	return 0;
}