Beispiel #1
0
primitiveOSFileHandle(void)
{
    sqInt fileNo;
    sqInt sqFileOop;

	sqFileOop = stackValue(0);
	if (!((((isBytes(sqFileOop))
		 && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile))))
		 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop)))))
		 && (isNonNullSQFile(sqFileOop)))) {
		return primitiveFail();
	}
	/* begin fileDescriptorFrom: */
	if (!((((isBytes(sqFileOop))
		 && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile))))
		 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop)))))
		 && (isNonNullSQFile(sqFileOop)))) {
		fileNo = -1;
		goto l1;
	}
	fileNo = fileno(fileHandleFrom(sqFileOop));
l1:	/* end fileDescriptorFrom: */;
	pop(2);
	pushInteger(fileNo);
	return 0;
}
Beispiel #2
0
primPCREExec(void)
{
	sqInt extraObj;
	sqInt length;
	int *matchSpacePtr;
	sqInt matchSpaceSize;
	sqInt result;
	char *searchBuffer;
	sqInt searchObject;


	/* Load Parameters */
	searchObject = stackObjectValue(0);
	searchBuffer = arrayValueOf(searchObject);
	length = byteSizeOf(searchObject);
	/* begin loadRcvrFromStackAt: */
	rcvr = stackObjectValue(1);
	pcrePtr = ((sqInt) (fetchArrayofObject(2, rcvr)));
	/* begin rcvrExtraPtr */
	extraObj = fetchPointerofObject(3, rcvr);
	extraPtr = ((sqInt) ((!(extraObj == (nilObject()))
	? arrayValueOf(extraObj)
	: 0)));
	matchFlags = fetchIntegerofObject(6, rcvr);
	matchSpacePtr = ((int *) (fetchArrayofObject(7, rcvr)));
	matchSpaceSize = (byteSizeOf(fetchPointerofObject(7, rcvr))) / 4;
	if (failed()) {
		return null;
	}
	result = pcre_exec((pcre *)pcrePtr, (pcre_extra *)extraPtr, 
				searchBuffer, length, 0, matchFlags, matchSpacePtr, matchSpaceSize);
	pop(2);
	pushInteger(result);
		return 0;
}
primitiveFileTruncate(void)
{
	// FilePlugin>>#primitiveFileTruncate
    SQFile *file;
    sqInt objectPointer;
    sqInt sz;
    squeakFileOffsetType truncatePosition;

	if (!(isIntegerObject(stackValue(0)))) {
		sz = sizeof(squeakFileOffsetType);
		if ((byteSizeOf(stackValue(0))) > sz) {
			return primitiveFail();
		}
	}
	truncatePosition = positive64BitValueOf(stackValue(0));
	/* begin fileValueOf: */
	objectPointer = stackValue(1);
	if (!((isBytes(objectPointer))
		 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
		primitiveFail();
		file = null;
		goto l1;
	}
	file = firstIndexableField(objectPointer);
l1:	/* end fileValueOf: */;
	if (!(failed())) {
		sqFileTruncate(file, truncatePosition);
	}
	if (!(failed())) {
		pop(2);
	}
}
Beispiel #4
0
primPCREExecfromto(void)
{
	sqInt extraObj;
	sqInt fromInteger;
	sqInt length;
	int *matchSpacePtr;
	sqInt matchSpaceSize;
	sqInt result;
	char *searchBuffer;
	sqInt searchObject;
	sqInt toInteger;


	/* Load Parameters */
	toInteger = stackIntegerValue(0);
	fromInteger = stackIntegerValue(1);
	searchObject = stackObjectValue(2);
	searchBuffer = arrayValueOf(searchObject);
	length = byteSizeOf(searchObject);
	/* begin loadRcvrFromStackAt: */
	rcvr = stackObjectValue(3);
	success(1 <= fromInteger);
	success(toInteger <= length);

	/* Smalltalk offsets are 1-based */
	fromInteger -= 1;
	success(fromInteger <= toInteger);
	length = toInteger - fromInteger;

	/* Load Instance Variables */
	searchBuffer += fromInteger;
	pcrePtr = ((sqInt) (fetchArrayofObject(2, rcvr)));
	/* begin rcvrExtraPtr */
	extraObj = fetchPointerofObject(3, rcvr);
	extraPtr = ((sqInt) ((!(extraObj == (nilObject()))
	? arrayValueOf(extraObj)
	: 0)));
	matchFlags = fetchIntegerofObject(6, rcvr);
	matchSpacePtr = ((int *) (fetchArrayofObject(7, rcvr)));
	matchSpaceSize = (byteSizeOf(fetchPointerofObject(7, rcvr))) / 4;
	if (failed()) {
		return null;
	}
	result = pcre_exec((pcre *)pcrePtr, (pcre_extra *)extraPtr, 
				searchBuffer, length, 0, matchFlags, matchSpacePtr, matchSpaceSize);
	pop(4);
	pushInteger(result);
		return 0;
}
Beispiel #5
0
primitiveSerialPortWrite(void)
{
	char *array;
	char * arrayPtr;
	sqInt bytesWritten;
	sqInt count;
	sqInt portNum;
	sqInt startIndex;
	sqInt _return_value;

	bytesWritten = 0;
	portNum = stackIntegerValue(3);
	success(isBytes(stackValue(2)));
	array = ((char *) (firstIndexableField(stackValue(2))));
	startIndex = stackIntegerValue(1);
	count = stackIntegerValue(0);
	if (failed()) {
		return null;
	}
	success((startIndex >= 1)
	 && (((startIndex + count) - 1) <= (byteSizeOf(((sqInt)(sqIntptr_t)(array) - BaseHeaderSize)))));
	if (!(failed())) {
		arrayPtr = (array + startIndex) - 1;
		bytesWritten = serialPortWriteFrom(portNum, count, arrayPtr);
	}
	if (failed()) {
		return null;
	}
	_return_value = integerObjectOf(bytesWritten);
	popthenPush(5, _return_value);
	return null;
}
primitiveDLSym(void)
{
    void *addr;
    sqInt i;
    char *name;
    sqInt nameObj;
    char *namePtr;
    sqInt sz;

	nameObj = stackValue(0);
	if (!(isBytes(nameObj))) {
		return primitiveFailFor(PrimErrBadArgument);
	}
	sz = byteSizeOf(nameObj);
	name = malloc(sz + 1);
	namePtr = firstIndexableField(nameObj);
	for (i = 0; i < sz; i += 1) {
		name[i] = (namePtr[i]);
	}
	name[sz] = 0;
	addr = dlsym(RTLD_SELF,name);
	free(name);
	return methodReturnValue((addr == 0
		? nilObject()
		: (/* begin positiveMachineIntegerFor: */
			(BytesPerWord == 8
					? positive64BitIntegerFor(((usqIntptr_t)addr))
					: positive32BitIntegerFor(((usqIntptr_t)addr))))));
}
primitiveSerialPortRead(void)
{
	// SerialPlugin>>#primitiveSerialPortRead
	char *array;
	sqInt arrayPtr;
	sqInt bytesRead;
	sqInt count;
	sqInt portNum;
	sqInt startIndex;
	sqInt _return_value;

	portNum = stackIntegerValue(3);
	success(isBytes(stackValue(2)));
	array = ((char *) (firstIndexableField(stackValue(2))));
	startIndex = stackIntegerValue(1);
	count = stackIntegerValue(0);
	if (failed()) {
		return null;
	}
	success((startIndex >= 1)
	 && (((startIndex + count) - 1) <= (byteSizeOf(((sqInt)(long)(array) - 4)))));
	arrayPtr = ((((sqInt)array)) + startIndex) - 1;
	bytesRead = serialPortReadInto( portNum, count, arrayPtr);
	_return_value = integerObjectOf(bytesRead);
	if (failed()) {
		return null;
	}
	popthenPush(5, _return_value);
	return null;
}
Beispiel #8
0
primitiveSetStringProperty(void)
{
    sqInt handle;
    sqInt propID;
    sqInt result;
    sqInt srcLen;
    sqInt srcOop;
    char *srcPtr;

    if (!((methodArgumentCount()) == 3)) {
        return primitiveFail();
    }
    srcOop = stackObjectValue(0);
    propID = stackIntegerValue(1);
    handle = stackIntegerValue(2);
    if (failed()) {
        return null;
    }
    if (!(isBytes(srcOop))) {
        return primitiveFail();
    }
    srcPtr = firstIndexableField(srcOop);
    srcLen = byteSizeOf(srcOop);
    result = sqSetStringPropertySSL(handle, propID, srcPtr, srcLen);
    if (!result) {
        return primitiveFail();
    }
    if (failed()) {
        return null;
    }
    pop(methodArgumentCount());
    return 0;
}
/*
  primitivePluginRequestUrlStream: url with: semaIndex
  Request a URL from the browser. Signal semaIndex
  when the result of the request can be queried.
  Returns a handle used in subsequent calls to plugin
  stream functions.
  Note: A request id is the index into requests[].
*/
int display_primitivePluginRequestURLStream()
{
    sqStreamRequest *req;
    int id, url, length, semaIndex;

    if (!inBrowser) return primitiveFail();

    DPRINT("VM: primitivePluginRequestURLStream()\n");

    for (id=0; id<MAX_REQUESTS; id++) {
        if (!requests[id]) break;
    }
    if (id >= MAX_REQUESTS) return primitiveFail();

    semaIndex= stackIntegerValue(0);
    url= stackObjectValue(1);
    if (failed()) return 0;

    if (!isBytes(url)) return primitiveFail();

    req= calloc(1, sizeof(sqStreamRequest));
    if (!req) return primitiveFail();
    req->localName= NULL;
    req->semaIndex= semaIndex;
    req->state= -1;
    requests[id]= req;

    length= byteSizeOf(url);
    browserGetURLRequest(id, firstIndexableField(url), length, NULL, 0);
    pop(3);
    push(positive32BitIntegerFor(id));
    DPRINT("VM:   request id: %i\n", id);
    return 1;
}
primitiveFileDelete(void)
{
	// FilePlugin>>#primitiveFileDelete
    char *nameIndex;
    sqInt namePointer;
    sqInt nameSize;
    sqInt okToDelete;

	namePointer = stackValue(0);
	if (!(isBytes(namePointer))) {
		return primitiveFail();
	}
	nameIndex = firstIndexableField(namePointer);

	/* If the security plugin can be loaded, use it to check for permission.
	   If not, assume it's ok */

	nameSize = byteSizeOf(namePointer);
	if (sCDFfn != 0) {
		okToDelete =  ((sqInt (*)(char *, sqInt))sCDFfn)(nameIndex, nameSize);
		if (!okToDelete) {
return primitiveFail();
		}
	}
	sqFileDeleteNameSize(nameIndex, nameSize);
	if (!(failed())) {
		pop(1);
	}
}
Beispiel #11
0
	/* AioPlugin>>#isSQSocketObject: */
static sqInt
isSQSocketObject(sqInt objectPointer)
{
	return ((isBytes(objectPointer))
	 && ((byteSizeOf(objectPointer)) == (sizeof(SQSocket))))
	 && (!(isNullSQSocket(objectPointer)));
}
primitiveGetMacintoshFileTypeAndCreatorFrom(void)
{
	char *aFileName;
	char creator[8];
	sqInt i;
	sqInt keyLength;
	sqInt oop;
	char *ptr;

	success(isBytes(stackValue(0)));
	aFileName = ((char *) (firstIndexableField(stackValue(0))));
	if (failed()) {
		return null;
	}
	keyLength = byteSizeOf(((sqInt)(sqIntptr_t)(aFileName) - BaseHeaderSize));
	sqInternetGetMacintoshFileTypeAndCreatorFromkeySizeinto(aFileName, keyLength, creator);
	oop = instantiateClassindexableSize(classString(), 8);
	ptr = firstIndexableField(oop);
	for (i = 0; i <= 7; i += 1) {
		ptr[i] = (creator[i]);
	}
	if (failed()) {
		return null;
	}
	popthenPush(2, oop);
	return null;
}
primitiveDirectoryDelete(void)
{
	// FilePlugin>>#primitiveDirectoryDelete
    sqInt dirName;
    char *dirNameIndex;
    sqInt dirNameSize;
    sqInt okToDelete;

	dirName = stackValue(0);
	if (!(isBytes(dirName))) {
		return primitiveFail();
	}
	dirNameIndex = firstIndexableField(dirName);

	/* If the security plugin can be loaded, use it to check for permission.
	   If not, assume it's ok */

	dirNameSize = byteSizeOf(dirName);
	if (sCDPfn != 0) {
		okToDelete =  ((sqInt (*)(char *, sqInt))sCDPfn)(dirNameIndex, dirNameSize);
		if (!okToDelete) {
return primitiveFail();
		}
	}
	if (!(dir_Delete(dirNameIndex, dirNameSize))) {
		return primitiveFail();
	}
	pop(1);
}
primitiveGetStringKeyedBy(void)
{
	char *aKey;
	char aString[1025];
	sqInt i;
	sqInt keyLength;
	sqInt oop;
	char *ptr;
	sqInt size;

	success(isBytes(stackValue(0)));
	aKey = ((char *) (firstIndexableField(stackValue(0))));
	if (failed()) {
		return null;
	}
	keyLength = byteSizeOf(((sqInt)(sqIntptr_t)(aKey) - BaseHeaderSize));
	size = sqInternetConfigurationGetStringKeyedBykeySizeinto(aKey, keyLength, aString);
	oop = instantiateClassindexableSize(classString(), size);
	ptr = firstIndexableField(oop);
	for (i = 0; i < size; i += 1) {
		ptr[i] = (aString[i]);
	}
	if (failed()) {
		return null;
	}
	popthenPush(2, oop);
	return null;
}
primitiveFileAtEnd(void)
{
	// FilePlugin>>#primitiveFileAtEnd
    sqInt atEnd;
    SQFile *file;
    sqInt objectPointer;

	/* begin fileValueOf: */
	objectPointer = stackValue(0);
	if (!((isBytes(objectPointer))
		 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
		primitiveFail();
		file = null;
		goto l1;
	}
	file = firstIndexableField(objectPointer);
l1:	/* end fileValueOf: */;
	if (!(failed())) {
		atEnd = sqFileAtEnd(file);
	}
	if (!(failed())) {
		pop(2);
		pushBool(atEnd);
	}
}
Beispiel #16
0
	/* AioPlugin>>#isSQFileObject: */
static sqInt
isSQFileObject(sqInt objectPointer)
{
	return (((isBytes(objectPointer))
	 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))
	 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(objectPointer)))))
	 && (isNonNullSQFile(objectPointer));
}
Beispiel #17
0
primitiveDisassembleAtInMemory(void)
{
	usqIntptr_t address;
	void *cpu;
	sqInt cpuAlien;
	sqInt instrLenOrErr;
	sqInt log;
	sqInt logLen;
	sqInt logObj;
	sqInt logObjData;
	char *memory;
	sqInt resultObj;

	logLen = 0;
	address = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	success(isWordsOrBytes(stackValue(0)));
	memory = ((char *) (firstIndexableField(stackValue(0))));
	cpuAlien = stackValue(2);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	instrLenOrErr = disassembleForAtInSize(cpu, address, memory, byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize)));
	if (instrLenOrErr < 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	log = getlog((&logLen));
	resultObj = instantiateClassindexableSize(classArray(), 2);
	if (resultObj == 0) {
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	pushRemappableOop(resultObj);
	logObj = instantiateClassindexableSize(classString(), logLen);
	if (failed()) {
		popRemappableOop();
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	logObjData = arrayValueOf(logObj);
	memcpy(logObjData, log, logLen);
	resultObj = popRemappableOop();
	storePointerofObjectwithValue(0, resultObj, integerObjectOf(instrLenOrErr));
	storePointerofObjectwithValue(1, resultObj, logObj);
	if (failed()) {
		return null;
	}
	popthenPush(3, resultObj);
	return null;
}
primitiveDirectoryGetMacTypeAndCreator(void)
{
	// FilePlugin>>#primitiveDirectoryGetMacTypeAndCreator
    sqInt creatorString;
    char *creatorStringIndex;
    sqInt fileName;
    char *fileNameIndex;
    sqInt fileNameSize;
    sqInt okToGet;
    sqInt typeString;
    char *typeStringIndex;

	creatorString = stackValue(0);
	typeString = stackValue(1);
	fileName = stackValue(2);
	if (!((isBytes(creatorString))
		 && ((byteSizeOf(creatorString)) == 4))) {
		return primitiveFail();
	}
	if (!((isBytes(typeString))
		 && ((byteSizeOf(typeString)) == 4))) {
		return primitiveFail();
	}
	if (!(isBytes(fileName))) {
		return primitiveFail();
	}
	creatorStringIndex = firstIndexableField(creatorString);
	typeStringIndex = firstIndexableField(typeString);
	fileNameIndex = firstIndexableField(fileName);

	/* If the security plugin can be loaded, use it to check for permission.
	   If not, assume it's ok */

	fileNameSize = byteSizeOf(fileName);
	if (sCGFTfn != 0) {
		okToGet =  ((sqInt (*)(char *, sqInt))sCGFTfn)(fileNameIndex, fileNameSize);
		if (!okToGet) {
return primitiveFail();
		}
	}
	if (!(dir_GetMacFileTypeAndCreator(fileNameIndex, fileNameSize, typeStringIndex, creatorStringIndex))) {
		return primitiveFail();
	}
	pop(3);
}
Beispiel #19
0
/*
  primitivePluginPostURL: url target: target data: data semaIndex: semaIndex
  Post data to a URL into the given target.
*/
int display_primitivePluginPostURL()
{
    sqStreamRequest *req;
    int url, urlLength;
    int target, targetLength;
    int data, dataLength;
    int id, semaIndex;

    if (!browserWindow) return primitiveFail();
    for (id=0; id<MAX_REQUESTS; id++) {
        if (!requests[id]) break;
    }

    if (id >= MAX_REQUESTS) return primitiveFail();

    semaIndex= stackIntegerValue(0);
    data= stackObjectValue(1);
    target= stackObjectValue(2);
    url= stackObjectValue(3);

    if (failed()) return 0;
    if (target == nilObject()) target= 0;
    if (!isBytes(url) || !isBytes(data) || !(!target || isBytes(target))) return primitiveFail();

    urlLength= byteSizeOf(url);
    targetLength= target ? byteSizeOf(target) : 0;
    dataLength= byteSizeOf(data);

    req= calloc(1, sizeof(sqStreamRequest));
    if(!req) return primitiveFail();
    req->localName= NULL;
    req->semaIndex= semaIndex;
    req->state= -1;
    requests[id]= req;

    browserPostURLRequest(id, firstIndexableField(url), urlLength,
                          target ? firstIndexableField(target) : NULL, targetLength,
                          firstIndexableField(data), dataLength);
    pop(4);
    push(positive32BitIntegerFor(id));
    return 1;
}
Beispiel #20
0
primitiveEncrypt(void)
{
    sqInt dstLen;
    sqInt dstOop;
    char *dstPtr;
    sqInt handle;
    sqInt result;
    sqInt srcLen;
    sqInt srcOop;
    char *srcPtr;
    sqInt start;

    if (!((methodArgumentCount()) == 5)) {
        return primitiveFail();
    }
    dstOop = stackObjectValue(0);
    srcLen = stackIntegerValue(1);
    start = stackIntegerValue(2);
    srcOop = stackObjectValue(3);
    handle = stackIntegerValue(4);
    if (failed()) {
        return null;
    }
    if (!(((start > 0)
            && (srcLen >= 0))
            && ((isBytes(srcOop))
                && ((isBytes(dstOop))
                    && ((byteSizeOf(srcOop)) >= ((start + srcLen) - 1)))))) {
        return primitiveFail();
    }
    srcPtr = firstIndexableField(srcOop);
    dstPtr = firstIndexableField(dstOop);
    srcPtr = (srcPtr + start) - 1;
    dstLen = byteSizeOf(dstOop);
    result = sqEncryptSSL(handle, srcPtr, srcLen, dstPtr, dstLen);
    if (failed()) {
        return null;
    }
    pop((methodArgumentCount()) + 1);
    pushInteger(result);
    return 0;
}
SQFile *
fileValueOf(sqInt objectPointer)
{
	// FilePlugin>>#fileValueOf:
	if (!((isBytes(objectPointer))
		 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
		primitiveFail();
		return null;
	}
	return firstIndexableField(objectPointer);
}
Beispiel #22
0
	/* AioPlugin>>#fileDescriptorFrom: */
static sqInt
fileDescriptorFrom(sqInt aSQFileByteArray)
{
	if (!((((isBytes(aSQFileByteArray))
		 && ((byteSizeOf(aSQFileByteArray)) == (sizeof(SQFile))))
		 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(aSQFileByteArray)))))
		 && (isNonNullSQFile(aSQFileByteArray)))) {
		return -1;
	}
	return fileno(fileHandleFrom(aSQFileByteArray));
}
Beispiel #23
0
primitiveSingleStepInMemoryMinAddressMaxAddressReadWrite(void)
{
	void *cpu;
	sqInt cpuAlien;
	usqIntptr_t maxAddress;
	sqInt maybeErr;
	char *memory;
	sqInt memorySize;
	usqIntptr_t minAddress;
	usqIntptr_t minWriteMaxExecAddress;

	success(isWordsOrBytes(stackValue(3)));
	memory = ((char *) (firstIndexableField(stackValue(3))));
	minAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(2))
		: positive64BitValueOf(stackValue(2)));
	maxAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	minWriteMaxExecAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(0))
		: positive64BitValueOf(stackValue(0)));
	cpuAlien = stackValue(4);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	prevInterruptCheckChain = setInterruptCheckChain(forceStopOnInterrupt);
	if (prevInterruptCheckChain == (forceStopOnInterrupt)) {
		prevInterruptCheckChain == 0;
	}
	memorySize = byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize));
	maybeErr = singleStepCPUInSizeMinAddressReadWrite(cpu, memory, ((memorySize < maxAddress) ? memorySize : maxAddress), minAddress, minWriteMaxExecAddress);
	setInterruptCheckChain(prevInterruptCheckChain);
	if (maybeErr != 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	if (failed()) {
		return null;
	}
	popthenPush(5, cpuAlien);
	return null;
}
primitiveFileRename(void)
{
	// FilePlugin>>#primitiveFileRename
    char *newNameIndex;
    sqInt newNamePointer;
    sqInt newNameSize;
    sqInt okToRename;
    char *oldNameIndex;
    sqInt oldNamePointer;
    sqInt oldNameSize;

	newNamePointer = stackValue(0);
	oldNamePointer = stackValue(1);
	if (!((isBytes(newNamePointer))
		 && (isBytes(oldNamePointer)))) {
		return primitiveFail();
	}
	newNameIndex = firstIndexableField(newNamePointer);
	newNameSize = byteSizeOf(newNamePointer);
	oldNameIndex = firstIndexableField(oldNamePointer);

	/* If the security plugin can be loaded, use it to check for rename permission.
	   If not, assume it's ok */

	oldNameSize = byteSizeOf(oldNamePointer);
	if (sCRFfn != 0) {
		okToRename =  ((sqInt (*)(char *, sqInt))sCRFfn)(oldNameIndex, oldNameSize);
		if (!okToRename) {
return primitiveFail();
		}
	}
	sqFileRenameOldSizeNewSize(oldNameIndex, oldNameSize, newNameIndex, newNameSize);
	if (!(failed())) {
		pop(2);
	}
}
primitiveFileRead(void)
{
	// FilePlugin>>#primitiveFileRead
    sqInt array;
    sqInt bytesRead;
    size_t count;
    size_t elementSize;
    SQFile *file;
    sqInt objectPointer;
    sqInt retryCount;
    size_t startIndex;

	retryCount = 0;
	count = positive32BitValueOf(stackValue(0));
	startIndex = positive32BitValueOf(stackValue(1));
	while (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);
		}
		bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
		if (!(((primitiveFailureCode()) == PrimErrObjectMayMove)
		 && (((retryCount += 1)) <= 2))) break;
		tenuringIncrementalGC();
		primitiveFailFor(PrimNoErr);
	}
	if (!(failed())) {
		popthenPush(5, integerObjectOf(bytesRead / elementSize));
	}
}
Beispiel #26
0
primitiveOSSocketHandle(void)
{
    int fileNo;
    sqInt sqSocketOop;

	sqSocketOop = stackValue(0);
	if (!(((isBytes(sqSocketOop))
		 && ((byteSizeOf(sqSocketOop)) == (sizeof(SQSocket))))
		 && (!(isNullSQSocket(sqSocketOop))))) {
		return primitiveFail();
	}
	fileNo = socketDescriptorFrom(sqSocketOop);
	if (fileNo < 0) {
		return primitiveFail();
	}
	pop(2);
	pushInteger(fileNo);
	return 0;
}
primitiveFileOpen(void)
{
	// FilePlugin>>#primitiveFileOpen
    sqInt filePointer;
    char *nameIndex;
    sqInt namePointer;
    sqInt nameSize;
    sqInt writeFlag;

	writeFlag = booleanValueOf(stackValue(0));
	namePointer = stackValue(1);
	if (!(isBytes(namePointer))) {
		return primitiveFail();
	}
	nameIndex = firstIndexableField(namePointer);
	nameSize = byteSizeOf(namePointer);
	filePointer = fileOpenNamesizewritesecure(nameIndex, nameSize, writeFlag, 1);
	if (!(failed())) {
		popthenPush(3, filePointer);
	}
}
fileOpenNamesizewritesecure(char *nameIndex, sqInt nameSize, sqInt writeFlag, sqInt secureFlag)
{
	// FilePlugin>>#fileOpenName:size:write:secure:
    SQFile *file;
    sqInt fileOop;
    sqInt okToOpen;

	fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile));
	/* begin fileValueOf: */
	if (!((isBytes(fileOop))
		 && ((byteSizeOf(fileOop)) == (sizeof(SQFile))))) {
		primitiveFail();
		file = null;
		goto l1;
	}
	file = firstIndexableField(fileOop);
