Guile NEWS --- history of user-visible changes. -*- text -*-
-Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
See the end for copying conditions.
Please send Guile bug reports to bug-guile@gnu.org.
* Changes to the scm_ interface
+** New function: scm_c_read (SCM port, void *buffer, scm_sizet size)
+
+Used by an application to read arbitrary number of bytes from a port.
+Same semantics as libc read, except that scm_c_read only returns less
+than SIZE bytes if at end-of-file.
+
+Warning: Doesn't update port line and column counts!
+
+** New function: scm_c_write (SCM port, const void *ptr, scm_sizet size)
+
+Used by an application to write arbitrary number of bytes to an SCM
+port. Similar semantics as libc write. However, unlike libc
+write, scm_c_write writes the requested number of bytes and has no
+return value.
+
+Warning: Doesn't update port line and column counts!
+
** New function: scm_init_guile ()
In contrast to scm_boot_guile, scm_init_guile will return normally
-/* Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999, 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
scm_lfwrite (s, strlen (s), port);
}
+/* scm_lfwrite
+ *
+ * Currently, this function has an identical implementation to
+ * scm_c_write. We could have turned it into a macro expanding into a
+ * call to scm_c_write. However, the implementation is small and
+ * might differ in the future.
+ */
+
void
scm_lfwrite (const char *ptr, scm_sizet size, SCM port)
{
pt->rw_active = SCM_PORT_WRITE;
}
+/* scm_c_read
+ *
+ * Used by an application to read arbitrary number of bytes from an
+ * SCM port. Same semantics as libc read, except that scm_c_read only
+ * returns less than SIZE bytes if at end-of-file.
+ *
+ * Warning: Doesn't update port line and column counts! */
+
+scm_sizet
+scm_c_read (SCM port, void *buffer, scm_sizet size)
+{
+ scm_port *pt = SCM_PTAB_ENTRY (port);
+ scm_sizet n_read = 0, n_available;
+
+ if (pt->rw_active == SCM_PORT_WRITE)
+ scm_ptobs[SCM_PTOBNUM (port)].flush (port);
+
+ if (pt->rw_random)
+ pt->rw_active = SCM_PORT_READ;
+
+ if (SCM_READ_BUFFER_EMPTY_P (pt))
+ {
+ if (scm_fill_input (port) == EOF)
+ return 0;
+ }
+
+ n_available = pt->read_end - pt->read_pos;
+
+ while (n_available < size)
+ {
+ memcpy (buffer, pt->read_pos, n_available);
+ buffer += n_available;
+ pt->read_pos += n_available;
+ n_read += n_available;
+
+ if (SCM_READ_BUFFER_EMPTY_P (pt))
+ {
+ if (scm_fill_input (port) == EOF)
+ return n_read;
+ }
+
+ size -= n_available;
+ n_available = pt->read_end - pt->read_pos;
+ }
+
+ memcpy (buffer, pt->read_pos, size);
+ pt->read_pos += size;
+
+ return n_read + size;
+}
+
+/* scm_c_write
+ *
+ * Used by an application to write arbitrary number of bytes to an SCM
+ * port. Similar semantics as libc write. However, unlike libc
+ * write, scm_c_write writes the requested number of bytes and has no
+ * return value.
+ *
+ * Warning: Doesn't update port line and column counts!
+ */
+
+void
+scm_c_write (SCM port, const void *ptr, scm_sizet size)
+{
+ scm_port *pt = SCM_PTAB_ENTRY (port);
+ scm_ptob_descriptor *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
+
+ if (pt->rw_active == SCM_PORT_READ)
+ scm_end_input (port);
+
+ ptob->write (port, ptr, size);
+
+ if (pt->rw_random)
+ pt->rw_active = SCM_PORT_WRITE;
+}
void
scm_flush (SCM port)
object = SCM_COERCE_OUTPORT (object);
- off = SCM_NUM2LONG (2,offset);
- SCM_VALIDATE_INUM_COPY (3,whence,how);
+ off = SCM_NUM2LONG (2, offset);
+ SCM_VALIDATE_INUM_COPY (3, whence, how);
if (how != SEEK_SET && how != SEEK_CUR && how != SEEK_END)
SCM_OUT_OF_RANGE (3, whence);
if (SCM_OPPORTP (object))
#ifndef PORTSH
#define PORTSH
-/* Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999, 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
extern scm_port **scm_port_table;
extern int scm_port_table_size; /* Number of ports in scm_port_table. */
+#define SCM_READ_BUFFER_EMPTY_P(c_port) (c_port->read_pos >= c_port->read_end)
\f
extern SCM scm_read_char (SCM port);
extern void scm_putc (char c, SCM port);
extern void scm_puts (const char *str_data, SCM port);
+extern scm_sizet scm_c_read (SCM port, void *buffer, scm_sizet size);
+extern void scm_c_write (SCM port, const void *buffer, scm_sizet size);
extern void scm_lfwrite (const char *ptr, scm_sizet size, SCM port);
extern void scm_flush (SCM port);
extern void scm_end_input (SCM port);