1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

* filesys.c, filesys.h (scm_input_waiting_p): Moved from ports.c.

Motivation: This is system specific code which is related to file
 	I/O.  It also may use select.  Added code by Gary Houston to
 	detect presence of character in stdio buffers.
This commit is contained in:
Mikael Djurfeldt 1996-10-30 23:31:11 +00:00
parent 7adf98eeb4
commit 66b47b6c79
2 changed files with 115 additions and 0 deletions

View file

@ -988,6 +988,9 @@ retrieve_select_type (set, list)
}
/* {Checking for events}
*/
SCM_PROC (s_sys_select, "select", 3, 2, 0, scm_sys_select);
SCM
@ -1050,6 +1053,117 @@ scm_sys_select (reads, writes, excepts, secs, msecs)
#endif
}
/* Check if FILE has characters waiting to be read. */
#ifdef __IBMC__
# define MSDOS
#endif
#ifdef MSDOS
# ifndef GO32
# include <io.h>
# include <conio.h>
int
scm_input_waiting_p (f, caller)
FILE *f;
char *caller;
{
if (feof (f))
return 1;
if (fileno (f) == fileno (stdin) && (isatty (fileno (stdin))))
return kbhit ();
return -1;
}
# endif
#else
# ifdef _DCC
# include <ioctl.h>
# else
# ifndef AMIGA
# ifndef vms
# ifdef MWC
# include <sys/io.h>
# else
# ifndef THINK_C
# ifndef ARM_ULIB
# include <sys/ioctl.h>
# endif
# endif
# endif
# endif
# endif
# endif
int
scm_input_waiting_p (f, caller)
FILE *f;
char *caller;
{
/* Can we return an end-of-file character? */
if (feof (f))
return 1;
/* Do we have characters in the stdio buffer? */
# ifdef FILE_CNT_FIELD
if (f->FILE_CNT_FIELD > 0)
return 1;
# else
# ifdef FILE_CNT_GPTR
if (f->_gptr != f->_egptr)
return 1;
# else
# ifdef FILE_CNT_READPTR
if (f->_IO_read_end != f->_IO_read_ptr)
return 1;
# else
Configure.in could not guess the name of the correct field in a FILE *.
This function needs to be ported to your system.
It should return zero iff no characters are waiting to be read.;
# endif
# endif
# endif
/* Is the file prepared to deliver input? */
# ifdef FIONREAD
{
long remir;
ioctl(fileno(f), FIONREAD, &remir);
return remir;
}
# else
# ifdef HAVE_SELECT
{
struct timeval timeout;
SELECT_TYPE read_set;
SELECT_TYPE write_set;
SELECT_TYPE except_set;
int fno = fileno ((FILE *)f);
FD_ZERO (&read_set);
FD_ZERO (&write_set);
FD_ZERO (&except_set);
FD_SET (fno, &read_set);
timeout.tv_sec = 0;
timeout.tv_usec = 0;
SCM_DEFER_INTS;
if (select (SELECT_SET_SIZE,
&read_set, &write_set, &except_set, &timeout)
< 0)
scm_syserror (caller);
SCM_ALLOW_INTS;
return FD_ISSET (fno, &read_set);
}
# else
return -1;
# endif
# endif
}
#endif
/* {Symbolic Links}
*/

View file

@ -95,6 +95,7 @@ extern SCM scm_sys_closedir SCM_P ((SCM port));
extern SCM scm_sys_chdir SCM_P ((SCM str));
extern SCM scm_sys_getcwd SCM_P ((void));
extern SCM scm_sys_select SCM_P ((SCM reads, SCM writes, SCM excepts, SCM secs, SCM msecs));
extern int scm_input_waiting_p SCM_P ((FILE *file, char *caller));
extern SCM scm_sys_symlink SCM_P ((SCM oldpath, SCM newpath));
extern SCM scm_sys_readlink SCM_P ((SCM path));
extern SCM scm_sys_lstat SCM_P ((SCM str));