1. Calling C function with file handles
- Posted by aku at inbox.as Feb 24, 2001
- 399 views
A function in bz2lib.dll typedef void BZFILE; BZFILE *BZ2_bzReadOpen ( int *bzerror, FILE *f, int small, int verbosity, void *unused, int nUnused ); Description: To make the library a little simpler and more portable, BZ2_bzReadOpen and BZ2_bzWriteOpen require you to pass them file handles (FILE*s) which have previously been opened for reading or writing respectively. That avoids portability problems associated with file operations and file attributes, whilst not being much of an imposition on the programmer. The FILE* arguments passed to BZ2_bzReadOpen/BZ2_bzWriteOpen should be set to binary mode. Most Unix systems will do this by default, but other platforms, including Windows and Mac, will not. If you omit this, you may encounter problems when moving code to new platforms. How can I convert the function to call in euphoria? Because of the "FILE *f" it is file handle. It is not the value returned by open(), isn't it?
2. Re: Calling C function with file handles
- Posted by stabmaster_ at HOTMAIL.COM Feb 24, 2001
- 383 views
This might not be the best solution, but here goes: Create an additional dll wich has 2 functions, openfile() and closefile(): FILE *openfile(char *fname) { return fopen(fname); } .you get the idea. Use these functions in your euphoria program to get a correct file pointer, e.g.: constant openfile = define_c_func(my_dll, "openfile", {C_POINTER}, C_INT) -- define closefile() here constant fname = allocate_string("mumbo.jumbo") atom filePointer filePointer = c_func(openfile, {fname}) -- do your stuff.. c_proc(closefile, {filePointer})