1 |
/* Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, Inc. |
/* Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, Inc. |
2 |
* |
* |
3 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
4 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
5 |
* the Free Software Foundation; either version 2, or (at your option) |
* the Free Software Foundation; either version 2, or (at your option) |
6 |
* any later version. |
* any later version. |
7 |
* |
* |
8 |
* This program is distributed in the hope that it will be useful, |
* This program is distributed in the hope that it will be useful, |
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
12 |
* |
* |
13 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
14 |
* along with this software; see the file COPYING. If not, write to |
* along with this software; see the file COPYING. If not, write to |
15 |
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
60 |
#else |
#else |
61 |
scm_sizet fwrite (); |
scm_sizet fwrite (); |
62 |
#endif |
#endif |
63 |
#ifdef HAVE_ST_BLKSIZE |
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
64 |
#include <sys/stat.h> |
#include <sys/stat.h> |
65 |
#endif |
#endif |
66 |
|
|
83 |
if (read_size == -1 || write_size == -1) |
if (read_size == -1 || write_size == -1) |
84 |
{ |
{ |
85 |
int default_size; |
int default_size; |
86 |
#ifdef HAVE_ST_BLKSIZE |
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
87 |
struct stat st; |
struct stat st; |
88 |
|
|
89 |
default_size = (fstat (fp->fdes, &st) == -1) ? default_buffer_size |
default_size = (fstat (fp->fdes, &st) == -1) ? default_buffer_size |
90 |
: st.st_blksize; |
: st.st_blksize; |
91 |
#else |
#else |
132 |
SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0); |
SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0); |
133 |
} |
} |
134 |
|
|
135 |
SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0, |
SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0, |
136 |
(SCM port, SCM mode, SCM size), |
(SCM port, SCM mode, SCM size), |
137 |
"Set the buffering mode for @var{port}. @var{mode} can be:\n" |
"Set the buffering mode for @var{port}. @var{mode} can be:\n" |
138 |
"@table @code\n" |
"@table @code\n" |
402 |
FD_ZERO (&except_set); |
FD_ZERO (&except_set); |
403 |
|
|
404 |
FD_SET (fdes, &read_set); |
FD_SET (fdes, &read_set); |
405 |
|
|
406 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
407 |
timeout.tv_usec = 0; |
timeout.tv_usec = 0; |
408 |
|
|
415 |
int remir; |
int remir; |
416 |
ioctl(fdes, FIONREAD, &remir); |
ioctl(fdes, FIONREAD, &remir); |
417 |
return remir; |
return remir; |
418 |
#else |
#else |
419 |
scm_misc_error ("fport_input_waiting", |
scm_misc_error ("fport_input_waiting", |
420 |
"Not fully implemented on this platform", |
"Not fully implemented on this platform", |
421 |
SCM_EOL); |
SCM_EOL); |
423 |
} |
} |
424 |
|
|
425 |
|
|
426 |
static int |
static int |
427 |
prinfport (SCM exp,SCM port,scm_print_state *pstate) |
prinfport (SCM exp,SCM port,scm_print_state *pstate) |
428 |
{ |
{ |
429 |
scm_puts ("#<", port); |
scm_puts ("#<", port); |
430 |
scm_print_port_mode (exp, port); |
scm_print_port_mode (exp, port); |
431 |
if (SCM_OPFPORTP (exp)) |
if (SCM_OPFPORTP (exp)) |
432 |
{ |
{ |
433 |
int fdes; |
int fdes; |
438 |
port); |
port); |
439 |
scm_putc (' ', port); |
scm_putc (' ', port); |
440 |
fdes = (SCM_FSTREAM (exp))->fdes; |
fdes = (SCM_FSTREAM (exp))->fdes; |
441 |
|
|
442 |
if (isatty (fdes)) |
if (isatty (fdes)) |
443 |
scm_puts (ttyname (fdes), port); |
scm_puts (ttyname (fdes), port); |
444 |
else |
else |
552 |
} |
} |
553 |
else /* SCM_PORT_NEITHER */ |
else /* SCM_PORT_NEITHER */ |
554 |
{ |
{ |
555 |
result = rv = lseek (fp->fdes, offset, whence); |
result = rv = lseek (fp->fdes, offset, whence); |
556 |
} |
} |
557 |
|
|
558 |
if (rv == -1) |
if (rv == -1) |
583 |
if (write (fdes, data, size) == -1) |
if (write (fdes, data, size) == -1) |
584 |
scm_syserror ("fport_write"); |
scm_syserror ("fport_write"); |
585 |
} |
} |
586 |
else |
else |
587 |
{ |
{ |
588 |
const char *input = (char *) data; |
const char *input = (char *) data; |
589 |
size_t remaining = size; |
size_t remaining = size; |
609 |
|
|
610 |
/* becomes 1 when process is exiting: normal exception handling won't |
/* becomes 1 when process is exiting: normal exception handling won't |
611 |
work by this time. */ |
work by this time. */ |
612 |
extern int terminating; |
extern int terminating; |
613 |
|
|
614 |
static void |
static void |
615 |
fport_flush (SCM port) |
fport_flush (SCM port) |
630 |
/* error. assume nothing was written this call, but |
/* error. assume nothing was written this call, but |
631 |
fix up the buffer for any previous successful writes. */ |
fix up the buffer for any previous successful writes. */ |
632 |
int done = init_size - remaining; |
int done = init_size - remaining; |
633 |
|
|
634 |
if (done > 0) |
if (done > 0) |
635 |
{ |
{ |
636 |
int i; |
int i; |
668 |
{ |
{ |
669 |
struct scm_fport *fp = SCM_FSTREAM (port); |
struct scm_fport *fp = SCM_FSTREAM (port); |
670 |
scm_port *pt = SCM_PTAB_ENTRY (port); |
scm_port *pt = SCM_PTAB_ENTRY (port); |
671 |
|
|
672 |
offset += pt->read_end - pt->read_pos; |
offset += pt->read_end - pt->read_pos; |
673 |
|
|
674 |
if (offset > 0) |
if (offset > 0) |