/
faCommon.c
67 lines (48 loc) · 1.32 KB
/
faCommon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* faCommon.c
*
* Provides a number of platform independent functions.
*/
#include "sq.h"
#include "faCommon.h"
extern struct VirtualMachine * interpreterProxy;
sqInt faSetStDirOop(fapath *aFaPath, sqInt pathNameOop)
{
int len;
char *pathName;
len = interpreterProxy->stSizeOf(pathNameOop);
pathName = interpreterProxy->arrayValueOf(pathNameOop);
return faSetStDir(aFaPath, pathName, len);
}
sqInt faSetStPathOop(fapath *aFaPath, sqInt pathNameOop)
{
int len;
char *pathName;
len = interpreterProxy->stSizeOf(pathNameOop);
pathName = interpreterProxy->arrayValueOf(pathNameOop);
return faSetStPath(aFaPath, pathName, len);
}
/*
* faCharToByteArray
*
* Copy the supplied C string to a newly allocated ByteArray
*/
sqInt faCharToByteArray(const char *cBuf, sqInt *byteArrayOop)
{
unsigned char *byteArrayPtr;
sqInt len;
sqInt newByteArray;
/* We never return strings longer than PATH_MAX */
len = strlen(cBuf);
if (len >= FA_PATH_MAX) {
return -1 /* stringTooLong */;
}
newByteArray = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classByteArray(), len);
if (!(newByteArray)) {
return interpreterProxy->primitiveFailFor(PrimErrNoMemory);
}
byteArrayPtr = interpreterProxy->arrayValueOf(newByteArray);
memcpy(byteArrayPtr, cBuf, len);
byteArrayOop[0] = newByteArray;
return 0;
}