FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CodenameOne/vm/ByteCodeTranslator/src/java_io_File.m at master · codenameone/CodenameOne · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
codenameone
/
CodenameOne
Public
Notifications
You must be signed in to change notification settings
Fork
434
Star
1.9k
Code
Issues
263
Pull requests
5
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
CodenameOne
/
vm
/
ByteCodeTranslator
/
src
/
java_io_File.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
530 lines (472 loc) · 22.7 KB
Breadcrumbs
CodenameOne
/
vm
/
ByteCodeTranslator
/
src
/
java_io_File.m
Copy path
File metadata and controls
530 lines (472 loc) · 22.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*
* Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
#
include
"
cn1_globals.h
"
#
include
"
java_io_File.h
"
#
include
"
java_lang_String.h
"
#
if
defined(__APPLE__) && defined(__OBJC__)
#
import
<
Foundation/Foundation.h
>
//
realpath and PATH_MAX, named rather than left to whatever Foundation happens to pull in.
#
include
<
limits.h
>
#
include
<
stdlib.h
>
#
include
<
string.h
>
JAVA_BOOLEAN
java_io_File_existsImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
fileExistsAtPath:
p];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_isDirectoryImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
isDir =
NO
;
BOOL
exists = [[
NSFileManager
defaultManager
]
fileExistsAtPath:
p
isDirectory:
&isDir];
[pool
release
];
return
exists && isDir;
}
JAVA_BOOLEAN
java_io_File_isFileImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
isDir =
NO
;
BOOL
exists = [[
NSFileManager
defaultManager
]
fileExistsAtPath:
p
isDirectory:
&isDir];
[pool
release
];
return
exists && !isDir;
}
JAVA_BOOLEAN
java_io_File_isHiddenImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
hidden = [[p
lastPathComponent
]
hasPrefix:
@"
.
"
];
[pool
release
];
return
hidden;
}
JAVA_LONG
java_io_File_lastModifiedImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
0
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSDictionary
*attrs = [[
NSFileManager
defaultManager
]
attributesOfItemAtPath:
p
error:
NULL
];
JAVA_LONG
time =
0
;
if
(attrs) {
NSDate
*date = [attrs
fileModificationDate
];
time = (
JAVA_LONG
)([date
timeIntervalSince1970
] *
1000
);
}
[pool
release
];
return
time;
}
JAVA_LONG
java_io_File_lengthImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
0
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSDictionary
*attrs = [[
NSFileManager
defaultManager
]
attributesOfItemAtPath:
p
error:
NULL
];
JAVA_LONG
len =
0
;
if
(attrs) {
len = [attrs
fileSize
];
}
[pool
release
];
return
len;
}
JAVA_BOOLEAN
java_io_File_createNewFileImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
createFileAtPath:
p
contents:
nil
attributes:
nil
];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_deleteImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
removeItemAtPath:
p
error:
NULL
];
[pool
release
];
return
res;
}
JAVA_OBJECT
java_io_File_listImpl___java_lang_String_R_java_lang_String_1ARRAY
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_NULL
;
enteringNativeAllocations
();
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSArray
* files = [[
NSFileManager
defaultManager
]
contentsOfDirectoryAtPath:
p
error:
NULL
];
if
(files ==
nil
) {
[pool
release
];
finishedNativeAllocations
();
return
JAVA_NULL
;
}
JAVA_OBJECT
arr =
allocArray
(threadStateData, [files
count
], &class__java_lang_String,
sizeof
(
JAVA_OBJECT
),
1
);
for
(
int
i=
0
; i<[files
count
]; i++) {
NSString
* f = [files
objectAtIndex:
i];
JAVA_OBJECT
s =
fromNSString
(
CN1_THREAD_STATE_PASS_ARG
f);
CN1_SET_ARRAY_ELEMENT_OBJECT
(arr, i, s);
}
[pool
release
];
finishedNativeAllocations
();
return
arr;
}
JAVA_BOOLEAN
java_io_File_mkdirImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
createDirectoryAtPath:
p
withIntermediateDirectories:
NO
attributes:
nil
error:
NULL
];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_renameToImpl___java_lang_String_java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_OBJECT
dest) {
if
(path ==
JAVA_NULL
|| dest ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSString
* d =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
dest);
BOOL
res = [[
NSFileManager
defaultManager
]
moveItemAtPath:
p
toPath:
d
error:
NULL
];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_setReadOnlyImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSDictionary
* attrs = [
NSDictionary
dictionaryWithObject:
[
NSNumber
numberWithBool:
YES
]
forKey:
NSFileImmutable
];
BOOL
res = [[
NSFileManager
defaultManager
]
setAttributes:
attrs
ofItemAtPath:
p
error:
NULL
];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_setWritableImpl___java_lang_String_boolean_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_BOOLEAN
writable) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSDictionary
* attrs = [
NSDictionary
dictionaryWithObject:
[
NSNumber
numberWithBool:
(!writable)]
forKey:
NSFileImmutable
];
BOOL
res = [[
NSFileManager
defaultManager
]
setAttributes:
attrs
ofItemAtPath:
p
error:
NULL
];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_setReadableImpl___java_lang_String_boolean_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_BOOLEAN
readable) {
//
Basic implementation for iOS/sandbox (mostly ignored/always true if exists)
return
java_io_File_existsImpl___java_lang_String_R_boolean
(threadStateData, __cn1ThisObject, path);
}
JAVA_BOOLEAN
java_io_File_setExecutableImpl___java_lang_String_boolean_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_BOOLEAN
executable) {
return
java_io_File_existsImpl___java_lang_String_R_boolean
(threadStateData, __cn1ThisObject, path);
}
JAVA_BOOLEAN
java_io_File_canReadImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
isReadableFileAtPath:
p];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_canWriteImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
isWritableFileAtPath:
p];
[pool
release
];
return
res;
}
JAVA_BOOLEAN
java_io_File_canExecuteImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
#
ifdef
CN1_ENABLE_FILE_SYSTEM_STATS
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
BOOL
res = [[
NSFileManager
defaultManager
]
isExecutableFileAtPath:
p];
[pool
release
];
return
res;
#
else
return
java_io_File_existsImpl___java_lang_String_R_boolean
(threadStateData, __cn1ThisObject, path);
#
endif
}
JAVA_LONG
java_io_File_getTotalSpaceImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
#
ifdef
CN1_ENABLE_FILE_SYSTEM_STATS
if
(path ==
JAVA_NULL
)
return
0
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSDictionary
*attrs = [[
NSFileManager
defaultManager
]
attributesOfFileSystemForPath:
p
error:
NULL
];
JAVA_LONG
size =
0
;
if
(attrs) {
size = [[attrs
objectForKey:
NSFileSystemSize
]
longLongValue
];
}
[pool
release
];
return
size;
#
else
return
0
;
#
endif
}
JAVA_LONG
java_io_File_getFreeSpaceImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
#
ifdef
CN1_ENABLE_FILE_SYSTEM_STATS
if
(path ==
JAVA_NULL
)
return
0
;
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSDictionary
*attrs = [[
NSFileManager
defaultManager
]
attributesOfFileSystemForPath:
p
error:
NULL
];
JAVA_LONG
size =
0
;
if
(attrs) {
size = [[attrs
objectForKey:
NSFileSystemFreeSize
]
longLongValue
];
}
[pool
release
];
return
size;
#
else
return
0
;
#
endif
}
JAVA_LONG
java_io_File_getUsableSpaceImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
return
java_io_File_getFreeSpaceImpl___java_lang_String_R_long
(threadStateData, __cn1ThisObject, path);
}
JAVA_OBJECT
java_io_File_getAbsolutePathImpl___java_lang_String_R_java_lang_String
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_NULL
;
enteringNativeAllocations
();
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSString
* absPath;
if
([p
isAbsolutePath
]) {
absPath = p;
}
else
{
NSString
* cwd = [[
NSFileManager
defaultManager
]
currentDirectoryPath
];
absPath = [cwd
stringByAppendingPathComponent:
p];
}
JAVA_OBJECT
res =
fromNSString
(
CN1_THREAD_STATE_PASS_ARG
absPath);
[pool
release
];
finishedNativeAllocations
();
return
res;
}
JAVA_OBJECT
java_io_File_getCanonicalPathImpl___java_lang_String_R_java_lang_String
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_NULL
;
enteringNativeAllocations
();
NSAutoreleasePool
* pool = [[
NSAutoreleasePool
alloc
]
init
];
NSString
* p =
toNSString
(
CN1_THREAD_STATE_PASS_ARG
path);
NSString
* absPath;
if
([p
isAbsolutePath
]) {
absPath = p;
}
else
{
NSString
* cwd = [[
NSFileManager
defaultManager
]
currentDirectoryPath
];
absPath = [cwd
stringByAppendingPathComponent:
p];
}
//
realpath first, which is what getCanonicalPath is specified to do and what the platform
//
itself resolves a path to. -stringByStandardizingPath is neither: it leaves a symbolic
//
link in the middle of a path alone, and it rewrites /private/tmp and /private/var back to
//
/tmp and /var -- the opposite direction from every other resolver on the system. SQLite
//
reports the realpath form for an attached database, so a key built from the standardized
//
form named a file the engine had never heard of.
//
//
Falls back for a path that does not exist yet, where realpath cannot answer at all.
NSString
* canon =
nil
;
char
resolved[
PATH_MAX
];
const
char
* utf8 = [absPath
fileSystemRepresentation
];
if
(utf8 !=
NULL
&&
realpath
(utf8, resolved) !=
NULL
) {
canon = [[
NSFileManager
defaultManager
]
stringWithFileSystemRepresentation:
resolved
length:
strlen
(resolved)];
}
if
(canon ==
nil
) {
canon = [absPath
stringByStandardizingPath
];
}
JAVA_OBJECT
res =
fromNSString
(
CN1_THREAD_STATE_PASS_ARG
canon);
[pool
release
];
finishedNativeAllocations
();
return
res;
}
#
else
//
POSIX implementation for non-ObjC environments (e.g. Linux CI)
#
include
<
stdio.h
>
#
include
<
sys/stat.h
>
#
include
<
unistd.h
>
#
include
<
dirent.h
>
#
include
<
string.h
>
#
include
<
limits.h
>
//
Helper: assumes stringToUTF8 is available (implemented in test stubs or runtime)
extern
const
char
*
stringToUTF8
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
str);
extern
JAVA_OBJECT
newStringFromCString
(
CODENAME_ONE_THREAD_STATE
,
const
char
*str);
JAVA_BOOLEAN
java_io_File_existsImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
return
access
(p,
F_OK
) != -
1
;
}
JAVA_BOOLEAN
java_io_File_isDirectoryImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
struct
stat s;
if
(
stat
(p, &s) ==
0
) {
return
S_ISDIR
(s.
st_mode
);
}
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_isFileImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
struct
stat s;
if
(
stat
(p, &s) ==
0
) {
return
S_ISREG
(s.
st_mode
);
}
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_isHiddenImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
//
This is a naive check, checking if filename starts with dot
//
We need to find the last slash
const
char
* lastSlash =
strrchr
(p,
'
/
'
);
const
char
* name = lastSlash ? lastSlash +
1
: p;
return
name[
0
] ==
'
.
'
;
}
JAVA_LONG
java_io_File_lastModifiedImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
0
;
const
char
* p =
stringToUTF8
(threadStateData, path);
struct
stat s;
if
(
stat
(p, &s) ==
0
) {
#
ifdef
__APPLE__
return
(
JAVA_LONG
)s.
st_mtimespec
.
tv_sec
*
1000
;
#
else
return
(
JAVA_LONG
)s.
st_mtime
*
1000
;
#
endif
}
return
0
;
}
JAVA_LONG
java_io_File_lengthImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
0
;
const
char
* p =
stringToUTF8
(threadStateData, path);
struct
stat s;
if
(
stat
(p, &s) ==
0
) {
return
(
JAVA_LONG
)s.
st_size
;
}
return
0
;
}
JAVA_BOOLEAN
java_io_File_createNewFileImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
if
(
access
(p,
F_OK
) != -
1
)
return
JAVA_FALSE
;
FILE
* f =
fopen
(p,
"
w
"
);
if
(f) {
fclose
(f);
return
JAVA_TRUE
;
}
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_deleteImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
if
(
remove
(p) ==
0
)
return
JAVA_TRUE
;
return
JAVA_FALSE
;
}
JAVA_OBJECT
java_io_File_listImpl___java_lang_String_R_java_lang_String_1ARRAY
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_NULL
;
enteringNativeAllocations
();
const
char
* p =
stringToUTF8
(threadStateData, path);
DIR
* d =
opendir
(p);
if
(d ==
NULL
) {
finishedNativeAllocations
();
return
JAVA_NULL
;
}
//
First count
int
count =
0
;
struct
dirent *dir;
while
((dir =
readdir
(d)) !=
NULL
) {
if
(
strcmp
(dir->
d_name
,
"
.
"
) ==
0
||
strcmp
(dir->
d_name
,
"
..
"
) ==
0
)
continue
;
count++;
}
closedir
(d);
JAVA_OBJECT
arr =
allocArray
(threadStateData, count, &class__java_lang_String,
sizeof
(
JAVA_OBJECT
),
1
);
d =
opendir
(p);
count =
0
;
while
((dir =
readdir
(d)) !=
NULL
) {
if
(
strcmp
(dir->
d_name
,
"
.
"
) ==
0
||
strcmp
(dir->
d_name
,
"
..
"
) ==
0
)
continue
;
JAVA_OBJECT
s =
newStringFromCString
(threadStateData, dir->
d_name
);
CN1_SET_ARRAY_ELEMENT_OBJECT
(arr, count, s);
count++;
}
closedir
(d);
finishedNativeAllocations
();
return
arr;
}
JAVA_BOOLEAN
java_io_File_mkdirImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
#
ifdef
_WIN32
if
(
mkdir
(p) ==
0
)
return
JAVA_TRUE
;
#
else
if
(
mkdir
(p,
0755
) ==
0
)
return
JAVA_TRUE
;
#
endif
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_renameToImpl___java_lang_String_java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_OBJECT
dest) {
if
(path ==
JAVA_NULL
|| dest ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
const
char
* d =
stringToUTF8
(threadStateData, dest);
if
(
rename
(p, d) ==
0
)
return
JAVA_TRUE
;
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_setReadOnlyImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
return
JAVA_FALSE
;
//
Not implemented for POSIX here
}
JAVA_BOOLEAN
java_io_File_setWritableImpl___java_lang_String_boolean_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_BOOLEAN
writable) {
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_setReadableImpl___java_lang_String_boolean_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_BOOLEAN
readable) {
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_setExecutableImpl___java_lang_String_boolean_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path,
JAVA_BOOLEAN
executable) {
return
JAVA_FALSE
;
}
JAVA_BOOLEAN
java_io_File_canReadImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
return
access
(p,
R_OK
) != -
1
;
}
JAVA_BOOLEAN
java_io_File_canWriteImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
return
access
(p,
W_OK
) != -
1
;
}
JAVA_BOOLEAN
java_io_File_canExecuteImpl___java_lang_String_R_boolean
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_FALSE
;
const
char
* p =
stringToUTF8
(threadStateData, path);
return
access
(p,
X_OK
) != -
1
;
}
JAVA_LONG
java_io_File_getTotalSpaceImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
return
0
;
}
JAVA_LONG
java_io_File_getFreeSpaceImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
return
0
;
}
JAVA_LONG
java_io_File_getUsableSpaceImpl___java_lang_String_R_long
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
return
0
;
}
JAVA_OBJECT
java_io_File_getAbsolutePathImpl___java_lang_String_R_java_lang_String
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_NULL
;
const
char
* p =
stringToUTF8
(threadStateData, path);
if
(p[
0
] ==
'
/
'
)
return
path;
char
buf[
PATH_MAX
];
if
(
getcwd
(buf,
sizeof
(buf)) !=
NULL
) {
strcat
(buf,
"
/
"
);
strcat
(buf, p);
return
newStringFromCString
(threadStateData, buf);
}
return
path;
}
JAVA_OBJECT
java_io_File_getCanonicalPathImpl___java_lang_String_R_java_lang_String
(
CODENAME_ONE_THREAD_STATE
,
JAVA_OBJECT
__cn1ThisObject,
JAVA_OBJECT
path) {
if
(path ==
JAVA_NULL
)
return
JAVA_NULL
;
const
char
* p =
stringToUTF8
(threadStateData, path);
char
buf[
PATH_MAX
];
if
(
realpath
(p, buf) !=
NULL
) {
return
newStringFromCString
(threadStateData, buf);
}
//
Fallback
return
java_io_File_getAbsolutePathImpl___java_lang_String_R_java_lang_String
(threadStateData, __cn1ThisObject, path);
}
#
endif
Back
|
FazBrowse Home
|
New Git URL