Beispiel #1
0
primitiveFileWrite(void)
{
    sqInt array;
    char *arrayIndex;
    size_t byteSize;
    sqInt bytesWritten;
    size_t count;
    SQFile * file;
    sqInt objectPointer;
    size_t startIndex;

	count = interpreterProxy->positive32BitValueOf(interpreterProxy->stackValue(0));
	startIndex = interpreterProxy->positive32BitValueOf(interpreterProxy->stackValue(1));
	array = interpreterProxy->stackValue(2);
	/* begin fileValueOf: */
	objectPointer = interpreterProxy->stackValue(3);
	if (!((interpreterProxy->isBytes(objectPointer))
		 && ((interpreterProxy->byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
		interpreterProxy->primitiveFail();
		file = null;
		goto l1;
	}
	file = interpreterProxy->firstIndexableField(objectPointer);
l1:	/* end fileValueOf: */;
	if (!(interpreterProxy->isWordsOrBytes(array))) {
		return interpreterProxy->primitiveFail();
	}
	if (interpreterProxy->isWords(array)) {
		byteSize = 4;
	}
	else {
		byteSize = 1;
	}
	if (!((startIndex >= 1)
		 && (((startIndex + count) - 1) <= (interpreterProxy->slotSizeOf(array))))) {
		return interpreterProxy->primitiveFail();
	}
	if (!(interpreterProxy->failed())) {

		/* Note: adjust startIndex for zero-origin indexing */

		arrayIndex = interpreterProxy->firstIndexableField(array);
		bytesWritten = sqFileWriteFromAt(file, count * byteSize, arrayIndex, (startIndex - 1) * byteSize);
	}
	if (!(interpreterProxy->failed())) {
		interpreterProxy->popthenPush(5, (((bytesWritten / byteSize) << 1) | 1));
	}
}
primitiveFileWrite(void)
{
	// FilePlugin>>#primitiveFileWrite
    sqInt array;
    sqInt bytesWritten;
    size_t count;
    size_t elementSize;
    SQFile *file;
    sqInt objectPointer;
    size_t startIndex;

	count = positive32BitValueOf(stackValue(0));
	startIndex = positive32BitValueOf(stackValue(1));
	array = stackValue(2);
	/* begin fileValueOf: */
	objectPointer = stackValue(3);
	if (!((isBytes(objectPointer))
		 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
		primitiveFail();
		file = null;
		goto l1;
	}
	file = firstIndexableField(objectPointer);
l1:	/* end fileValueOf: */;
	if ((failed())
	 || (!(isWordsOrBytes(array)))) {
		return primitiveFailFor(PrimErrBadArgument);
	}
	elementSize = (isWords(array)
		? 4
		: 1);
	if (!((startIndex >= 1)
		 && (((startIndex + count) - 1) <= (slotSizeOf(array))))) {
		return primitiveFailFor(PrimErrBadIndex);
	}
	bytesWritten = sqFileWriteFromAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
	if (!(failed())) {
		popthenPush(5, integerObjectOf(bytesWritten / elementSize));
	}
}