Пример #1
0
// native fread_raw(file, stream[], blocksize, blocks);
static cell AMX_NATIVE_CALL amx_fread_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->Read(data, params[3] * params[4]);
}
Пример #2
0
// native fread(file, &data, mode);
static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

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

	switch (params[3])
	{
		case BLOCK_CHAR:
		{
			char value;
			size_t res = fp->Read(&value, sizeof(value));
			*data = static_cast<cell>(value);
			return res;
		}
		case BLOCK_SHORT:
		{
			short value;
			size_t res = fp->Read(&value, sizeof(value));
			*data = static_cast<cell>(value);
			return res;
		}
		case BLOCK_INT:
		{
			int value;
			size_t res = fp->Read(&value, sizeof(value));
			*data = static_cast<cell>(value);
			return res;
		}
	}

	return 0;
}
Пример #3
0
//native fgetc(file);
static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

	uint8_t val;

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

	return static_cast<cell>(val);
}
Пример #4
0
static cell File_ReadTyped(AMX *amx, cell *params)
{
	FileObject* fp = reinterpret_cast<FileObject*>(params[1]);

	if (!fp)
	{
		return 0;
	}

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

	T value;

	if (fp->Read(&value, sizeof(value)) != sizeof(value))
	{
		return 0;
	}

	*data = value;
	return 1;
}
Пример #5
0
// native fread_blocks(file, data[], blocks, mode);
static cell AMX_NATIVE_CALL amx_fread_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;

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

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

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

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

	return read / size;
}