1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

Don't use local_fgets on sockets; ftell doesn't work on sockets.

(Thanks to Jorgen "forcer" Schaefer.)
* ports.h (SCM_NOFTELL): New flag.
* fports.c (local_fgets): If it's set, use the generic fgets.
* socket.c (scm_socket): Set SCM_NOFTELL on the ports we produce.
This commit is contained in:
Jim Blandy 1998-10-17 18:10:30 +00:00
parent ccd9642e20
commit d9803e92ba
3 changed files with 12 additions and 0 deletions

View file

@ -416,6 +416,16 @@ local_fgets (SCM port, int *len)
pre_read (port);
/* If this is a socket port or something where we can't rely on
ftell to determine how much we've read, then call the generic
function. We could use a separate scm_ptobfuns table with
scm_generic_fgets, but then we'd have to change SCM_FPORTP, etc.
Ideally, it should become something that means "this port has a
file descriptor"; sometimes we reject sockets when we shouldn't.
But I'm too stupid at the moment to do that right. */
if (SCM_CAR (port) & SCM_NOFTELL)
return scm_generic_fgets (port, len);
f = (FILE *) SCM_STREAM (port);
if (feof (f))
return NULL;

View file

@ -83,6 +83,7 @@ extern int scm_port_table_size; /* Number of ports in scm_port_table. */
#define SCM_RDNG (2L<<16) /* Is it a readable port? */
#define SCM_WRTNG (4L<<16) /* Is it writable? */
#define SCM_BUF0 (8L<<16)
#define SCM_NOFTELL (16L<<16) /* Does ftell work on this? Yuck! */
#define SCM_CRDY (32L<<16) /* Should char-ready? return #t? */
/* A mask used to clear the char-ready port flag. */

View file

@ -107,6 +107,7 @@ scm_socket (family, style, proto)
SCM_DEFER_INTS;
fd = socket (SCM_INUM (family), SCM_INUM (style), SCM_INUM (proto));
result = scm_sock_fd_to_port (fd, s_socket);
SCM_SETOR_CAR (result, SCM_NOFTELL);
SCM_ALLOW_INTS;
return result;
}