File: ref.c

package info (click to toggle)
eclipse-platform-resources 4.10-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,584 kB
  • sloc: java: 96,534; xml: 1,812; ansic: 870; makefile: 37
file content (311 lines) | stat: -rw-r--r-- 10,341 bytes parent folder | download | duplicates (4)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*******************************************************************************
 * Copyright (c) 2005, 2016 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Mikael Barbero (Eclipse Foundation) - 286681 handle WAIT_ABANDONED_0 return value
 *******************************************************************************/
#include <windows.h>
#include "ref.h"

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FindFirstChangeNotificationW
 * Signature: (Ljava/lang/String;ZI)J
 */
JNIEXPORT jlong JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FindFirstChangeNotificationW
(JNIEnv * env, jclass this, jstring lpPathName, jboolean bWatchSubtree, jint dwNotifyFilter) {
	jlong result;
	jsize numberOfChars;
	jchar *path;
	const jchar *temp;

	// create a new byte array to hold the prefixed and null terminated path
	numberOfChars= (*env)->GetStringLength(env, lpPathName);
	path= malloc((numberOfChars + 5) * sizeof(jchar));
	//path= malloc((numberOfChars + 4) * sizeof(jchar));

	// get the path characters from the vm, copy them, and release them
	temp= (*env)->GetStringChars(env, lpPathName, JNI_FALSE);
	memcpy(path + 4, temp, numberOfChars * sizeof(jchar));
	(*env)->ReleaseStringChars(env, lpPathName, temp);

	// prefix the path to enable long filenames, and null terminate it
	path[0] = L'\\';
	path[1] = L'\\';
	path[2] = L'?';
	path[3] = L'\\';
	path[(numberOfChars + 4)] = L'\0';

	// make the request and free the memory
	//printf("%S\n", path);
	result = (jlong) FindFirstChangeNotificationW(path, bWatchSubtree, dwNotifyFilter);
	free(path);
	
	return result;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FindFirstChangeNotificationA
 * Signature: ([BZI)J
 */
JNIEXPORT jlong JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FindFirstChangeNotificationA
(JNIEnv * env, jclass this, jbyteArray lpPathName, jboolean bWatchSubtree, jint dwNotifyFilter) {
	jlong result;
	jsize numberOfChars;
	jbyte *path, *temp;
	
	// create a new byte array to hold the null terminated path
	numberOfChars = (*env)->GetArrayLength(env, lpPathName);
	path = malloc((numberOfChars + 1) * sizeof(jbyte));

	// get the path bytes from the vm, copy them, and release them
	temp = (*env)->GetByteArrayElements(env, lpPathName, 0);
	memcpy(path, temp, numberOfChars * sizeof(jbyte));
	(*env)->ReleaseByteArrayElements(env, lpPathName, temp, 0);

	// null terminate the path, make the request, and release the path memory
	path[numberOfChars] = '\0';
	result = (jlong) FindFirstChangeNotificationA(path, bWatchSubtree, dwNotifyFilter);
	free(path);

	return result;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FindCloseChangeNotification
 * Signature: (J)Z
 */
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FindCloseChangeNotification
(JNIEnv *env, jclass this, jlong hChangeHandle){
	return (jboolean) FindCloseChangeNotification((HANDLE) hChangeHandle);
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FindNextChangeNotification
 * Signature: (J)Z
 */
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FindNextChangeNotification
(JNIEnv *env, jclass this, jlong hChangeHandle){
	return (jboolean) FindNextChangeNotification((HANDLE) hChangeHandle);
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    WaitForMultipleObjects
 * Signature: (I[JZI)I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_WaitForMultipleObjects
(JNIEnv *env, jclass this, jint nCount, jlongArray lpHandles, jboolean bWaitAll, jint dwMilliseconds) {
	int i;
	jint result;
	HANDLE handles[MAXIMUM_WAIT_OBJECTS];
	jlong *handlePointers = (*env)->GetLongArrayElements(env, lpHandles, 0);

	for (i = 0; i < nCount; i++) {
		handles[i] = (HANDLE) handlePointers[i];
	}

	result = WaitForMultipleObjects(nCount, handles, bWaitAll, dwMilliseconds);
	(*env)->ReleaseLongArrayElements(env, lpHandles, handlePointers, 0);

	return result;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    IsUnicode
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_IsUnicode
  (JNIEnv *env, jclass this) {
  	OSVERSIONINFO osvi;
  	memset(&osvi, 0, sizeof(OSVERSIONINFO));
  	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  	if (! GetVersionEx (&osvi) ) 
    	return JNI_FALSE;
    if (osvi.dwMajorVersion >= 5)
    	return JNI_TRUE;
    return JNI_FALSE;
}
  
/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    GetLastError
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_GetLastError
(JNIEnv *env, jclass this){
	return GetLastError();
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FILE_NOTIFY_CHANGE_LAST_WRITE
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FILE_1NOTIFY_1CHANGE_1LAST_1WRITE
(JNIEnv *env, jclass this) {
	return FILE_NOTIFY_CHANGE_LAST_WRITE;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FILE_NOTIFY_CHANGE_DIR_NAME
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FILE_1NOTIFY_1CHANGE_1DIR_1NAME
(JNIEnv *env, jclass this) {
	return FILE_NOTIFY_CHANGE_DIR_NAME;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FILE_NOTIFY_CHANGE_ATTRIBUTES
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FILE_1NOTIFY_1CHANGE_1ATTRIBUTES
(JNIEnv *env, jclass this) {
	return FILE_NOTIFY_CHANGE_ATTRIBUTES;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FILE_NOTIFY_CHANGE_SIZE
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FILE_1NOTIFY_1CHANGE_1SIZE
(JNIEnv *env, jclass this) {
	return FILE_NOTIFY_CHANGE_SIZE;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FILE_NOTIFY_CHANGE_FILE_NAME
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FILE_1NOTIFY_1CHANGE_1FILE_1NAME
(JNIEnv *env, jclass this) {
	return FILE_NOTIFY_CHANGE_FILE_NAME;
}


/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    FILE_NOTIFY_CHANGE_SECURITY
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_FILE_1NOTIFY_1CHANGE_1SECURITY
(JNIEnv *env, jclass this) {
	return FILE_NOTIFY_CHANGE_SECURITY;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    MAXIMUM_WAIT_OBJECTS
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_MAXIMUM_1WAIT_1OBJECTS
(JNIEnv *env, jclass this) {
	return MAXIMUM_WAIT_OBJECTS;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    MAX_PATH
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_MAX_1PATH
(JNIEnv *env, jclass this) {
	return MAX_PATH;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    INFINITE
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_INFINITE
(JNIEnv *env, jclass this) {
	return INFINITE;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    WAIT_OBJECT_0
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_WAIT_1OBJECT_10
(JNIEnv *env, jclass this) {
	return WAIT_OBJECT_0;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    WAIT_ABANDONED_0
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_WAIT_1ABANDONED_10
(JNIEnv *env, jclass this) {
	return WAIT_ABANDONED_0;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    WAIT_FAILED
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_WAIT_1FAILED
(JNIEnv *env, jclass this) {
	return WAIT_FAILED;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    WAIT_TIMEOUT
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_WAIT_1TIMEOUT
(JNIEnv *env, jclass this) {
	return WAIT_TIMEOUT;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    ERROR_INVALID_HANDLE
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_ERROR_1INVALID_1HANDLE
(JNIEnv *env, jclass this) {
	return ERROR_INVALID_HANDLE;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    ERROR_SUCCESS
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_ERROR_1SUCCESS
(JNIEnv *env, jclass this) {
	return ERROR_SUCCESS;
}

/*
 * Class:     org_eclipse_core_internal_resources_refresh_win32_Win32Natives
 * Method:    INVALID_HANDLE_VALUE
 * Signature: ()J
 */
JNIEXPORT jlong JNICALL Java_org_eclipse_core_internal_resources_refresh_win32_Win32Natives_INVALID_1HANDLE_1VALUE
(JNIEnv * env, jclass this) {
	return (jlong)INVALID_HANDLE_VALUE;
}