c_src: update with new intern methods
[nit.git] / c_src / file._ffi.c
1 /*
2 Extern implementation of Nit module file
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include "file._ffi.h"
7 #define new_HashSet_of_String file___new_HashSet_of_String
8 #define HashSet_of_String_add file___HashSet_of_String_add
9 #define NativeString_to_s file___NativeString_to_s
10 #define String_to_cstring file___String_to_cstring
11
12 Set_of_String file___String_files___impl( String recv )
13 {
14 #line 379 "lib/standard/file.nit"
15
16
17 char *dir_path;
18 DIR *dir;
19
20 dir_path = String_to_cstring( recv );
21 if ((dir = opendir(dir_path)) == NULL)
22 {
23 perror( dir_path );
24 exit( 1 );
25 }
26 else
27 {
28 HashSet_of_String results;
29 String file_name;
30 struct dirent *de;
31
32 results = new_HashSet_of_String();
33
34 while ( ( de = readdir( dir ) ) != NULL )
35 if ( strcmp( de->d_name, ".." ) != 0 &&
36 strcmp( de->d_name, "." ) != 0 )
37 {
38 file_name = NativeString_to_s( strdup( de->d_name ) );
39 HashSet_of_String_add( results, file_name );
40 }
41
42 closedir( dir );
43 return HashSet_of_String_as_Set_of_String( results );
44 }
45 }
46
47 struct stat * file___NativeString_file_lstat___impl( char* recv )
48 {
49 #line 414 "lib/standard/file.nit"
50
51
52 struct stat* stat_element;
53 int res;
54 stat_element = malloc(sizeof(struct stat));
55 res = lstat(recv, stat_element);
56 if (res == -1) return NULL;
57 return stat_element;
58 }
59
60 int file___FileStat_is_reg___impl( struct stat * recv )
61 {
62 #line 436 "lib/standard/file.nit"
63
64 return S_ISREG(recv->st_mode); }
65
66 int file___FileStat_is_dir___impl( struct stat * recv )
67 {
68 #line 437 "lib/standard/file.nit"
69
70 return S_ISDIR(recv->st_mode); }
71
72 int file___FileStat_is_chr___impl( struct stat * recv )
73 {
74 #line 438 "lib/standard/file.nit"
75
76 return S_ISCHR(recv->st_mode); }
77
78 int file___FileStat_is_blk___impl( struct stat * recv )
79 {
80 #line 439 "lib/standard/file.nit"
81
82 return S_ISBLK(recv->st_mode); }
83
84 int file___FileStat_is_fifo___impl( struct stat * recv )
85 {
86 #line 440 "lib/standard/file.nit"
87
88 return S_ISFIFO(recv->st_mode); }
89
90 int file___FileStat_is_lnk___impl( struct stat * recv )
91 {
92 #line 441 "lib/standard/file.nit"
93
94 return S_ISLNK(recv->st_mode); }
95
96 int file___FileStat_is_sock___impl( struct stat * recv )
97 {
98 #line 442 "lib/standard/file.nit"
99
100 return S_ISSOCK(recv->st_mode); }