diff options
-rw-r--r-- | libguile/ChangeLog | 15 | ||||
-rw-r--r-- | libguile/filesys.c | 20 | ||||
-rw-r--r-- | libguile/filesys.h | 1 | ||||
-rw-r--r-- | libguile/ioext.c | 25 | ||||
-rw-r--r-- | libguile/ioext.h | 1 | ||||
-rw-r--r-- | libguile/ports.c | 20 | ||||
-rw-r--r-- | libguile/ports.h | 1 |
7 files changed, 83 insertions, 0 deletions
diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 63a972b23..4d7f024b9 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,18 @@ +2000-11-07 Gary Houston <ghouston@arglist.com> + + * ports.c (scm_port_for_each): new proc. implements port-for-each, + which applies a procedure to each port in the port table. + ports.h: declare scm_port_for_each. + + * ioext.c (scm_dup2): new proc. implements "dup2" which is a simple + wrapper for the dup2 system call (unlike dup->fdes or + primitive-move->fdes). + * ioext.h: declare scm_dup2. + + * filesys.c (scm_close_fdes): new proc. implements "close-fdes" + which is a simple wrapper for close system call (unlike scm_close). + * filesys.h: declare for scm_close_fdes. + 2000-11-06 Mikael Djurfeldt <mdj@linnaeus.mit.edu> * eval.c (SCM_IM_DISPATCH), objects.c (scm_mcache_lookup_cmethod): diff --git a/libguile/filesys.c b/libguile/filesys.c index 7e280652e..e8e62b1d5 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -335,6 +335,26 @@ SCM_DEFINE (scm_close, "close", 1, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_close_fdes, "close-fdes", 1, 0, 0, + (SCM fd), + "A simple wrapper for the @code{close} system call.\n" + "Close file descriptor @var{fd}, which must be an integer.\n" + "Unlike close (@pxref{Ports and File Descriptors, close}),\n" + "the file descriptor will be closed even if a port is using it.\n" + "The return value is unspecified.") +#define FUNC_NAME s_scm_close_fdes +{ + int c_fd; + int rv; + + SCM_VALIDATE_INUM_COPY (1, fd, c_fd); + SCM_SYSCALL (rv = close (c_fd)); + if (rv < 0) + SCM_SYSERROR; + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + /* {Files} */ diff --git a/libguile/filesys.h b/libguile/filesys.h index f20240a8c..b6e8de297 100644 --- a/libguile/filesys.h +++ b/libguile/filesys.h @@ -64,6 +64,7 @@ extern SCM scm_umask (SCM mode); extern SCM scm_open_fdes (SCM path, SCM flags, SCM mode); extern SCM scm_open (SCM path, SCM flags, SCM mode); extern SCM scm_close (SCM fd_or_port); +extern SCM scm_close_fdes (SCM fd); extern SCM scm_stat (SCM object); extern SCM scm_link (SCM oldpath, SCM newpath); extern SCM scm_rename (SCM oldname, SCM newname); diff --git a/libguile/ioext.c b/libguile/ioext.c index 9cb84560e..439a7d7a0 100644 --- a/libguile/ioext.c +++ b/libguile/ioext.c @@ -412,6 +412,31 @@ SCM_DEFINE (scm_dup_to_fdes, "dup->fdes", 1, 1, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_dup2, "dup2", 2, 0, 0, + (SCM oldfd, SCM newfd), + "A simple wrapper for the @code{dup2} system call.\n" + "Copies the file descriptor @var{oldfd} to descriptor\n" + "number @var{newfd}, replacing the previous meaning\n" + "of @var{newfd}. Both @var{oldfd} and @var{newfd} must\n" + "be integers.\n" + "Unlike for dup->fdes or primitive-move->fdes, no attempt\n" + "is made to move away ports which are using @var{newfd}\n". + "The return value is unspecified.") +#define FUNC_NAME s_scm_dup2 +{ + int c_oldfd; + int c_newfd; + int rv; + + SCM_VALIDATE_INUM_COPY (1, oldfd, c_oldfd); + SCM_VALIDATE_INUM_COPY (2, newfd, c_newfd); + rv = dup2 (c_oldfd, c_newfd); + if (rv == -1) + SCM_SYSERROR; + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + SCM_DEFINE (scm_fileno, "fileno", 1, 0, 0, (SCM port), "Returns the integer file descriptor underlying @var{port}.\n" diff --git a/libguile/ioext.h b/libguile/ioext.h index 37aa09559..a79b1a5b5 100644 --- a/libguile/ioext.h +++ b/libguile/ioext.h @@ -54,6 +54,7 @@ extern SCM scm_write_line (SCM obj, SCM port); extern SCM scm_ftell (SCM object); extern SCM scm_redirect_port (SCM into_pt, SCM from_pt); extern SCM scm_dup_to_fdes (SCM fd_or_port, SCM newfd); +extern SCM scm_dup2 (SCM oldfd, SCM newfd); extern SCM scm_fileno (SCM port); extern SCM scm_isatty_p (SCM port); extern SCM scm_fdopen (SCM fdes, SCM modes); diff --git a/libguile/ports.c b/libguile/ports.c index 7476613a0..f6b9eeaff 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -668,6 +668,26 @@ SCM_DEFINE (scm_close_output_port, "close-output-port", 1, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0, + (SCM proc), + "Apply @var{proc} to each port in the Guile port table\n" + "in turn. The return value is unspecified.") +#define FUNC_NAME s_scm_port_for_each +{ + int i; + SCM_VALIDATE_PROC (1, proc); + + /* when pre-emptive multithreading is supported, access to the port + table will need to be controlled by a mutex. */ + SCM_DEFER_INTS; + for (i = 0; i < scm_port_table_size; i++) + { + scm_apply (proc, scm_cons (scm_port_table[i]->port, SCM_EOL), SCM_EOL); + } + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1, (SCM ports), "Close all open file ports used by the interpreter\n" diff --git a/libguile/ports.h b/libguile/ports.h index d4f884ee3..22d69db47 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -266,6 +266,7 @@ extern SCM scm_port_mode (SCM port); extern SCM scm_close_input_port (SCM port); extern SCM scm_close_output_port (SCM port); extern SCM scm_close_port (SCM port); +extern SCM scm_port_for_each (SCM proc); extern SCM scm_close_all_ports_except (SCM ports); extern SCM scm_input_port_p (SCM x); extern SCM scm_output_port_p (SCM x); |