-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
\f
#define _LARGEFILE64_SOURCE /* ask for stat64 etc */
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "libguile/gc.h"
#include "libguile/posix.h"
#include "libguile/dynwind.h"
+#include "libguile/hashtab.h"
#include "libguile/fports.h"
if (SCM_INPUT_PORT_P (port) && read_size > 0)
{
- pt->read_buf = scm_gc_malloc (read_size, "port buffer");
+ pt->read_buf = scm_gc_malloc_pointerless (read_size, "port buffer");
pt->read_pos = pt->read_end = pt->read_buf;
pt->read_buf_size = read_size;
}
if (SCM_OUTPUT_PORT_P (port) && write_size > 0)
{
- pt->write_buf = scm_gc_malloc (write_size, "port buffer");
+ pt->write_buf = scm_gc_malloc_pointerless (write_size, "port buffer");
pt->write_pos = pt->write_buf;
pt->write_buf_size = write_size;
}
/* Move ports with the specified file descriptor to new descriptors,
* resetting the revealed count to 0.
*/
-
-void
-scm_evict_ports (int fd)
+static void
+scm_i_evict_port (void *closure, SCM port)
{
- long i;
+ int fd = * (int*) closure;
- scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex);
-
- for (i = 0; i < scm_i_port_table_size; i++)
+ if (SCM_FPORTP (port))
{
- SCM port = scm_i_port_table[i]->port;
+ scm_t_port *p;
+ scm_t_fport *fp;
- if (SCM_FPORTP (port))
- {
- scm_t_fport *fp = SCM_FSTREAM (port);
+ /* XXX: In some cases, we can encounter a port with no associated ptab
+ entry. */
+ p = SCM_PTAB_ENTRY (port);
+ fp = (p != NULL) ? (scm_t_fport *) p->stream : NULL;
- if (fp->fdes == fd)
- {
- fp->fdes = dup (fd);
- if (fp->fdes == -1)
- scm_syserror ("scm_evict_ports");
- scm_set_port_revealed_x (port, scm_from_int (0));
- }
+ if ((fp != NULL) && (fp->fdes == fd))
+ {
+ fp->fdes = dup (fd);
+ if (fp->fdes == -1)
+ scm_syserror ("scm_evict_ports");
+ scm_set_port_revealed_x (port, scm_from_int (0));
}
}
+}
- scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex);
+void
+scm_evict_ports (int fd)
+{
+ scm_c_port_for_each (scm_i_evict_port, (void *) &fd);
}
pt = SCM_PTAB_ENTRY(port);
{
scm_t_fport *fp
- = (scm_t_fport *) scm_gc_malloc (sizeof (scm_t_fport), "file port");
+ = (scm_t_fport *) scm_gc_malloc_pointerless (sizeof (scm_t_fport),
+ "file port");
fp->fdes = fdes;
pt->rw_random = SCM_FDES_RANDOM_P (fdes);
case on NetBSD apparently), then fport_seek_or_seek64 is right to be
fport_seek already. */
-#if HAVE_STAT64 && SIZEOF_OFF_T != SIZEOF_OFF64_T
+#if GUILE_USE_64_CALLS && HAVE_STAT64 && SIZEOF_OFF_T != SIZEOF_OFF64_T
static off_t
fport_seek (SCM port, off_t offset, int whence)
{