l1:	/* end fileValueOf: */;
	if (!(failed())) {
		if (secureFlag) {

			/* If the security plugin can be loaded, use it to check for permission.
			   If not, assume it's ok */

			if (sCOFfn != 0) {

				/* If the security plugin can be loaded, use it to check for permission.
				   If not, assume it's ok */

				okToOpen = ((sqInt (*) (char *, sqInt, sqInt)) sCOFfn)(nameIndex, nameSize, writeFlag);
				if (!okToOpen) {
primitiveFail();
				}
			}
		}
	}
	if (!(failed())) {
		sqFileOpen(file, nameIndex, nameSize, writeFlag);
	}
	return fileOop;
}
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));
	}
}
Beispiel #30
0
primitiveSerialPortWriteByName(void)
{
	char *array;
	char * arrayPtr;
	sqInt bytesWritten;
	sqInt count;
	char *port;
	char *portName;
	sqInt portNameSize;
	sqInt startIndex;
	sqInt _return_value;

	bytesWritten = 0;
	success(isBytes(stackValue(3)));
	portName = ((char *) (firstIndexableField(stackValue(3))));
	success(isBytes(stackValue(2)));
	array = ((char *) (firstIndexableField(stackValue(2))));
	startIndex = stackIntegerValue(1);
	count = stackIntegerValue(0);
	if (failed()) {
		return null;
	}
	portNameSize = slotSizeOf(((sqInt)((portName) - BaseHeaderSize)));
	port = calloc(portNameSize+1, sizeof(char));
	memcpy(port, portName, portNameSize);
	success((startIndex >= 1)
	 && (((startIndex + count) - 1) <= (byteSizeOf(((sqInt)(sqIntptr_t)(array) - BaseHeaderSize)))));
	if (!(failed())) {
		arrayPtr = (array + startIndex) - 1;
		bytesWritten = serialPortWriteFromByName(port, count, arrayPtr);
	}
	free(port);
	if (failed()) {
		return null;
	}
	_return_value = integerObjectOf(bytesWritten);
	popthenPush(5, _return_value);
	return null;
}