From 9ff77d3b9fe8384841743c4e7a3ef5b33d9a83b5 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 1 Jun 2008 19:21:35 +0200 Subject: [PATCH] Use `scm_set_port_read ()' in string ports. --- libguile/strports.c | 27 ++++++++++++++++++--------- 1 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libguile/strports.c b/libguile/strports.c index 8659ccf..f6fb24b 100644 --- a/libguile/strports.c +++ b/libguile/strports.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003, 2005, 2006, 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 @@ -45,6 +45,10 @@ #include #endif +#ifndef SCM_MIN +# define SCM_MIN(A, B) ((A) < (B) ? (A) : (B)) +#endif + /* {Ports - string ports} @@ -93,15 +97,19 @@ scm_t_bits scm_tc16_strport; -static int -stfill_buffer (SCM port) +/* Read up to SIZE bytes from PORT into BUFFER. */ +static size_t +st_read (SCM port, void *buffer, size_t size) { + size_t available, count; scm_t_port *pt = SCM_PTAB_ENTRY (port); - - if (pt->read_pos >= pt->read_end) - return EOF; - else - return scm_return_first_int (*pt->read_pos, port); + + available = pt->read_end - pt->read_pos; + count = SCM_MIN (available, size); + + memcpy (buffer, pt->read_pos, count); + + return count; } /* change the size of a port's string to new_size. this doesn't @@ -538,8 +546,9 @@ scm_eval_string (SCM string) static scm_t_bits scm_make_stptob () { - scm_t_bits tc = scm_make_port_type ("string", stfill_buffer, st_write); + scm_t_bits tc = scm_make_port_type ("string", NULL, st_write); + scm_set_port_read (tc, st_read); scm_set_port_mark (tc, scm_markstream); scm_set_port_end_input (tc, st_end_input); scm_set_port_flush (tc, st_flush); -- 1.5.5