mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 12:20:26 +02:00
Rewrite fport_flush' using Gnulib's
full_write'.
* libguile/fports.c (fport_flush): Rewrite using `full_write'.
This commit is contained in:
parent
72a54e9480
commit
5335850dbf
1 changed files with 7 additions and 35 deletions
|
@ -52,6 +52,8 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <full-write.h>
|
||||||
|
|
||||||
#include "libguile/iselect.h"
|
#include "libguile/iselect.h"
|
||||||
|
|
||||||
/* Some defines for Windows (native port, not Cygwin). */
|
/* Some defines for Windows (native port, not Cygwin). */
|
||||||
|
@ -823,45 +825,15 @@ fport_write (SCM port, const void *data, size_t size)
|
||||||
static void
|
static void
|
||||||
fport_flush (SCM port)
|
fport_flush (SCM port)
|
||||||
{
|
{
|
||||||
|
size_t written;
|
||||||
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
scm_t_fport *fp = SCM_FSTREAM (port);
|
scm_t_fport *fp = SCM_FSTREAM (port);
|
||||||
unsigned char *ptr = pt->write_buf;
|
size_t count = pt->write_pos - pt->write_buf;
|
||||||
long init_size = pt->write_pos - pt->write_buf;
|
|
||||||
long remaining = init_size;
|
|
||||||
|
|
||||||
while (remaining > 0)
|
written = full_write (fp->fdes, pt->write_buf, count);
|
||||||
{
|
if (written < count)
|
||||||
long count;
|
scm_syserror ("scm_flush");
|
||||||
|
|
||||||
SCM_SYSCALL (count = write (fp->fdes, ptr, remaining));
|
|
||||||
if (count < 0)
|
|
||||||
{
|
|
||||||
/* error. assume nothing was written this call, but
|
|
||||||
fix up the buffer for any previous successful writes. */
|
|
||||||
long done = init_size - remaining;
|
|
||||||
|
|
||||||
if (done > 0)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < remaining; i++)
|
|
||||||
{
|
|
||||||
*(pt->write_buf + i) = *(pt->write_buf + done + i);
|
|
||||||
}
|
|
||||||
pt->write_pos = pt->write_buf + remaining;
|
|
||||||
}
|
|
||||||
if (scm_gc_running_p)
|
|
||||||
{
|
|
||||||
/* silently ignore the error. scm_error would abort if we
|
|
||||||
called it now. */
|
|
||||||
count = remaining;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
scm_syserror ("fport_flush");
|
|
||||||
}
|
|
||||||
ptr += count;
|
|
||||||
remaining -= count;
|
|
||||||
}
|
|
||||||
pt->write_pos = pt->write_buf;
|
pt->write_pos = pt->write_buf;
|
||||||
pt->rw_active = SCM_PORT_NEITHER;
|
pt->rw_active = SCM_PORT_NEITHER;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue