Permalink
Browse files

fixed the entire 2!:n family for android, entirely in native code

  • Loading branch information...
1 parent 9a04ca7 commit 0427ccc36db2a21058fd0c1a638ea9228ee7ff67 @mdykman committed Mar 28, 2012
Showing with 25 additions and 17 deletions.
  1. +4 −0 jni/j-jni-interface.c
  2. +1 −0 jni/j-jni-interface.h
  3. +20 −17 xh.c
View
@@ -12,6 +12,7 @@ While wrriten a part of an Android project, JInterface is generic enough to be u
A subclass of JInterface, org.dykman.j.android.AndroidJInterface include additional android-specific methods which can be invoke from J, via 15!:0
*/
+char android_temp_dir[240];
static JNIEnv *local_jnienv;
static jobject local_baseobj;
@@ -70,6 +71,9 @@ JNIEXPORT void JNICALL Java_org_dykman_j_JInterface_setEnv
(JNIEnv *env, jobject obj, jstring jkey, jstring jval) {
char*key = (*env)->GetStringUTFChars(env, jkey, 0);
char*val = (*env)->GetStringUTFChars(env, jval, 0);
+ if(strcmp(key,"TMP")==0) {
+ strcpy(android_temp_dir,val);
+ }
setenv(key,val,0);
free(key);
free(val);
View
@@ -14,6 +14,7 @@ int _stdcall android_unzip_file(const char* file, const char* todir);
char* _stdcall android_exec_host(const char *cmd);
void _stdcall android_quit();
void _stdcall android_free(void* ptr);
+extern char android_temp_dir[];
#endif
#ifdef ANDROID
View
37 xh.c
@@ -36,27 +36,23 @@ F1(jthost){A z;
A t;I b;C*fn,*s;F f;I n;
n=AN(w);
GA(t,LIT,n+5+L_tmpnam,1,0); s=CAV(t);
- fn=5+n+s;
- MC(s,AV(w),n);
-#ifndef ANDROID
+ fn=5+n+s; MC(s,AV(w),n);
+ #ifdef ANDROID
+ const char*ftmp=getenv("TMP");
+ ASSERT(ftmp!=NULL,EVFACE);
+ strcpy(fn,ftmp);
+ char atmp[L_tmpnam];
+ {C* t=tmpnam(atmp); }
+ strcat(fn,atmp+4);
+ #else
+ {C* t=tmpnam(fn); }
+ #endif
MC(n+s," > ",5L);
- {C* t=tmpnam(fn);}
b=!system(s);
if(b){f=fopen(fn,FREAD); z=rd(f,0L,-1L); fclose(f);}
unlink(fn);
ASSERT(b&&f,EVFACE);
-#else
- #include "jni/j-jni-interface.h"
- C*res=malloc(n+1);
- strncpy(res,s,n);
- res[n]=0;
- fn = android_exec_host(res);
- free(res);
- z = jtstr(jt,strlen(fn),fn);
- LOGFD("command=%s, result=%s",res,fn);
-#endif
}
-
#endif
R z;
}
@@ -71,7 +67,7 @@ F1(jthostne){C*s;
{
I b;
b=system(s);
-#if !SY_64 && (SYS&SYS_LINUX)
+#if !SY_64 && (SYS&SYS_LINUX) && !ANDROID
//Java-jnative-j.so system always returns -1
if(jt->sm==SMJAVA&&-1==b) b=-1==system("")?0:-1;
#endif
@@ -94,6 +90,12 @@ F1(jtjwait ){ASSERT(0,EVDOMAIN);}
#define CL(f) {close(f[0]);close(f[1]);}
+#ifdef ANDROID
+#define HOST_SHELL "/system/bin/sh"
+#else
+#define HOST_SHELL "/bin/sh"
+#endif
+
F1(jthostio){C*s;A z;F*pz;I fi[2],fo[2],r;int fii[2],foi[2];
fii[0]=fi[0];fii[1]=fi[1];foi[0]=fo[0];foi[1]=fo[1];
F1RANK(1,jthostio,0);
@@ -104,10 +106,11 @@ F1(jthostio){C*s;A z;F*pz;I fi[2],fo[2],r;int fii[2],foi[2];
if(pz[1])fclose(pz[1]); CL(fi);CL(fo);}
if(!add2(pz[1],pz[2],s)){fclose(pz[1]);fclose(pz[2]);
CL(fi);CL(fo);}
+
switch(r=fork()){
case -1:CL(fi);CL(fo);ASSERT(0,EVFACE);
case 0:close(0);{int i=dup(fo[0]);};close(1);{int i=dup(fi[1]);};CL(fi);CL(fo);
- execl("/bin/sh","/bin/sh","-c",s,NULL); exit(-1);
+ execl(HOST_SHELL,HOST_SHELL,"-c",s,NULL); exit(-1);
}close(fo[0]);close(fi[1]);
add2(NULL,NULL,NULL); pz[0]=(F)r;
R z;

0 comments on commit 0427ccc

Please sign in to comment.