From C To Pascal, Files
Hi alltogether! Its for the PostgreSQL-Unit. In C, I have a function: void printSomethingToFile(File* file); for which I want to write a wrapper. What I did was: ----------------- snip -------------- In C: void _p_printSomethingToFile(int file_descriptor) { FILE *myfile; myfile = fdopen(file_descriptor, "w"); /* if (errno != 0) printf("errno is %d\n"errno); */ printSomethingToFile(myfile); /* fflush(myfile); */ } Pascal (Unit-Part): Procedure CprintSomethingToFile(int file_descriptor); asmname '_p_printSomethingToFile'; Procedure PrintSomethingToFile(aFile : Text); Var fd : Integer; Begin fd := FileHandle(aFile); CprintSomethingToFile(fd) End; Pascal (Program) Var f : Text; Begin ... Assign(f, 'filename.out'); Rewrite(f); PrintSomethingToFile(f); Close(f); ... End. ----------------- snip -------------- Sometimes this works (especially, if I write a line of text _before_ I use PrintSomethingToFile) and sometimes it fails because errno is set to a value <> 0 after calling fdopen. If I use fflush(myfile) after (in C) printSomethingToFile(myfile) it seems to work. The text is written propely, but errno is <>0 ! errno is mostly set to "Bad File Descriptor". Is there something, I did wrong? Eike Lange
participants (2)
-
Eike Lange -
Frank Heckenbach