10
10
#include <unistd.h>
11
11
#include <dirent.h>
12
12
#include <jni.h>
13
+ #include <sys/stat.h>
14
+ #include <sys/types.h>
15
+
16
+ #include <errno.h>
13
17
14
18
#include "SDL.h"
15
19
@@ -68,15 +72,26 @@ PyMODINIT_FUNC initandroidembed(void) {
68
72
/* } */
69
73
/* } */
70
74
71
- int dir_exists (char * filename ) {
72
- DIR * dip ;
73
- if (dip = opendir (filename )) {
74
- closedir (filename );
75
- return 1 ;
75
+ /* int dir_exists(char* filename) { */
76
+ /* DIR *dip; */
77
+ /* if (dip = opendir(filename)) { */
78
+ /* closedir(filename); */
79
+ /* return 1; */
80
+ /* } */
81
+ /* return 0; */
82
+ /* } */
83
+
84
+
85
+ int dir_exists (char * filename ) {
86
+ struct stat st ;
87
+ if (stat (filename , & st ) == 0 ) {
88
+ if (S_ISDIR (st .st_mode ))
89
+ return 1 ;
76
90
}
77
91
return 0 ;
78
92
}
79
93
94
+
80
95
int file_exists (const char * filename )
81
96
{
82
97
FILE * file ;
@@ -112,6 +127,12 @@ int main(int argc, char *argv[]) {
112
127
/* LOG(argv[0]); */
113
128
/* LOG("AND: That was argv 0"); */
114
129
//setenv("PYTHONVERBOSE", "2", 1);
130
+
131
+ LOG ("Changing directory to the one provided by ANDROID_ARGUMENT" );
132
+ LOG (env_argument );
133
+ chdir (env_argument );
134
+
135
+
115
136
Py_SetProgramName (L"android_python" );
116
137
117
138
/* our logging module for android
@@ -120,14 +141,31 @@ int main(int argc, char *argv[]) {
120
141
121
142
LOG ("Preparing to initialize python" );
122
143
144
+ char errstr [256 ];
145
+ snprintf (errstr , 256 , "errno before is %d" ,
146
+ errno );
147
+ LOG (errstr );
148
+
149
+ if (dir_exists ("crystax_python" )) {
150
+ LOG ("exists without slash" );
151
+ }
152
+
153
+ snprintf (errstr , 256 , "errno after is %d" ,
154
+ errno );
155
+ LOG (errstr );
156
+
123
157
if (dir_exists ("../libs" )) {
124
158
LOG ("libs exists" );
125
159
} else {
126
160
LOG ("libs does not exist" );
127
161
}
162
+
163
+ if (file_exists ("main.py" )) {
164
+ LOG ("The main.py does exist" );
165
+ }
128
166
129
- if (dir_exists ( "crystax_python" ) ) {
130
- LOG ("exists without slash " );
167
+ if (file_exists ( "main.py" ) == 1 ) {
168
+ LOG ("The main.py does exist2 " );
131
169
}
132
170
133
171
if (dir_exists ("crystax_python/" )) {
@@ -240,7 +278,6 @@ int main(int argc, char *argv[]) {
240
278
/* run it !
241
279
*/
242
280
LOG ("Run user program, change dir and execute main.py" );
243
- chdir (env_argument );
244
281
245
282
/* search the initial main.py
246
283
*/
0 commit comments