diff options
author | Matthias Köppe <mkoeppe@mail.math.uni-magdeburg.de> | 2000-09-21 21:06:17 +0000 |
---|---|---|
committer | Matthias Köppe <mkoeppe@mail.math.uni-magdeburg.de> | 2000-09-21 21:06:17 +0000 |
commit | b53f74cb5fb7aab941e71857244d41b463349c3d (patch) | |
tree | e829816d4acc995d0e53cf18c3701108f9d5a465 /Lib/guile/ports.i | |
parent | 5f17119bd1bb515d4c251580ed2a2dfc0d828ae4 (diff) | |
download | swig-b53f74cb5fb7aab941e71857244d41b463349c3d.tar.gz |
[Guile] New typemaps for FILE *.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@875 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Lib/guile/ports.i')
-rw-r--r-- | Lib/guile/ports.i | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/guile/ports.i b/Lib/guile/ports.i new file mode 100644 index 000000000..3741070b0 --- /dev/null +++ b/Lib/guile/ports.i @@ -0,0 +1,44 @@ +/* ports.i --- Guile typemaps for handling ports -*- c -*- + Copyright (C) 2000 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> + + $Header$ +*/ + +%{ + #ifndef _POSIX_SOURCE + /* This is needed on Solaris for fdopen(). */ + # define _POSIX_SOURCE=199506L + #endif + #include <stdio.h> + #include <errno.h> +%} + +/* Feed FILE * arguments from file ports */ + +%typemap(guile, in) FILE * +{ + if(!(SCM_FPORTP($source))) + scm_wrong_type_arg("$name", $argnum, $source); + else { + int fd; + if (SCM_OUTPUT_PORT_P($source)) + scm_force_output($source); + fd=dup(SCM_FPORT_FDES($source)); + if(fd==-1) + scm_misc_error("$name", strerror(errno), SCM_EOL); + $target=fdopen(fd, + SCM_OUTPUT_PORT_P($source) + ? (SCM_INPUT_PORT_P($source) + ? "rw" : "w") + : "r"); + if($target==NULL) + scm_misc_error("$name", strerror(errno), SCM_EOL); + } +} + +%typemap(guile, indoc) FILE * "($arg <port>)"; + +%typemap(guile, freearg) FILE* { + fclose($target); +} + |