forked from gabordemooij/citrine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.c
657 lines (636 loc) · 19.9 KB
/
file.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
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <time.h>
#include <errno.h>
#include <sys/file.h>
#include <dirent.h>
#include "citrine.h"
#include "siphash.h"
/**
* File
*
* Represents a File object.
* Creates a new file object based on the specified path.
*
* Usage:
*
* File new: '/example/path/to/file.txt'.
*/
ctr_object* ctr_file_new(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* s = ctr_object_make(myself, argumentList);
ctr_object* pathObject;
s->info.type = CTR_OBJECT_TYPE_OTEX; /* indicates resource for GC */
s->link = myself;
s->value.rvalue = NULL;
pathObject = ctr_build_string( argumentList->object->value.svalue->value, argumentList->object->value.svalue->vlen );
ctr_internal_object_add_property( s, ctr_build_string_from_cstring( "path" ), pathObject, 0 );
return s;
}
/**
* [File] path
*
* Returns the path of a file. The file object will respond to this
* message by returning a string object describing the full path to the
* recipient.
*/
ctr_object* ctr_file_path(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
if (path == NULL) return CtrStdNil;
return path;
}
/**
* [File] toString
*
* Returns a string representation of the file. If a path has been associated
* with this file, this message will return the path of the file on the file system.
* If no path has been associated with the file, the string [File (no path)] will
* be returned.
*/
ctr_object* ctr_file_to_string(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* path = ctr_file_path(myself,argumentList);
if ( path == CtrStdNil) {
return ctr_build_string_from_cstring("[File (no path)]");
}
return ctr_internal_cast2string(path);
}
/**
* [File] read
*
* Reads contents of a file. Send this message to a file to read the entire contents in
* one go. For big files you might want to prefer a streaming approach to avoid
* memory exhaustion (see readBytes etc).
*
* Usage:
*
* data := File new: '/path/to/mydata.csv', read.
*
* In the example above we read the contents of the entire CSV file callled mydata.csv
* in the variable called data.
*/
ctr_object* ctr_file_read(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
ctr_object* str;
ctr_size vlen, fileLen;
char* pathString;
char *buffer;
FILE* f;
int error_code;
if (path == NULL) return CtrStdNil;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate( sizeof(char) * ( vlen + 1 ) );
memcpy(pathString, path->value.svalue->value, vlen);
memcpy(pathString+vlen,"\0",1);
f = fopen(pathString, "rb");
error_code = errno;
ctr_heap_free( pathString );
if (!f) {
ctr_error( "Unable to open file: %s.", error_code );
return CtrStdNil;
}
fseek(f, 0, SEEK_END);
fileLen=ftell(f);
fseek(f, 0, SEEK_SET);
buffer=(char *)ctr_heap_allocate(fileLen+1);
if (!buffer){
fprintf(stderr,"Out of memory\n");
fclose(f);exit(1);
}
fread(buffer, fileLen, 1, f);
fclose(f);
str = ctr_build_string(buffer, fileLen);
ctr_heap_free( buffer );
return str;
}
/**
* [File] write: [String]
*
* Writes content to a file. Send this message to a file object to write the
* entire contents of the specified string to the file in one go. The file object
* responds to this message for convience reasons, however for big files it might
* be a better idea to use the streaming API if possible (see readBytes etc.).
*
* data := '<xml>hello</xml>'.
* File new: 'myxml.xml', write: data.
*
* In the example above we write the XML snippet in variable data to a file
* called myxml.xml in the current working directory.
*/
ctr_object* ctr_file_write(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_FILE_WRITE );
ctr_object* str = ctr_internal_cast2string(argumentList->object);
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0 );
FILE* f;
ctr_size vlen;
char* pathString;
int error_code;
if (path == NULL) return CtrStdNil;
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate(vlen + 1);
memcpy(pathString, path->value.svalue->value, vlen);
memcpy(pathString+vlen,"\0",1);
f = fopen(pathString, "wb+");
error_code = errno;
ctr_heap_free( pathString );
if (!f) {
CtrStdFlow = ctr_error( "Unable to open file: %s.", error_code );
return CtrStdNil;
}
fwrite(str->value.svalue->value, sizeof(char), str->value.svalue->vlen, f);
fclose(f);
return myself;
}
/**
* [File] append: [String]
*
* Appends content to a file. The file object responds to this message like it
* responds to the write-message, however in this case the contents of the string
* will be appended to the existing content inside the file.
*/
ctr_object* ctr_file_append(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_FILE_WRITE );
ctr_object* str = ctr_internal_cast2string(argumentList->object);
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
ctr_size vlen;
char* pathString;
FILE* f;
if (path == NULL) return myself;
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate(vlen + 1);
memcpy(pathString, path->value.svalue->value, vlen);
memcpy(pathString+vlen,"\0",1);
f = fopen(pathString, "ab+");
ctr_heap_free( pathString );
if (!f) {
CtrStdFlow = ctr_build_string_from_cstring("Unable to open file.\0");
CtrStdFlow->info.sticky = 1;
return CtrStdNil;
}
fwrite(str->value.svalue->value, sizeof(char), str->value.svalue->vlen, f);
fclose(f);
return myself;
}
/**
* [File] exists
*
* Returns True if the file exists and False otherwise.
*/
ctr_object* ctr_file_exists(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
ctr_size vlen;
char* pathString;
FILE* f;
int exists;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (path == NULL) return ctr_build_bool(0);
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate(vlen + 1);
memcpy(pathString, path->value.svalue->value, vlen);
memcpy(pathString+vlen,"\0",1);
f = fopen(pathString, "r");
ctr_heap_free( pathString );
exists = (f != NULL );
if (f) {
fclose(f);
}
return ctr_build_bool(exists);
}
/**
* [File] include
*
* Includes the file as a piece of executable code.
*/
ctr_object* ctr_file_include(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_INCLUDE );
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
ctr_tnode* parsedCode;
ctr_size vlen;
char* pathString;
char* prg;
uint64_t program_size = 0;
if (path == NULL) return myself;
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate_tracked(sizeof(char)*(vlen+1)); //needed until end, pathString appears in stracktrace
memcpy(pathString, path->value.svalue->value, vlen);
memcpy(pathString+vlen,"\0",1);
prg = ctr_internal_readf(pathString, &program_size);
parsedCode = ctr_cparse_parse(prg, pathString);
ctr_heap_free( prg );
ctr_cwlk_subprogram++;
ctr_cwlk_run(parsedCode);
ctr_cwlk_subprogram--;
return myself;
}
/**
* [File] delete
*
* Deletes the file.
*/
ctr_object* ctr_file_delete(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_FILE_WRITE );
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
ctr_size vlen;
char* pathString;
int r;
if (path == NULL) return myself;
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate( sizeof( char ) * ( vlen + 1 ) );
memcpy(pathString, path->value.svalue->value, vlen);
memcpy(pathString+vlen,"\0",1);
r = remove(pathString);
ctr_heap_free( pathString );
if (r!=0) {
CtrStdFlow = ctr_build_string_from_cstring( "Unable to delete file." );
CtrStdFlow->info.sticky = 1;
return CtrStdNil;
}
return myself;
}
/**
* [File] size
*
* Returns the size of the file.
*/
ctr_object* ctr_file_size(ctr_object* myself, ctr_argument* argumentList) {
ctr_object* path = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
ctr_size vlen;
char* pathString;
FILE* f;
int prev, sz;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (path == NULL) return ctr_build_number_from_float(0);
vlen = path->value.svalue->vlen;
pathString = ctr_heap_allocate( sizeof(char) * ( vlen + 1 ) );
memcpy(pathString, path->value.svalue->value, ( sizeof( char ) * vlen ) );
memcpy(pathString+vlen,"\0",1);
f = fopen(pathString, "r");
ctr_heap_free( pathString );
if (f == NULL) return ctr_build_number_from_float(0);
prev = ftell(f);
fseek(f, 0L, SEEK_END);
sz=ftell(f);
fseek(f,prev,SEEK_SET);
if (f) {
fclose(f);
}
return ctr_build_number_from_float( (ctr_number) sz );
}
/**
* [File] open: [string]
*
* Open a file with using the specified mode.
*
* Usage:
*
* f := File new: '/path/to/file'.
* f open: 'r+'. #opens file for reading and writing
*
* The example above opens the file in f for reading and writing.
*/
ctr_object* ctr_file_open(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
ctr_object* pathObj = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
char* mode;
char* path;
FILE* handle;
ctr_resource* rs = ctr_heap_allocate(sizeof(ctr_resource));
ctr_object* modeStrObj = ctr_internal_cast2string( argumentList->object );
if ( myself->value.rvalue != NULL ) {
ctr_heap_free( rs );
CtrStdFlow = ctr_build_string_from_cstring( "File has already been opened." );
CtrStdFlow->info.sticky = 1;
return myself;
}
if ( pathObj == NULL ) return myself;
path = ctr_heap_allocate_cstring( pathObj );
mode = ctr_heap_allocate_cstring( modeStrObj );
handle = fopen(path,mode);
ctr_heap_free( path );
ctr_heap_free( mode );
rs->type = 1;
rs->ptr = handle;
myself->value.rvalue = rs;
return myself;
}
/**
* [File] close.
*
* Closes the file represented by the recipient.
*
* Usage:
*
* f := File new: '/path/to/file.txt'.
* f open: 'r+'.
* f close.
*
* The example above opens and closes a file.
*/
ctr_object* ctr_file_close(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (myself->value.rvalue == NULL) return myself;
if (myself->value.rvalue->type != 1) return myself;
if (myself->value.rvalue->ptr) {
fclose((FILE*)myself->value.rvalue->ptr);
}
ctr_heap_free( myself->value.rvalue );
myself->value.rvalue = NULL;
return myself;
}
/**
* [File] readBytes: [Number].
*
* Reads a number of bytes from the file.
*
* Usage:
*
* f := File new: '/path/to/file.txt'.
* f open: 'r+'.
* x := f readBytes: 10.
* f close.
*
* The example above reads 10 bytes from the file represented by f
* and puts them in buffer x.
*/
ctr_object* ctr_file_read_bytes(ctr_object* myself, ctr_argument* argumentList) {
int bytes;
char* buffer;
ctr_object* result;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (myself->value.rvalue == NULL) return myself;
if (myself->value.rvalue->type != 1) return myself;
bytes = ctr_internal_cast2number(argumentList->object)->value.nvalue;
if (bytes < 0) return ctr_build_string_from_cstring("");
buffer = (char*) ctr_heap_allocate(bytes);
if (buffer == NULL) {
CtrStdFlow = ctr_build_string_from_cstring("Cannot allocate memory for file buffer.");
CtrStdFlow->info.sticky = 1;
return ctr_build_string_from_cstring("");
}
fread(buffer, sizeof(char), (int)bytes, (FILE*)myself->value.rvalue->ptr);
result = ctr_build_string(buffer, bytes);
ctr_heap_free( buffer );
return result;
}
/**
* [File] writeBytes: [String].
*
* Takes a string and writes the bytes in the string to the file
* object. Returns the number of bytes actually written.
*
* Usage:
*
* f := File new: '/path/to/file.txt'.
* f open: 'r+'.
* n := f writeBytes: 'Hello World'.
* f close.
*
* The example above writes 'Hello World' to the specified file as bytes.
* The number of bytes written is returned in variable n.
*/
ctr_object* ctr_file_write_bytes(ctr_object* myself, ctr_argument* argumentList) {
ctr_check_permission( CTR_SECPRO_NO_FILE_WRITE );
int bytes, written;
ctr_object* string2write;
char* buffer;
if (myself->value.rvalue == NULL) return myself;
if (myself->value.rvalue->type != 1) return myself;
string2write = ctr_internal_cast2string(argumentList->object);
buffer = ctr_heap_allocate_cstring( string2write );
bytes = string2write->value.svalue->vlen;
written = fwrite(buffer, sizeof(char), (int)bytes, (FILE*)myself->value.rvalue->ptr);
ctr_heap_free( buffer );
return ctr_build_number_from_float((double_t) written);
}
/**
* [File] seek: [Number].
*
* Moves the file pointer to the specified position in the file
* (relative to the current position).
*
* Usage:
*
* file open: 'r', seek: 10.
*
* The example above opens a file for reading and moves the
* pointer to position 10 (meaning 10 bytes from the beginning of the file).
* The seek value may be negative.
*/
ctr_object* ctr_file_seek(ctr_object* myself, ctr_argument* argumentList) {
int offset;
int error;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (myself->value.rvalue == NULL) return myself;
if (myself->value.rvalue->type != 1) return myself;
offset = (long int) ctr_internal_cast2number(argumentList->object)->value.nvalue;
error = fseek((FILE*)myself->value.rvalue->ptr, offset, SEEK_CUR);
if (error) {
CtrStdFlow = ctr_build_string_from_cstring("Seek failed.");
CtrStdFlow->info.sticky = 1;
}
return myself;
}
/**
* [File] rewind.
*
* Rewinds the file. Moves the file pointer to the beginning of the file.
*
* Usage:
*
* file open: 'r'.
* x := file readBytes: 10. #read 10 bytes
* file rewind. #rewind, set pointer to begin again
* y := file readBytes: 10. #re-read same 10 bytes
*
* The example above reads the same sequence of 10 bytes twice, resulting
* in variable x and y being equal.
*/
ctr_object* ctr_file_seek_rewind(ctr_object* myself, ctr_argument* argumentList) {
int error;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (myself->value.rvalue == NULL) return myself;
if (myself->value.rvalue->type != 1) return myself;
error = fseek((FILE*)myself->value.rvalue->ptr, 0, SEEK_SET);
if (error) {
CtrStdFlow = ctr_build_string_from_cstring("Seek rewind failed.");
CtrStdFlow->info.sticky = 1;
}
return myself;
}
/**
* [File] end.
*
* Moves the file pointer to the end of the file. Use this in combination with
* negative seek operations.
*
* Usage:
*
* file open: 'r'.
* file end.
* x := file seek: -10, readBytes: 10.
*
* The example above will read the last 10 bytes of the file. This is
* accomplished by first moving the file pointer to the end of the file,
* then putting it back 10 bytes (negative number), and then reading 10
* bytes.
*/
ctr_object* ctr_file_seek_end(ctr_object* myself, ctr_argument* argumentList) {
int error;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
if (myself->value.rvalue == NULL) return myself;
if (myself->value.rvalue->type != 1) return myself;
error = fseek((FILE*)myself->value.rvalue->ptr, 0, SEEK_END);
if (error) {
CtrStdFlow = ctr_build_string_from_cstring("Seek end failed.");
CtrStdFlow->info.sticky = 1;
}
return myself;
}
/**
* @internal
*
* Locks a file or unlocks a file.
* All locking functions use this function under the hood.
*/
ctr_object* ctr_file_lock_generic(ctr_object* myself, ctr_argument* argumentList, int lock) {
int b;
int fd;
char* path;
ctr_object* pathObj;
ctr_object* answer;
ctr_object* fdObj;
ctr_object* fdObjKey;
ctr_check_permission( CTR_SECPRO_NO_FILE_WRITE );
pathObj = ctr_internal_object_find_property(myself, ctr_build_string_from_cstring( "path" ), 0);
path = ctr_heap_allocate_cstring( pathObj );
fdObjKey = ctr_build_string_from_cstring("fileDescriptor");
fdObj = ctr_internal_object_find_property(
myself,
fdObjKey,
CTR_CATEGORY_PRIVATE_PROPERTY
);
if (fdObj == NULL) {
fd = open( path, O_CREAT );
fdObj = ctr_build_number_from_float( (ctr_size) fd );
ctr_internal_object_set_property(
myself, fdObjKey, fdObj, CTR_CATEGORY_PRIVATE_PROPERTY
);
} else {
fd = (int) fdObj->value.nvalue;
}
b = flock( fd, lock );
if (b != 0) {
close(fd);
answer = ctr_build_bool(0);
ctr_internal_object_delete_property( myself, fdObjKey, CTR_CATEGORY_PRIVATE_PROPERTY );
} else {
answer = ctr_build_bool(1);
}
ctr_heap_free( path );
return answer;
}
/**
* [File] unlock.
*
* Attempts to unlock a file. This message is non-blocking, on failure
* it will immediately return. Answers True if the file has been
* unlocked succesfully. Otherwise, the answer is False.
*/
ctr_object* ctr_file_unlock(ctr_object* myself, ctr_argument* argumentList) {
return ctr_file_lock_generic( myself, argumentList, LOCK_UN | LOCK_NB );
}
/**
* [File] lock.
*
* Attempts to acquire an exclusive lock on file.
* This message is non-blocking, on failure
* it will immediately return. Answers True if the lock has been
* acquired and False otherwise.
*/
ctr_object* ctr_file_lock(ctr_object* myself, ctr_argument* argumentList) {
return ctr_file_lock_generic( myself, argumentList, LOCK_EX | LOCK_NB );
}
/**
* [File] list: [String].
*
* Returns the contents of the specified folder as a an array.
* Each entry of the array contains a map with the keys 'file'
* and 'type'. The 'file' entry contains a string with the name
* of the file while the 'type' entry contains a string describing
* the type of the file.
*
* Usage:
*
* files := File list: '/tmp/testje'.
*
*/
ctr_object* ctr_file_list(ctr_object* myself, ctr_argument* argumentList) {
DIR* d;
struct dirent* entry;
char* pathValue;
ctr_object* fileList;
ctr_object* fileListItem;
ctr_object* path;
ctr_argument* putArgumentList;
ctr_argument* addArgumentList;
ctr_check_permission( CTR_SECPRO_NO_FILE_READ );
path = ctr_internal_cast2string( argumentList->object );
fileList = ctr_array_new(CtrStdArray, NULL);
pathValue = ctr_heap_allocate_cstring( path );
d = opendir( pathValue );
if (d == 0) {
CtrStdFlow = ctr_build_string_from_cstring("Failed to open folder.");
ctr_heap_free(pathValue);
return CtrStdNil;
}
putArgumentList = ctr_heap_allocate( sizeof( ctr_argument ) );
addArgumentList = ctr_heap_allocate( sizeof( ctr_argument ) );
putArgumentList->next = ctr_heap_allocate( sizeof( ctr_argument ) );
while((entry = readdir(d))) {
fileListItem = ctr_map_new(CtrStdMap, NULL);
putArgumentList->next->object = ctr_build_string_from_cstring( "file" );
putArgumentList->object = ctr_build_string_from_cstring(entry->d_name);
ctr_map_put(fileListItem, putArgumentList);
putArgumentList->next->object = ctr_build_string_from_cstring( "type" );
switch(entry->d_type) {
case DT_REG:
putArgumentList->object = ctr_build_string_from_cstring("file");
break;
case DT_DIR:
putArgumentList->object = ctr_build_string_from_cstring("folder");
break;
case DT_LNK:
putArgumentList->object = ctr_build_string_from_cstring("symbolic link");
break;
case DT_CHR:
putArgumentList->object = ctr_build_string_from_cstring("character device");
break;
case DT_BLK:
putArgumentList->object = ctr_build_string_from_cstring("block device");
break;
case DT_SOCK:
putArgumentList->object = ctr_build_string_from_cstring("socket");
break;
case DT_FIFO:
putArgumentList->object = ctr_build_string_from_cstring("named pipe");
break;
default:
putArgumentList->object = ctr_build_string_from_cstring("other");
break;
}
ctr_map_put(fileListItem, putArgumentList);
addArgumentList->object = fileListItem;
ctr_array_push(fileList, addArgumentList);
}
closedir(d);
ctr_heap_free(putArgumentList->next);
ctr_heap_free(putArgumentList);
ctr_heap_free(addArgumentList);
ctr_heap_free(pathValue);
return fileList;
}