Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * ports.i
  6. *
  7. * Guile typemaps for handling ports
  8. * ----------------------------------------------------------------------------- */
  9. %{
  10. #ifndef _POSIX_SOURCE
  11. /* This is needed on Solaris for fdopen(). */
  12. # define _POSIX_SOURCE 199506L
  13. #endif
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <unistd.h>
  17. %}
  18. /* This typemap for FILE * accepts
  19. (1) FILE * pointer objects,
  20. (2) Scheme file ports. In this case, it creates a temporary C stream
  21. which reads or writes from a dup'ed file descriptor.
  22. */
  23. %typemap(in, doc="$NAME is a file port or a FILE * pointer") FILE *
  24. ( int closep )
  25. {
  26. if (SWIG_ConvertPtr($input, (void**) &($1), $1_descriptor, 0) == 0) {
  27. closep = 0;
  28. }
  29. else if(!(SCM_FPORTP($input)))
  30. scm_wrong_type_arg("$name", $argnum, $input);
  31. else {
  32. int fd;
  33. if (SCM_OUTPUT_PORT_P($input))
  34. scm_force_output($input);
  35. fd=dup(SCM_FPORT_FDES($input));
  36. if(fd==-1)
  37. scm_misc_error("$name", strerror(errno), SCM_EOL);
  38. $1=fdopen(fd,
  39. SCM_OUTPUT_PORT_P($input)
  40. ? (SCM_INPUT_PORT_P($input)
  41. ? "r+" : "w")
  42. : "r");
  43. if($1==NULL)
  44. scm_misc_error("$name", strerror(errno), SCM_EOL);
  45. closep = 1;
  46. }
  47. }
  48. %typemap(freearg) FILE* {
  49. if (closep$argnum)
  50. fclose($1);
  51. }