This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How to convert a port to a FILE*?


Writing a Guile front-end to a library, I came across the
problem mentioned in the subject.

I thought I could get around it like this:

SCM
newpl_wrapper (SCM plty, SCM out, SCM err, SCM in)
/* string plty, port out, port err, port in */
{
  char *c_type;
  FILE *c_in, *c_out, *c_err;
  SCM pl, filed;
  int handle;

  SCM_DEFER_INTS;
...
    filed = scm_fileno (out);
    c_out = fdopen (scm2int (filed), "w");
    if (SCM_INPORTP (in))
    {
      filed = scm_fileno (in);
      c_out = fdopen (scm2char (filed), "r");
    }
    else
      c_in = NULL;
... then repeat for `err' what I just did for `in'.

Yes, I know I should add sanity-checking after the `out' fdopen.
And the rather unintuitive "out, err, in" order is because `in'
and `err' are optional (actually, the library currently ignores
`in' silently).

Well, when I try that (with a perfectly good just-opened port) I
get "illegal hardware instruction" on the fdopen [I had to do
some clumsy debugging to be sure it was really on the fdopen,
like adding `printf ("ok\n")' just after it ;-)]. Anyone has a
hint on what am I doing wrong?

Also, are `SCM_INPORTP' and `SCM_OUTPORTP' really what I think
they are?

[]s,
                                               |alo
                                               +----
--
      I am Lalo of deB-org. You will be freed.
                 Resistance is futile.

http://www.webcom.com/lalo      mailto:lalo@webcom.com
                 pgp key in the web page

Debian GNU/Linux       --        http://www.debian.org