-
Notifications
You must be signed in to change notification settings - Fork 65
/
faCommon.c
125 lines (94 loc) · 2.26 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* faCommon.c
*
* Provides a number of platform independent functions for FileAttributesPlugin.
*/
#include "sq.h"
#include "faCommon.h"
extern struct VirtualMachine * interpreterProxy;
int vmSessionId = 0;
/*
* faInitialiseModule
*
* Initialise global data for the FileAttributesPlugin.
*
* This function must be called only once each each time the VM is run.
*/
sqInt faInitialiseModule()
{
if (vmSessionId == 0)
return interpreterProxy->falseObject();
vmSessionId = interpreterProxy->getThisSessionID();
return interpreterProxy->trueObject();
}
/*
* faInitSessionId
*
* Initialise the supplied session.
*/
sqInt faInitSessionId(int *sessionId)
{
*sessionId = vmSessionId;
return FA_SUCCESS;
}
/*
* faValidateSessionId
*
* Check that the supplied faPath structure looks valid.
*
* Currently this is just checking that the sessionId is correct.
*/
sqInt faValidateSessionId(int sessionId)
{
return sessionId == vmSessionId;
}
/*
* faInvalidateSessionId
*
* Mark the supplied faPath structure as invalid.
*/
sqInt faInvalidateSessionId(int *sessionId)
{
*sessionId = 0;
return FA_SUCCESS;
}
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;
}