8000 Moved chdir in SDL2 start.c · kived/python-for-android@6d7e4b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d7e4b1

Browse files
committed
Moved chdir in SDL2 start.c
1 parent 76bcf99 commit 6d7e4b1

File tree

1 file changed

+45
-8
lines changed
  • pythonforandroid/bootstraps/sdl2/build/jni/src

1 file changed

+45
-8
lines changed

pythonforandroid/bootstraps/sdl2/build/jni/src/start.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <unistd.h>
1111
#include <dirent.h>
1212
#include <jni.h>
13+
#include <sys/stat.h>
14+
#include <sys/types.h>
15+
16+
#include <errno.h>
1317

1418
#include "SDL.h"
1519

@@ -68,15 +72,26 @@ PyMODINIT_FUNC initandroidembed(void) {
6872
/* } */
6973
/* } */
7074

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;
7690
}
7791
return 0;
7892
}
7993

94+
8095
int file_exists(const char * filename)
8196
{
8297
FILE *file;
@@ -112,6 +127,12 @@ int main(int argc, char *argv[]) {
112127
/* LOG(argv[0]); */
113128
/* LOG("AND: That was argv 0"); */
114129
//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+
115136
Py_SetProgramName(L"android_python");
116137

117138
/* our logging module for android
@@ -120,14 +141,31 @@ int main(int argc, char *argv[]) {
120141

121142
LOG("Preparing to initialize python");
122143

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+
123157
if (dir_exists("../libs")) {
124158
LOG("libs exists");
125159
} else {
126160
LOG("libs does not exist");
127161
}
162+
163+
if (file_exists("main.py")) {
164+
LOG("The main.py does exist");
165+
}
128166

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");
131169
}
132170

133171
if (dir_exists("crystax_python/")) {
@@ -240,7 +278,6 @@ int main(int argc, char *argv[]) {
240278
/* run it !
241279
*/
242280
LOG("Run user program, change dir and execute main.py");
243-
chdir(env_argument);
244281

245282
/* search the initial main.py
246283
*/

0 commit comments

Comments
 (0)
0