extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
unz_file_info64 *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize));
and it is used like this:
char filename_inzip[256];
unz_file_info64 file_info;
uLong ratio=0;
const char *string_method;
char charCrypt=' ';
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
In Nim I have tried both the following:
proc unzGetCurrentFileInfo64*( file:pointer,
pfile_info:unz_file_info64,
szFileName:array[256,char], # char *szFileName,
fileNameBufferSize:uint32, # uLong fileNameBufferSize,
extraField:pointer, # void *extraField,
extraFieldBufferSize:uint32, # uLong extraFieldBufferSize,
szComment:cstring, # char *szComment,
commentBufferSize:uint32):int #uLong commentBufferSize));
and:
#...
szFileName:cstring, # char *szFileName,
#...
But when I used the procedure like follows:
var filename_inzip:array[256,char] # or cstring
var pfile_info = new(unz_file_info64)
var filename_len:uint32
error = unzGetCurrentFileInfo64(uf,pfile_info,filename_inzip,filename_len,nil,0,"" ,0)
the varible filename_inzip is empty. Any clue of what is wrong?
if ((err==UNZ_OK) && (szFileName!=NULL))
{
....
}
Not sure if this might the problem.
First question, have you tried hard enough to use tools like c2nim or similar? It helps getting some types correct.
From last line of your message
var filename_len:uint32
I have the feeling that is input data to the function, so try to set it to your buffer size.
char filename_inzip[256];
The above is misleading -- C can not pass strings as value arrays, so C passes always pointers to functions. An array is automatically passed as a pointer to that array in C. So Nim's cstring is right from type, but you have to initialize it. Maybe
buf = array[256, char]
filename_inzip: cstring = addr(buf)
But note, the above array lives on the stack. If that parameter have to exists after the proc returns, then you must allocate it on heap with low level new equivalents like alloc(). But I think there exist more elegant functions to initialize cstrings.
For the size types, try to use Nim's c types, like cint, culong. Because in C size(int) may be 4 bytes, but may be different. Depends on 32/64 bit OS or embedded devices.
I am on the process of working with c2nim. I filed a bug, and now I manage to create unzip.nim from the header. But not working yet.
You really nailed the issue. Now it works.
Thanks a lot