Passing WINNT file name as a argument from java to C code
Hi ,
Plz help me on the following issue for which we are struggling from last 2 weeks.
I am working on the encrption/decryption of some native files involving C based DES algorithm functions.
I have got some native files whose names has to be passed from my jni code to Native c code as parameters to those C functions.
I am using the GetStringUTFChars() in the following manner.
Is it the correct way.if wrong plz rectify my code.
JNIEXPORT jlong JNICALL Java_com_deceval_siidj_desgmdlib_DESObj_SetKeyFile
(JNIEnv *env, jobject obj, jstring filename)
{
long retskeyfile;
const char *fname;
fname =(char*) (*env)->GetStringUTFChars(env,filename,0);
if (fname == NULL) {
return -7; /* OutOfMemoryError already thrown */
}
retskeyfile=SetKeyFile( (char *)fname );
(*env)->ReleaseStringUTFChars(env,filename,fname);
return retskeyfile;
}
//C code is as follow
longSetKeyFile( char *filename )
{
#define MAXSIZE 2048
FILE *mfile;
char buffer [ MAXSIZE + 1 ];
int n;
/*printf ("sizeof int %i\n" , sizeof(int) );
printf ("sizeof long %i\n" , sizeof(long) );
printf ("sizeof char %i\n" , sizeof(char) );*/
mfile = fopen( filename , "rb" );
if ( mfile == NULL ) return -1;
n = fread (buffer , 1 , MAXSIZE , mfile );
fclose(mfile);
if ( (n=processBuffer( buffer , n ))!=0 ) return n;
_st[0] = 1 ;
return 0;
}
I am getting a return value -2 but expected value is 0.
Is there any other mechanism for passing on the file name from java code to C code.
Thanks in advance,
Santhosh

