more SWI upgrades
This commit is contained in:
parent
42b07768d6
commit
1012f1e1b6
@ -3,9 +3,9 @@
|
|||||||
Part of SWI-Prolog
|
Part of SWI-Prolog
|
||||||
|
|
||||||
Author: Jan Wielemaker
|
Author: Jan Wielemaker
|
||||||
E-mail: wielemak@science.uva.nl
|
E-mail: J.Wielemaker@uva.nl
|
||||||
WWW: http://www.swi-prolog.org
|
WWW: http://www.swi-prolog.org
|
||||||
Copyright (C): 1985-2007, University of Amsterdam
|
Copyright (C): 1985-2009, University of Amsterdam
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -222,6 +222,7 @@ S__setbuf(IOSTREAM *s, char *buffer, size_t size)
|
|||||||
|
|
||||||
free(newunbuf);
|
free(newunbuf);
|
||||||
errno = oldeno;
|
errno = oldeno;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +247,7 @@ S__setbuf(IOSTREAM *s, char *buffer, size_t size)
|
|||||||
|
|
||||||
void
|
void
|
||||||
Ssetbuffer(IOSTREAM *s, char *buffer, size_t size)
|
Ssetbuffer(IOSTREAM *s, char *buffer, size_t size)
|
||||||
{ S__setbuf(s, buffer, size);
|
{ if ( S__setbuf(s, buffer, size) != (size_t)-1 )
|
||||||
s->flags &= ~SIO_USERBUF;
|
s->flags &= ~SIO_USERBUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,8 +340,8 @@ StryLock(IOSTREAM *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
int
|
||||||
S__unlock(IOSTREAM *s)
|
Sunlock(IOSTREAM *s)
|
||||||
{ int rval = 0;
|
{ int rval = 0;
|
||||||
|
|
||||||
#ifdef DEBUG_IO_LOCKS
|
#ifdef DEBUG_IO_LOCKS
|
||||||
@ -359,15 +360,7 @@ S__unlock(IOSTREAM *s)
|
|||||||
{ assert(0);
|
{ assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
Sunlock(IOSTREAM *s)
|
|
||||||
{ int rval = S__unlock(s);
|
|
||||||
SUNLOCK(s);
|
SUNLOCK(s);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,14 +424,13 @@ S__flushbufc(int c, IOSTREAM *s)
|
|||||||
{ char chr = (char)c;
|
{ char chr = (char)c;
|
||||||
|
|
||||||
if ( (*s->functions->write)(s->handle, &chr, 1) != 1 )
|
if ( (*s->functions->write)(s->handle, &chr, 1) != 1 )
|
||||||
{ s->flags |= SIO_FERR;
|
{ S__seterror(s);
|
||||||
c = -1;
|
c = -1;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{ if ( S__setbuf(s, NULL, 0) == (size_t)-1 )
|
{ if ( S__setbuf(s, NULL, 0) == (size_t)-1 )
|
||||||
{ s->flags |= SIO_FERR;
|
|
||||||
c = -1;
|
c = -1;
|
||||||
} else
|
else
|
||||||
*s->bufp++ = (char)c;
|
*s->bufp++ = (char)c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,6 +549,7 @@ S__fillbuf(IOSTREAM *s)
|
|||||||
} else if ( errno == EWOULDBLOCK )
|
} else if ( errno == EWOULDBLOCK )
|
||||||
{ s->bufp = s->buffer;
|
{ s->bufp = s->buffer;
|
||||||
s->limitp = s->buffer;
|
s->limitp = s->buffer;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
} else
|
} else
|
||||||
@ -1410,7 +1403,10 @@ Sfeof(IOSTREAM *s)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
S__seterror(IOSTREAM *s)
|
S__seterror(IOSTREAM *s)
|
||||||
{ if ( s->functions->control )
|
{ s->io_errno = errno;
|
||||||
|
|
||||||
|
if ( !(s->flags&SIO_CLOSING) && /* s->handle is already invalid */
|
||||||
|
s->functions->control )
|
||||||
{ char *msg;
|
{ char *msg;
|
||||||
|
|
||||||
if ( (*s->functions->control)(s->handle,
|
if ( (*s->functions->control)(s->handle,
|
||||||
@ -1441,6 +1437,7 @@ Sfpasteof(IOSTREAM *s)
|
|||||||
void
|
void
|
||||||
Sclearerr(IOSTREAM *s)
|
Sclearerr(IOSTREAM *s)
|
||||||
{ s->flags &= ~(SIO_FEOF|SIO_WARN|SIO_FERR|SIO_FEOF2|SIO_TIMEOUT|SIO_CLEARERR);
|
{ s->flags &= ~(SIO_FEOF|SIO_WARN|SIO_FERR|SIO_FEOF2|SIO_TIMEOUT|SIO_CLEARERR);
|
||||||
|
s->io_errno = 0;
|
||||||
Sseterr(s, 0, NULL);
|
Sseterr(s, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1563,6 +1560,7 @@ Ssize(IOSTREAM *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno = ESPIPE;
|
errno = ESPIPE;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1608,6 +1606,7 @@ Sseek64(IOSTREAM *s, int64_t pos, int whence)
|
|||||||
|
|
||||||
if ( !s->functions->seek && !s->functions->seek64 )
|
if ( !s->functions->seek && !s->functions->seek64 )
|
||||||
{ errno = ESPIPE;
|
{ errno = ESPIPE;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1628,11 +1627,12 @@ Sseek64(IOSTREAM *s, int64_t pos, int whence)
|
|||||||
pos = (*s->functions->seek)(s->handle, (long)pos, whence);
|
pos = (*s->functions->seek)(s->handle, (long)pos, whence);
|
||||||
else
|
else
|
||||||
{ errno = EINVAL;
|
{ errno = EINVAL;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pos < 0 )
|
if ( pos < 0 )
|
||||||
{ errno = EINVAL;
|
{ S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1684,6 +1684,7 @@ Stell64(IOSTREAM *s)
|
|||||||
return pos;
|
return pos;
|
||||||
} else
|
} else
|
||||||
{ errno = EINVAL;
|
{ errno = EINVAL;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1693,10 +1694,13 @@ long
|
|||||||
Stell(IOSTREAM *s)
|
Stell(IOSTREAM *s)
|
||||||
{ int64_t pos = Stell64(s);
|
{ int64_t pos = Stell64(s);
|
||||||
|
|
||||||
|
if ( pos == -1 )
|
||||||
|
return -1;
|
||||||
if ( pos <= LONG_MAX )
|
if ( pos <= LONG_MAX )
|
||||||
return (long) pos;
|
return (long) pos;
|
||||||
|
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
S__seterror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1717,7 +1721,7 @@ Sclose(IOSTREAM *s)
|
|||||||
{ int rval = 0;
|
{ int rval = 0;
|
||||||
|
|
||||||
if ( s->magic != SIO_MAGIC ) /* already closed!? */
|
if ( s->magic != SIO_MAGIC ) /* already closed!? */
|
||||||
{ errno = EINVAL;
|
{ s->io_errno = errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1747,11 +1751,12 @@ Sclose(IOSTREAM *s)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ( s->functions->close && (*s->functions->close)(s->handle) < 0 )
|
if ( s->functions->close && (*s->functions->close)(s->handle) < 0 )
|
||||||
{ s->flags |= SIO_FERR;
|
{ S__seterror(s);
|
||||||
rval = -1;
|
rval = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(s->locks > 0) /* remove buffer-locks */
|
while(s->locks > 0) /* remove buffer-locks */
|
||||||
{ int rc = S__unlock(s);
|
{ int rc = Sunlock(s);
|
||||||
|
|
||||||
if ( rval == 0 )
|
if ( rval == 0 )
|
||||||
rval = rc;
|
rval = rc;
|
||||||
@ -1759,7 +1764,6 @@ Sclose(IOSTREAM *s)
|
|||||||
if ( rval < 0 )
|
if ( rval < 0 )
|
||||||
reportStreamError(s);
|
reportStreamError(s);
|
||||||
run_close_hooks(s); /* deletes Prolog registration */
|
run_close_hooks(s); /* deletes Prolog registration */
|
||||||
|
|
||||||
SUNLOCK(s);
|
SUNLOCK(s);
|
||||||
|
|
||||||
#ifdef O_PLMT
|
#ifdef O_PLMT
|
||||||
@ -1771,6 +1775,8 @@ Sclose(IOSTREAM *s)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
s->magic = SIO_CMAGIC;
|
s->magic = SIO_CMAGIC;
|
||||||
|
if ( s->message )
|
||||||
|
free(s->message);
|
||||||
if ( !(s->flags & SIO_STATIC) )
|
if ( !(s->flags & SIO_STATIC) )
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
@ -1826,8 +1832,7 @@ Sgets(char *buf)
|
|||||||
|
|
||||||
int
|
int
|
||||||
Sfputs(const char *q, IOSTREAM *s)
|
Sfputs(const char *q, IOSTREAM *s)
|
||||||
{
|
{ for( ; *q; q++)
|
||||||
for( ; *q; q++)
|
|
||||||
{ if ( Sputcode(*q&0xff, s) < 0 )
|
{ if ( Sputcode(*q&0xff, s) < 0 )
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
@ -2003,7 +2008,7 @@ Svfprintf(IOSTREAM *s, const char *fm, va_list args)
|
|||||||
v = va_arg(args, int);
|
v = va_arg(args, int);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
v = va_arg(args, intptr_t);
|
v = va_arg(args, long);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
vl = va_arg(args, int64_t);
|
vl = va_arg(args, int64_t);
|
||||||
@ -2660,6 +2665,15 @@ IOFUNCTIONS Sttyfunctions =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
(*) Windows isatty() is totally broken since VC9; crashing the
|
||||||
|
application instead of returning EINVAL on wrong values of fd. As we
|
||||||
|
provide the socket-id through Sfileno, this code crashes on
|
||||||
|
tcp_open_socket(). As ttys and its detection is of no value on Windows
|
||||||
|
anyway, we skip this. Second, Windows doesn't have fork(), so FD_CLOEXEC
|
||||||
|
is of no value.
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
IOSTREAM *
|
IOSTREAM *
|
||||||
Snew(void *handle, int flags, IOFUNCTIONS *functions)
|
Snew(void *handle, int flags, IOFUNCTIONS *functions)
|
||||||
{ IOSTREAM *s;
|
{ IOSTREAM *s;
|
||||||
@ -2692,8 +2706,16 @@ Snew(void *handle, int flags, IOFUNCTIONS *functions)
|
|||||||
recursiveMutexInit(s->mutex);
|
recursiveMutexInit(s->mutex);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ( (fd = Sfileno(s)) >= 0 && isatty(fd) )
|
|
||||||
|
#ifndef __WINDOWS__ /* (*) */
|
||||||
|
if ( (fd = Sfileno(s)) >= 0 )
|
||||||
|
{ if ( isatty(fd) )
|
||||||
s->flags |= SIO_ISATTY;
|
s->flags |= SIO_ISATTY;
|
||||||
|
#if defined(F_SETFD) && defined(FD_CLOEXEC)
|
||||||
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -2718,7 +2740,7 @@ IOSTREAM *
|
|||||||
Sopen_file(const char *path, const char *how)
|
Sopen_file(const char *path, const char *how)
|
||||||
{ int fd;
|
{ int fd;
|
||||||
int oflags = O_BINARY;
|
int oflags = O_BINARY;
|
||||||
int flags = SIO_FILE|SIO_TEXT|SIO_RECORDPOS;
|
int flags = SIO_FILE|SIO_TEXT|SIO_RECORDPOS|SIO_FBUF;
|
||||||
int op = *how++;
|
int op = *how++;
|
||||||
intptr_t lfd;
|
intptr_t lfd;
|
||||||
enum {lnone=0,lread,lwrite} lock = lnone;
|
enum {lnone=0,lread,lwrite} lock = lnone;
|
||||||
@ -2830,8 +2852,8 @@ Sopen_file(const char *path, const char *how)
|
|||||||
|
|
||||||
IOSTREAM *
|
IOSTREAM *
|
||||||
Sfdopen(int fd, const char *type)
|
Sfdopen(int fd, const char *type)
|
||||||
{ int flags;
|
{ intptr_t lfd;
|
||||||
intptr_t lfd;
|
int flags = SIO_FILE|SIO_RECORDPOS|SIO_FBUF;
|
||||||
|
|
||||||
if ( fd < 0 )
|
if ( fd < 0 )
|
||||||
{ errno = EINVAL;
|
{ errno = EINVAL;
|
||||||
@ -2843,9 +2865,15 @@ Sfdopen(int fd, const char *type)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( *type == 'r' )
|
if ( *type == 'r' )
|
||||||
flags = SIO_FILE|SIO_INPUT|SIO_RECORDPOS;
|
{ flags |= SIO_INPUT;
|
||||||
else
|
} else if ( *type == 'w' )
|
||||||
flags = SIO_FILE|SIO_OUTPUT|SIO_RECORDPOS;
|
{ flags |= SIO_OUTPUT;
|
||||||
|
} else
|
||||||
|
{ errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if ( type[1] != 'b' )
|
||||||
|
flags |= SIO_TEXT;
|
||||||
|
|
||||||
lfd = (intptr_t)fd;
|
lfd = (intptr_t)fd;
|
||||||
|
|
||||||
@ -2948,9 +2976,9 @@ Sopen_pipe(const char *command, const char *type)
|
|||||||
{ int flags;
|
{ int flags;
|
||||||
|
|
||||||
if ( *type == 'r' )
|
if ( *type == 'r' )
|
||||||
flags = SIO_PIPE|SIO_INPUT;
|
flags = SIO_PIPE|SIO_INPUT|SIO_FBUF;
|
||||||
else
|
else
|
||||||
flags = SIO_PIPE|SIO_OUTPUT;
|
flags = SIO_PIPE|SIO_OUTPUT|SIO_FBUF;
|
||||||
|
|
||||||
return Snew((void *)fd, flags, &Spipefunctions);
|
return Snew((void *)fd, flags, &Spipefunctions);
|
||||||
}
|
}
|
||||||
@ -3004,7 +3032,7 @@ Swrite_memfile(void *handle, char *buf, size_t size)
|
|||||||
{ memfile *mf = handle;
|
{ memfile *mf = handle;
|
||||||
|
|
||||||
if ( mf->here + size + 1 >= mf->allocated )
|
if ( mf->here + size + 1 >= mf->allocated )
|
||||||
{ intptr_t ns = S__memfile_nextsize(mf->here + size + 1);
|
{ size_t ns = S__memfile_nextsize(mf->here + size + 1);
|
||||||
char *nb;
|
char *nb;
|
||||||
|
|
||||||
if ( mf->allocated == 0 || !mf->malloced )
|
if ( mf->allocated == 0 || !mf->malloced )
|
||||||
@ -3416,7 +3444,17 @@ Scleanup(void)
|
|||||||
|
|
||||||
s->bufp = s->buffer; /* avoid actual flush */
|
s->bufp = s->buffer; /* avoid actual flush */
|
||||||
S__removebuf(s);
|
S__removebuf(s);
|
||||||
|
|
||||||
|
#ifdef O_PLMT
|
||||||
|
if ( S__iob[i].mutex )
|
||||||
|
{ recursiveMutex *m = S__iob[i].mutex;
|
||||||
|
|
||||||
|
S__iob[i].mutex = NULL;
|
||||||
|
recursiveMutexDelete(m);
|
||||||
|
free(m);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
*s = S__iob0[i]; /* re-initialise */
|
*s = S__iob0[i]; /* re-initialise */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user