File: ports.i

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (50 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* -----------------------------------------------------------------------------
 * ports.i
 *
 * Guile typemaps for handling ports
 * ----------------------------------------------------------------------------- */

%{
  #ifndef _POSIX_SOURCE
  /* This is needed on Solaris for fdopen(). */
  #  define _POSIX_SOURCE 199506L
  #endif
  #include <stdio.h>
  #include <errno.h>
  #include <unistd.h>
%}

/* This typemap for FILE * accepts
   (1) FILE * pointer objects,
   (2) Scheme file ports.  In this case, it creates a temporary C stream
       which reads or writes from a dup'ed file descriptor.
 */

%typemap(in, doc="$NAME is a file port or a FILE * pointer") FILE *
{
  if (SWIG_ConvertPtr($input, (void**) &($1), $1_descriptor, 0) != 0) {
    if (!(SCM_FPORTP($input))) {
      scm_wrong_type_arg("$symname", $argnum, $input);
    } else {
      int fd;
      if (SCM_OUTPUT_PORT_P($input)) {
        scm_force_output($input);
      }
      fd=dup(SCM_FPORT_FDES($input));
      if (fd==-1) {
        scm_misc_error("$symname", strerror(errno), SCM_EOL);
      }
      $1=fdopen(fd, SCM_OUTPUT_PORT_P($input) ? (SCM_INPUT_PORT_P($input) ? "r+" : "w") : "r");
      if ($1==NULL) {
        scm_misc_error("$symname", strerror(errno), SCM_EOL);
      }
    }
  }
}

%typemap(freearg) FILE*  {
  if ($1) {
    fclose($1);
  }
}