signed wchar
This commit is contained in:
parent
4d3d9c408d
commit
71f0076ed6
25
os/format.c
25
os/format.c
@ -233,10 +233,10 @@ output is directed to the stream used by format/2.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "yapio.h"
|
|
||||||
#include "YapText.h"
|
#include "YapText.h"
|
||||||
|
#include "Yatom.h"
|
||||||
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -257,8 +257,8 @@ output is directed to the stream used by format/2.
|
|||||||
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "iopreds.h"
|
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
|
#include "iopreds.h"
|
||||||
|
|
||||||
#define FORMAT_MAX_SIZE 1024
|
#define FORMAT_MAX_SIZE 1024
|
||||||
|
|
||||||
@ -618,7 +618,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
goto do_type_atom_error;
|
goto do_type_atom_error;
|
||||||
yhandle_t sl = Yap_StartSlots();
|
yhandle_t sl = Yap_StartSlots();
|
||||||
// stream is already locked.
|
// stream is already locked.
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0, Handle_vars_f | To_heap_f, GLOBAL_MaxPriority);
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0, Handle_vars_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(sl);
|
Yap_CloseSlots(sl);
|
||||||
break;
|
break;
|
||||||
case 'c': {
|
case 'c': {
|
||||||
@ -810,8 +811,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
char *pt, *res;
|
char *pt, *res;
|
||||||
|
|
||||||
tmpbase = tmp1;
|
tmpbase = tmp1;
|
||||||
while (!(res = Yap_gmp_to_string(t, tmpbase, TMP_STRING_SIZE,
|
while (!(
|
||||||
radix))) {
|
res = Yap_gmp_to_string(t, tmpbase, TMP_STRING_SIZE, radix))) {
|
||||||
if (tmpbase == tmp1) {
|
if (tmpbase == tmp1) {
|
||||||
tmpbase = NULL;
|
tmpbase = NULL;
|
||||||
} else {
|
} else {
|
||||||
@ -871,7 +872,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
t = targs[targ++];
|
t = targs[targ++];
|
||||||
yhandle_t sl = Yap_StartSlots();
|
yhandle_t sl = Yap_StartSlots();
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
||||||
Quote_illegal_f | Ignore_ops_f | To_heap_f, GLOBAL_MaxPriority);
|
Quote_illegal_f | Ignore_ops_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(sl);
|
Yap_CloseSlots(sl);
|
||||||
break;
|
break;
|
||||||
case '@':
|
case '@':
|
||||||
@ -910,7 +912,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
{
|
{
|
||||||
Int sl = Yap_InitSlot(args);
|
Int sl = Yap_InitSlot(args);
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
||||||
Handle_vars_f | Use_portray_f | To_heap_f, GLOBAL_MaxPriority);
|
Handle_vars_f | Use_portray_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
args = Yap_GetFromSlot(sl);
|
args = Yap_GetFromSlot(sl);
|
||||||
Yap_CloseSlots(sl);
|
Yap_CloseSlots(sl);
|
||||||
}
|
}
|
||||||
@ -936,7 +939,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
t = targs[targ++];
|
t = targs[targ++];
|
||||||
yhandle_t sl0 = Yap_StartSlots();
|
yhandle_t sl0 = Yap_StartSlots();
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
||||||
Handle_vars_f | Quote_illegal_f | To_heap_f, GLOBAL_MaxPriority);
|
Handle_vars_f | Quote_illegal_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(sl0);
|
Yap_CloseSlots(sl0);
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
@ -1022,8 +1026,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
else
|
else
|
||||||
finfo.pad_entries[finfo.padders].filler = fptr[-2];
|
finfo.pad_entries[finfo.padders].filler = fptr[-2];
|
||||||
finfo.padders++;
|
finfo.padders++;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
do_instantiation_error:
|
do_instantiation_error:
|
||||||
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
|
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
|
||||||
goto do_default_error;
|
goto do_default_error;
|
||||||
|
11
os/getw.h
11
os/getw.h
@ -24,7 +24,7 @@ static int GETW(int sno) {
|
|||||||
case ENC_ISO_ANSI: {
|
case ENC_ISO_ANSI: {
|
||||||
char buf[8];
|
char buf[8];
|
||||||
int out;
|
int out;
|
||||||
int wch;
|
wchar_t wch;
|
||||||
mbstate_t mbstate;
|
mbstate_t mbstate;
|
||||||
|
|
||||||
memset((void *)&(mbstate), 0, sizeof(mbstate_t));
|
memset((void *)&(mbstate), 0, sizeof(mbstate_t));
|
||||||
@ -80,7 +80,8 @@ case ENC_ISO_UTF8: {
|
|||||||
int c3 = GETC();
|
int c3 = GETC();
|
||||||
if (c3 == -1)
|
if (c3 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = ((ch & 7)<<18) | ((c1 & 0x3f)<<12) | ((c2 & 0x3f)<<6) | (c3 & 0x3f);
|
wch = ((ch & 7) << 18) | ((c1 & 0x3f) << 12) | ((c2 & 0x3f) << 6) |
|
||||||
|
(c3 & 0x3f);
|
||||||
return post_process_read_wchar(wch, 4, st);
|
return post_process_read_wchar(wch, 4, st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,7 +106,6 @@ case ENC_UTF16_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|||||||
return post_process_read_wchar(wch, 2, st);
|
return post_process_read_wchar(wch, 2, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case ENC_UTF16_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
case ENC_UTF16_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
@ -138,7 +138,6 @@ case ENC_UTF16_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|||||||
return post_process_read_wchar(wch, 2, st);
|
return post_process_read_wchar(wch, 2, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case ENC_UCS2_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
case ENC_UCS2_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
@ -199,5 +198,9 @@ case ENC_ISO_UTF32_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|||||||
}
|
}
|
||||||
return post_process_read_wchar(wch, 4, st);
|
return post_process_read_wchar(wch, 4, st);
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkIntTerm(st->encoding),
|
||||||
|
"Bad Encoding\n");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
96
os/iopreds.c
96
os/iopreds.c
@ -33,12 +33,15 @@ static char SccsId[] = "%W% %G%";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "yapio.h"
|
|
||||||
#include "eval.h"
|
|
||||||
#include "YapText.h"
|
#include "YapText.h"
|
||||||
|
#include "Yatom.h"
|
||||||
|
#include "eval.h"
|
||||||
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#if HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#if HAVE_STDARG_H
|
#if HAVE_STDARG_H
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#endif
|
#endif
|
||||||
@ -96,7 +99,6 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#endif
|
#endif
|
||||||
#include "iopreds.h"
|
#include "iopreds.h"
|
||||||
|
|
||||||
|
|
||||||
#define GETW get_wchar_from_FILE
|
#define GETW get_wchar_from_FILE
|
||||||
#define GETC() fgetwc(st->file)
|
#define GETC() fgetwc(st->file)
|
||||||
#include "getw.h"
|
#include "getw.h"
|
||||||
@ -248,7 +250,7 @@ static void unix_upd_stream_info(StreamDesc *s) {
|
|||||||
filedes = fileno(s->file);
|
filedes = fileno(s->file);
|
||||||
if (isatty(filedes)) {
|
if (isatty(filedes)) {
|
||||||
#if HAVE_TTYNAME
|
#if HAVE_TTYNAME
|
||||||
char *ttys = ttyname(filedes);
|
char *ttys = ttyname_r(filedes, LOCAL_FileNameBuf, YAP_FILENAME_MAX - 1);
|
||||||
if (ttys == NULL)
|
if (ttys == NULL)
|
||||||
s->name = AtomTty;
|
s->name = AtomTty;
|
||||||
else
|
else
|
||||||
@ -266,7 +268,6 @@ static void unix_upd_stream_info(StreamDesc *s) {
|
|||||||
s->status |= Seekable_Stream_f;
|
s->status |= Seekable_Stream_f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void InitFileIO(StreamDesc *s) {
|
static void InitFileIO(StreamDesc *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
if (s->status & Socket_Stream_f) {
|
if (s->status & Socket_Stream_f) {
|
||||||
@ -660,7 +661,6 @@ int post_process_read_wchar(int ch, size_t n, StreamDesc *s) {
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int post_process_weof(StreamDesc *s) {
|
int post_process_weof(StreamDesc *s) {
|
||||||
if (!ResetEOF(s)) {
|
if (!ResetEOF(s)) {
|
||||||
s->status |= Eof_Stream_f;
|
s->status |= Eof_Stream_f;
|
||||||
@ -692,7 +692,6 @@ int PlGetc(int sno) {
|
|||||||
return fgetc(s->file);
|
return fgetc(s->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// layered version
|
// layered version
|
||||||
static int get_wchar__(int sno) { return fgetwc(GLOBAL_Stream[sno].file); }
|
static int get_wchar__(int sno) { return fgetwc(GLOBAL_Stream[sno].file); }
|
||||||
|
|
||||||
@ -793,8 +792,7 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
break;
|
break;
|
||||||
case ENC_UTF16_LE:
|
case ENC_UTF16_LE: {
|
||||||
{
|
|
||||||
if (ch < 0x10000) {
|
if (ch < 0x10000) {
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch & 0xff));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch & 0xff));
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||||
@ -811,8 +809,7 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
case ENC_UTF16_BE:
|
case ENC_UTF16_BE: {
|
||||||
{
|
|
||||||
// computations
|
// computations
|
||||||
if (ch < 0x10000) {
|
if (ch < 0x10000) {
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||||
@ -825,12 +822,10 @@ int PlGetc(int sno) {
|
|||||||
GLOBAL_Stream[sno].stream_putc(sno, (lead & 0xff));
|
GLOBAL_Stream[sno].stream_putc(sno, (lead & 0xff));
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (trail >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (trail >> 8));
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (trail & 0xff));
|
GLOBAL_Stream[sno].stream_putc(sno, (trail & 0xff));
|
||||||
|
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
case ENC_UCS2_LE:
|
case ENC_UCS2_LE: {
|
||||||
{
|
|
||||||
if (ch >= 0x10000) {
|
if (ch >= 0x10000) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -838,8 +833,7 @@ int PlGetc(int sno) {
|
|||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
case ENC_UCS2_BE:
|
case ENC_UCS2_BE: {
|
||||||
{
|
|
||||||
// computations
|
// computations
|
||||||
if (ch < 0x10000) {
|
if (ch < 0x10000) {
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||||
@ -870,8 +864,8 @@ int PlGetc(int sno) {
|
|||||||
/* used by user-code to read characters from the current input stream */
|
/* used by user-code to read characters from the current input stream */
|
||||||
int Yap_PlGetchar(void) {
|
int Yap_PlGetchar(void) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return (GLOBAL_Stream[LOCAL_c_input_stream].stream_getc(
|
return (
|
||||||
LOCAL_c_input_stream));
|
GLOBAL_Stream[LOCAL_c_input_stream].stream_getc(LOCAL_c_input_stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yap_PlGetWchar(void) {
|
int Yap_PlGetWchar(void) {
|
||||||
@ -1079,8 +1073,7 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Yap_initStream(int sno, FILE *fd, const char *name, Term file_name,
|
bool Yap_initStream(int sno, FILE *fd, const char *name, Term file_name,
|
||||||
encoding_t encoding, stream_flags_t flags,
|
encoding_t encoding, stream_flags_t flags, Atom open_mode) {
|
||||||
Atom open_mode) {
|
|
||||||
StreamDesc *st = &GLOBAL_Stream[sno];
|
StreamDesc *st = &GLOBAL_Stream[sno];
|
||||||
st->status = flags;
|
st->status = flags;
|
||||||
|
|
||||||
@ -1146,8 +1139,8 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define OPEN_DEFS() \
|
#define OPEN_DEFS() \
|
||||||
PAR("alias", isatom, OPEN_ALIAS), PAR("bom", booleanFlag, OPEN_BOM), \
|
PAR("alias", isatom, OPEN_ALIAS) \
|
||||||
PAR("buffer", isatom, OPEN_BUFFER), \
|
, PAR("bom", booleanFlag, OPEN_BOM), PAR("buffer", isatom, OPEN_BUFFER), \
|
||||||
PAR("close_on_abort", booleanFlag, OPEN_CLOSE_ON_ABORT), \
|
PAR("close_on_abort", booleanFlag, OPEN_CLOSE_ON_ABORT), \
|
||||||
PAR("create", isatom, OPEN_CREATE), \
|
PAR("create", isatom, OPEN_CREATE), \
|
||||||
PAR("encoding", isatom, OPEN_ENCODING), \
|
PAR("encoding", isatom, OPEN_ENCODING), \
|
||||||
@ -1172,8 +1165,8 @@ int PlGetc(int sno) {
|
|||||||
static const param_t open_defs[] = {OPEN_DEFS()};
|
static const param_t open_defs[] = {OPEN_DEFS()};
|
||||||
#undef PAR
|
#undef PAR
|
||||||
|
|
||||||
static Int do_open(
|
static Int
|
||||||
Term file_name, Term t2,
|
do_open(Term file_name, Term t2,
|
||||||
Term tlist USES_REGS) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
Term tlist USES_REGS) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||||
Atom open_mode;
|
Atom open_mode;
|
||||||
int sno;
|
int sno;
|
||||||
@ -1279,8 +1272,7 @@ int PlGetc(int sno) {
|
|||||||
|
|
||||||
// Skip scripts that start with !#/.. or similar
|
// Skip scripts that start with !#/.. or similar
|
||||||
bool script =
|
bool script =
|
||||||
(args[OPEN_SCRIPT].used ? args[OPEN_SCRIPT].tvalue == TermTrue
|
(args[OPEN_SCRIPT].used ? args[OPEN_SCRIPT].tvalue == TermTrue : false);
|
||||||
: false);
|
|
||||||
// binary type
|
// binary type
|
||||||
if (args[OPEN_TYPE].used) {
|
if (args[OPEN_TYPE].used) {
|
||||||
Term t = args[OPEN_TYPE].tvalue;
|
Term t = args[OPEN_TYPE].tvalue;
|
||||||
@ -1328,11 +1320,11 @@ int PlGetc(int sno) {
|
|||||||
fname = LOCAL_FileNameBuf;
|
fname = LOCAL_FileNameBuf;
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s",
|
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s", fname,
|
||||||
fname, strerror(errno)));
|
strerror(errno)));
|
||||||
else {
|
else {
|
||||||
return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name,
|
return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name, "%s: %s",
|
||||||
"%s: %s", fname, strerror(errno)));
|
fname, strerror(errno)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if MAC
|
#if MAC
|
||||||
@ -1341,11 +1333,9 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
flags &= ~(Free_Stream_f);
|
flags &= ~(Free_Stream_f);
|
||||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags,
|
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags, open_mode))
|
||||||
open_mode))
|
|
||||||
return false;
|
return false;
|
||||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags,
|
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags, open_mode))
|
||||||
open_mode))
|
|
||||||
return false;
|
return false;
|
||||||
if (open_mode == AtomWrite) {
|
if (open_mode == AtomWrite) {
|
||||||
if (needs_bom && !write_bom(sno, st))
|
if (needs_bom && !write_bom(sno, st))
|
||||||
@ -1389,8 +1379,7 @@ int PlGetc(int sno) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Int open3(
|
static Int open3(USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||||
USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
|
||||||
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1472,13 +1461,11 @@ int PlGetc(int sno) {
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static Int open4(
|
static Int open4(USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||||
USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
|
||||||
return do_open(Deref(ARG1), Deref(ARG2), Deref(ARG4) PASS_REGS);
|
return do_open(Deref(ARG1), Deref(ARG2), Deref(ARG4) PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_file_expansion(
|
static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
||||||
USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
|
||||||
Term file_name = Deref(ARG1);
|
Term file_name = Deref(ARG1);
|
||||||
|
|
||||||
/* we know file_name is bound */
|
/* we know file_name is bound */
|
||||||
@ -1549,8 +1536,8 @@ int PlGetc(int sno) {
|
|||||||
#define CheckStream(arg, kind, msg) \
|
#define CheckStream(arg, kind, msg) \
|
||||||
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
||||||
|
|
||||||
static int CheckStream__(const char *file, const char *f, int line,
|
static int CheckStream__(const char *file, const char *f, int line, Term arg,
|
||||||
Term arg, int kind, const char *msg) {
|
int kind, const char *msg) {
|
||||||
int sno = -1;
|
int sno = -1;
|
||||||
arg = Deref(arg);
|
arg = Deref(arg);
|
||||||
if (IsVarTerm(arg)) {
|
if (IsVarTerm(arg)) {
|
||||||
@ -1613,8 +1600,8 @@ int PlGetc(int sno) {
|
|||||||
return CheckStream__(file, f, line, arg, kind, msg);
|
return CheckStream__(file, f, line, arg, kind, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yap_CheckTextStream__(const char *file, const char *f, int line,
|
int Yap_CheckTextStream__(const char *file, const char *f, int line, Term arg,
|
||||||
Term arg, int kind, const char *msg) {
|
int kind, const char *msg) {
|
||||||
int sno;
|
int sno;
|
||||||
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1683,8 +1670,7 @@ int PlGetc(int sno) {
|
|||||||
|
|
||||||
(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
||||||
Int sno = CheckStream(
|
Int sno = CheckStream(
|
||||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f),
|
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
|
||||||
"close/2");
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
if (sno <= StdErrStream) {
|
if (sno <= StdErrStream) {
|
||||||
@ -1722,8 +1708,7 @@ int PlGetc(int sno) {
|
|||||||
*/
|
*/
|
||||||
static Int close2(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
static Int close2(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
||||||
Int sno = CheckStream(
|
Int sno = CheckStream(
|
||||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f),
|
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
|
||||||
"close/2");
|
|
||||||
Term tlist;
|
Term tlist;
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@ -1762,8 +1747,8 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ABSOLUTE_FILE_NAME_DEFS() \
|
#define ABSOLUTE_FILE_NAME_DEFS() \
|
||||||
PAR("access", isatom, ABSOLUTE_FILE_NAME_ACCESS), \
|
PAR("access", isatom, ABSOLUTE_FILE_NAME_ACCESS) \
|
||||||
PAR("expand", booleanFlag, ABSOLUTE_FILE_NAME_EXPAND), \
|
, PAR("expand", booleanFlag, ABSOLUTE_FILE_NAME_EXPAND), \
|
||||||
PAR("extensions", ok, ABSOLUTE_FILE_NAME_EXTENSIONS), \
|
PAR("extensions", ok, ABSOLUTE_FILE_NAME_EXTENSIONS), \
|
||||||
PAR("file_errors", is_file_errors, ABSOLUTE_FILE_NAME_FILE_ERRORS), \
|
PAR("file_errors", is_file_errors, ABSOLUTE_FILE_NAME_FILE_ERRORS), \
|
||||||
PAR("file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE), \
|
PAR("file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE), \
|
||||||
@ -1817,8 +1802,7 @@ int PlGetc(int sno) {
|
|||||||
t[ABSOLUTE_FILE_NAME_RELATIVE_TO] = gethdir(TermDot);
|
t[ABSOLUTE_FILE_NAME_RELATIVE_TO] = gethdir(TermDot);
|
||||||
}
|
}
|
||||||
if (args[ABSOLUTE_FILE_NAME_FILE_TYPE].used)
|
if (args[ABSOLUTE_FILE_NAME_FILE_TYPE].used)
|
||||||
t[ABSOLUTE_FILE_NAME_FILE_TYPE] =
|
t[ABSOLUTE_FILE_NAME_FILE_TYPE] = args[ABSOLUTE_FILE_NAME_FILE_TYPE].tvalue;
|
||||||
args[ABSOLUTE_FILE_NAME_FILE_TYPE].tvalue;
|
|
||||||
else
|
else
|
||||||
t[ABSOLUTE_FILE_NAME_FILE_TYPE] = TermTxt;
|
t[ABSOLUTE_FILE_NAME_FILE_TYPE] = TermTxt;
|
||||||
if (args[ABSOLUTE_FILE_NAME_ACCESS].used)
|
if (args[ABSOLUTE_FILE_NAME_ACCESS].used)
|
||||||
@ -1831,8 +1815,7 @@ int PlGetc(int sno) {
|
|||||||
else
|
else
|
||||||
t[ABSOLUTE_FILE_NAME_FILE_ERRORS] = TermError;
|
t[ABSOLUTE_FILE_NAME_FILE_ERRORS] = TermError;
|
||||||
if (args[ABSOLUTE_FILE_NAME_SOLUTIONS].used)
|
if (args[ABSOLUTE_FILE_NAME_SOLUTIONS].used)
|
||||||
t[ABSOLUTE_FILE_NAME_SOLUTIONS] =
|
t[ABSOLUTE_FILE_NAME_SOLUTIONS] = args[ABSOLUTE_FILE_NAME_SOLUTIONS].tvalue;
|
||||||
args[ABSOLUTE_FILE_NAME_SOLUTIONS].tvalue;
|
|
||||||
else
|
else
|
||||||
t[ABSOLUTE_FILE_NAME_SOLUTIONS] = TermFirst;
|
t[ABSOLUTE_FILE_NAME_SOLUTIONS] = TermFirst;
|
||||||
if (args[ABSOLUTE_FILE_NAME_EXPAND].used)
|
if (args[ABSOLUTE_FILE_NAME_EXPAND].used)
|
||||||
@ -1849,8 +1832,7 @@ int PlGetc(int sno) {
|
|||||||
args[ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH].tvalue;
|
args[ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH].tvalue;
|
||||||
else
|
else
|
||||||
t[ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH] =
|
t[ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH] =
|
||||||
(trueGlobalPrologFlag(VERBOSE_FILE_SEARCH_FLAG) ? TermTrue
|
(trueGlobalPrologFlag(VERBOSE_FILE_SEARCH_FLAG) ? TermTrue : TermFalse);
|
||||||
: TermFalse);
|
|
||||||
tf = Yap_MkApplTerm(Yap_MkFunctor(AtomOpt, ABSOLUTE_FILE_NAME_END),
|
tf = Yap_MkApplTerm(Yap_MkFunctor(AtomOpt, ABSOLUTE_FILE_NAME_END),
|
||||||
ABSOLUTE_FILE_NAME_END, t);
|
ABSOLUTE_FILE_NAME_END, t);
|
||||||
return (Yap_unify(ARG2, tf));
|
return (Yap_unify(ARG2, tf));
|
||||||
|
17
os/iopreds.h
17
os/iopreds.h
@ -18,9 +18,9 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#define HAVE_SOCKET 1
|
#define HAVE_SOCKET 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "Yap.h"
|
|
||||||
#include "Atoms.h"
|
#include "Atoms.h"
|
||||||
|
#include "Yap.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file defines main data-structure for stream management,
|
* This file defines main data-structure for stream management,
|
||||||
@ -206,12 +206,17 @@ typedef struct stream_desc {
|
|||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
lockvar streamlock; /* protect stream access */
|
lockvar streamlock; /* protect stream access */
|
||||||
#endif
|
#endif
|
||||||
int (*stream_putc)(int, int); /** function the stream uses for writing a single octet */
|
int (*stream_putc)(
|
||||||
int (*stream_wputc)(int, int); /** function the stream uses for writing a character */
|
int, int); /** function the stream uses for writing a single octet */
|
||||||
|
int (*stream_wputc)(
|
||||||
|
int, wchar_t); /** function the stream uses for writing a character */
|
||||||
int (*stream_getc)(int); /** function the stream uses for reading an octet. */
|
int (*stream_getc)(int); /** function the stream uses for reading an octet. */
|
||||||
int (*stream_wgetc)(int); /** function the stream uses for reading a character. */
|
int (*stream_wgetc)(
|
||||||
|
int); /** function the stream uses for reading a character. */
|
||||||
|
|
||||||
int (*stream_wgetc_for_read)(int); /* function the stream uses for parser. It may be different from above if the ISO character conversion is on */
|
int (*stream_wgetc_for_read)(
|
||||||
|
int); /* function the stream uses for parser. It may be different
|
||||||
|
from above if the ISO character conversion is on */
|
||||||
encoding_t encoding; /** current encoding for stream */
|
encoding_t encoding; /** current encoding for stream */
|
||||||
} StreamDesc;
|
} StreamDesc;
|
||||||
|
|
||||||
|
96
os/mem.c
96
os/mem.c
@ -24,8 +24,8 @@ static char SccsId[] = "%W% %G%";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
|
#include "Yatom.h"
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
@ -55,6 +55,11 @@ static char SccsId[] = "%W% %G%";
|
|||||||
FILE *open_memstream(char **buf, size_t *len);
|
FILE *open_memstream(char **buf, size_t *len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
#undef HAVE_FMEMOPEN
|
||||||
|
#undef HAVE_OPEN_MEMSTREAM
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAVE_FMEMOPEN
|
#if HAVE_FMEMOPEN
|
||||||
#define MAY_READ 1
|
#define MAY_READ 1
|
||||||
#endif
|
#endif
|
||||||
@ -73,9 +78,7 @@ FILE * open_memstream (char **buf, size_t *len);
|
|||||||
static int MemGetc(int);
|
static int MemGetc(int);
|
||||||
|
|
||||||
/* read from memory */
|
/* read from memory */
|
||||||
static int
|
static int MemGetc(int sno) {
|
||||||
MemGetc(int sno)
|
|
||||||
{
|
|
||||||
register StreamDesc *s = &GLOBAL_Stream[sno];
|
register StreamDesc *s = &GLOBAL_Stream[sno];
|
||||||
Int ch;
|
Int ch;
|
||||||
int spos;
|
int spos;
|
||||||
@ -83,8 +86,7 @@ MemGetc(int sno)
|
|||||||
spos = s->u.mem_string.pos;
|
spos = s->u.mem_string.pos;
|
||||||
if (spos == s->u.mem_string.max_size) {
|
if (spos == s->u.mem_string.max_size) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ch = s->u.mem_string.buf[spos];
|
ch = s->u.mem_string.buf[spos];
|
||||||
s->u.mem_string.pos = ++spos;
|
s->u.mem_string.pos = ++spos;
|
||||||
}
|
}
|
||||||
@ -96,13 +98,10 @@ MemGetc(int sno)
|
|||||||
static int MemPutc(int, int);
|
static int MemPutc(int, int);
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
static int
|
static int MemPutc(int sno, int ch) {
|
||||||
MemPutc(int sno, int ch)
|
|
||||||
{
|
|
||||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||||
#if MAC || _MSC_VER
|
#if MAC || _MSC_VER
|
||||||
if (ch == 10)
|
if (ch == 10) {
|
||||||
{
|
|
||||||
ch = '\n';
|
ch = '\n';
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -118,7 +117,8 @@ MemPutc(int sno, int ch)
|
|||||||
(newbuf = Yap_AllocAtomSpace(new_max_size * sizeof(char))) != NULL) {
|
(newbuf = Yap_AllocAtomSpace(new_max_size * sizeof(char))) != NULL) {
|
||||||
new_src = MEM_BUF_CODE;
|
new_src = MEM_BUF_CODE;
|
||||||
#if HAVE_MEMMOVE
|
#if HAVE_MEMMOVE
|
||||||
memmove((void *)newbuf, (void *)s->u.mem_string.buf, (size_t)((s->u.mem_string.pos)*sizeof(char)));
|
memmove((void *)newbuf, (void *)s->u.mem_string.buf,
|
||||||
|
(size_t)((s->u.mem_string.pos) * sizeof(char)));
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
Int n = s->u.mem_string.pos;
|
Int n = s->u.mem_string.pos;
|
||||||
@ -131,7 +131,8 @@ MemPutc(int sno, int ch)
|
|||||||
#endif
|
#endif
|
||||||
Yap_FreeAtomSpace(s->u.mem_string.buf);
|
Yap_FreeAtomSpace(s->u.mem_string.buf);
|
||||||
#if !HAVE_SYSTEM_MALLOC
|
#if !HAVE_SYSTEM_MALLOC
|
||||||
} else if ((newbuf = (ADDR)realloc(s->u.mem_string.buf, new_max_size*sizeof(char))) != NULL) {
|
} else if ((newbuf = (ADDR)realloc(s->u.mem_string.buf,
|
||||||
|
new_max_size * sizeof(char))) != NULL) {
|
||||||
new_src = MEM_BUF_MALLOC;
|
new_src = MEM_BUF_MALLOC;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@ -141,7 +142,8 @@ MemPutc(int sno, int ch)
|
|||||||
save_machine_regs();
|
save_machine_regs();
|
||||||
longjmp(*(jmp_buf *)GLOBAL_Stream[sno].u.mem_string.error_handler, 1);
|
longjmp(*(jmp_buf *)GLOBAL_Stream[sno].u.mem_string.error_handler, 1);
|
||||||
} else {
|
} else {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "YAP could not grow heap for writing to string");
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
|
||||||
|
"YAP could not grow heap for writing to string");
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -157,10 +159,8 @@ MemPutc(int sno, int ch)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int Yap_open_buf_read_stream(const char *nbuf, size_t nchars, encoding_t *encp,
|
||||||
int
|
memBufSource src) {
|
||||||
Yap_open_buf_read_stream(const char *nbuf, size_t nchars, encoding_t *encp, memBufSource src)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
StreamDesc *st;
|
StreamDesc *st;
|
||||||
@ -170,7 +170,8 @@ MemPutc(int sno, int ch)
|
|||||||
|
|
||||||
sno = GetFreeStreamD();
|
sno = GetFreeStreamD();
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (PlIOError (RESOURCE_ERROR_MAX_STREAMS,TermNil, "new stream not available for open_mem_read_stream/1"));
|
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, TermNil,
|
||||||
|
"new stream not available for open_mem_read_stream/1"));
|
||||||
st = GLOBAL_Stream + sno;
|
st = GLOBAL_Stream + sno;
|
||||||
if (encp)
|
if (encp)
|
||||||
encoding = *encp;
|
encoding = *encp;
|
||||||
@ -184,8 +185,7 @@ MemPutc(int sno, int ch)
|
|||||||
f = NULL;
|
f = NULL;
|
||||||
flags = Input_Stream_f | InMemory_Stream_f;
|
flags = Input_Stream_f | InMemory_Stream_f;
|
||||||
#endif
|
#endif
|
||||||
Yap_initStream(sno, f, NULL, TermNil,
|
Yap_initStream(sno, f, NULL, TermNil, encoding, flags, AtomRead);
|
||||||
encoding, flags, AtomRead);
|
|
||||||
// like any file stream.
|
// like any file stream.
|
||||||
#if !MAY_READ
|
#if !MAY_READ
|
||||||
/* currently these streams are not seekable */
|
/* currently these streams are not seekable */
|
||||||
@ -248,14 +248,12 @@ open_mem_read_stream (USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
|
|||||||
return (Yap_unify(ARG2, t));
|
return (Yap_unify(ARG2, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp,
|
||||||
Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp, memBufSource sr)
|
memBufSource sr) {
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
StreamDesc *st;
|
StreamDesc *st;
|
||||||
|
|
||||||
|
|
||||||
sno = GetFreeStreamD();
|
sno = GetFreeStreamD();
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -294,20 +292,19 @@ Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp, memBufSou
|
|||||||
return sno;
|
return sno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int Yap_OpenBufWriteStream(USES_REGS1) {
|
||||||
Yap_OpenBufWriteStream( USES_REGS1 )
|
|
||||||
{
|
|
||||||
char *nbuf;
|
char *nbuf;
|
||||||
size_t sz = Yap_page_size;
|
size_t sz = Yap_page_size;
|
||||||
|
|
||||||
|
while ((nbuf = (char *)Yap_AllocAtomSpace(Yap_page_size * sizeof(char))) ==
|
||||||
while ((nbuf = (char *)Yap_AllocAtomSpace(Yap_page_size*sizeof(char))) == NULL) {
|
NULL) {
|
||||||
if (!Yap_growheap(FALSE, Yap_page_size * sizeof(char), NULL)) {
|
if (!Yap_growheap(FALSE, Yap_page_size * sizeof(char), NULL)) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Yap_open_buf_write_stream(nbuf, sz, &GLOBAL_Stream[LOCAL_c_output_stream].encoding, 0);
|
return Yap_open_buf_write_stream(
|
||||||
|
nbuf, sz, &GLOBAL_Stream[LOCAL_c_output_stream].encoding, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
@ -318,7 +315,8 @@ open_mem_write_stream (USES_REGS1) /* $open_mem_write_stream(-Stream) */
|
|||||||
|
|
||||||
sno = Yap_OpenBufWriteStream(PASS_REGS1);
|
sno = Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
if (sno == -1)
|
if (sno == -1)
|
||||||
return (PlIOError (SYSTEM_ERROR_INTERNAL,TermNil, "new stream not available for open_mem_read_stream/1"));
|
return (PlIOError(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"new stream not available for open_mem_read_stream/1"));
|
||||||
t = Yap_MkStream(sno);
|
t = Yap_MkStream(sno);
|
||||||
return (Yap_unify(ARG1, t));
|
return (Yap_unify(ARG1, t));
|
||||||
}
|
}
|
||||||
@ -331,13 +329,10 @@ open_mem_write_stream (USES_REGS1) /* $open_mem_write_stream(-Stream) */
|
|||||||
* @return temporary buffer, discarded by close and may be moved away
|
* @return temporary buffer, discarded by close and may be moved away
|
||||||
* by other writes..
|
* by other writes..
|
||||||
*/
|
*/
|
||||||
char *
|
char *Yap_MemExportStreamPtr(int sno) {
|
||||||
Yap_MemExportStreamPtr( int sno )
|
|
||||||
{
|
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
char *s;
|
char *s;
|
||||||
if (fflush(GLOBAL_Stream[sno].file) == 0)
|
if (fflush(GLOBAL_Stream[sno].file) == 0) {
|
||||||
{
|
|
||||||
s = GLOBAL_Stream[sno].nbuf;
|
s = GLOBAL_Stream[sno].nbuf;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -347,11 +342,10 @@ Yap_MemExportStreamPtr( int sno )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int peek_mem_write_stream(
|
||||||
static Int
|
USES_REGS1) { /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */
|
||||||
peek_mem_write_stream ( USES_REGS1 )
|
Int sno =
|
||||||
{ /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */
|
Yap_CheckStream(ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2");
|
||||||
Int sno = Yap_CheckStream (ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2");
|
|
||||||
Int i;
|
Int i;
|
||||||
Term tf = ARG2;
|
Term tf = ARG2;
|
||||||
CELL *HI;
|
CELL *HI;
|
||||||
@ -391,9 +385,7 @@ peek_mem_write_stream ( USES_REGS1 )
|
|||||||
return (Yap_unify(ARG3, tf));
|
return (Yap_unify(ARG3, tf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Yap_MemOps(StreamDesc *st) {
|
||||||
Yap_MemOps( StreamDesc *st )
|
|
||||||
{
|
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
st->stream_putc = FilePutc;
|
st->stream_putc = FilePutc;
|
||||||
#else
|
#else
|
||||||
@ -407,8 +399,7 @@ void
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Yap_CloseMemoryStream( int sno )
|
bool Yap_CloseMemoryStream(int sno) {
|
||||||
{
|
|
||||||
if (!(GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
if (!(GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
@ -436,15 +427,14 @@ bool Yap_CloseMemoryStream( int sno )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Yap_InitMems(void) {
|
||||||
Yap_InitMems( void )
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term cm = CurrentModule;
|
Term cm = CurrentModule;
|
||||||
CurrentModule = CHARSIO_MODULE;
|
CurrentModule = CHARSIO_MODULE;
|
||||||
Yap_InitCPred("open_mem_read_stream", 2, open_mem_read_stream, SyncPredFlag);
|
Yap_InitCPred("open_mem_read_stream", 2, open_mem_read_stream, SyncPredFlag);
|
||||||
Yap_InitCPred ("open_mem_write_stream", 1, open_mem_write_stream, SyncPredFlag);
|
Yap_InitCPred("open_mem_write_stream", 1, open_mem_write_stream,
|
||||||
Yap_InitCPred ("peek_mem_write_stream", 3, peek_mem_write_stream, SyncPredFlag);
|
SyncPredFlag);
|
||||||
|
Yap_InitCPred("peek_mem_write_stream", 3, peek_mem_write_stream,
|
||||||
|
SyncPredFlag);
|
||||||
CurrentModule = cm;
|
CurrentModule = cm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
196
os/sig.c
196
os/sig.c
@ -29,12 +29,11 @@ static void HandleMatherr(int sig, void *sipv, void *uapv);
|
|||||||
#define SIG_FREECLAUSES (SIG_PROLOG_OFFSET + 4)
|
#define SIG_FREECLAUSES (SIG_PROLOG_OFFSET + 4)
|
||||||
#define SIG_PLABORT (SIG_PROLOG_OFFSET + 5)
|
#define SIG_PLABORT (SIG_PROLOG_OFFSET + 5)
|
||||||
|
|
||||||
static struct signame
|
static struct signame {
|
||||||
{ int sig;
|
int sig;
|
||||||
const char *name;
|
const char *name;
|
||||||
int flags;
|
int flags;
|
||||||
} signames[] =
|
} signames[] = {
|
||||||
{
|
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
{SIGHUP, "hup", 0},
|
{SIGHUP, "hup", 0},
|
||||||
#endif
|
#endif
|
||||||
@ -124,15 +123,12 @@ static struct signame
|
|||||||
{SIG_THREAD_SIGNAL, "prolog:thread_signal", 0},
|
{SIG_THREAD_SIGNAL, "prolog:thread_signal", 0},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ -1, NULL, 0}
|
{-1, NULL, 0}};
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*signal_handler_t)(int, void *, void *);
|
typedef void (*signal_handler_t)(int, void *, void *);
|
||||||
|
|
||||||
#if HAVE_SIGACTION
|
#if HAVE_SIGACTION
|
||||||
static void
|
static void my_signal_info(int sig, void *handler) {
|
||||||
my_signal_info(int sig, void * handler)
|
|
||||||
{
|
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
|
|
||||||
sigact.sa_handler = handler;
|
sigact.sa_handler = handler;
|
||||||
@ -142,9 +138,7 @@ my_signal_info(int sig, void * handler)
|
|||||||
sigaction(sig, &sigact, NULL);
|
sigaction(sig, &sigact, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void my_signal(int sig, void *handler) {
|
||||||
my_signal(int sig, void * handler)
|
|
||||||
{
|
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
|
|
||||||
sigact.sa_handler = (void *)handler;
|
sigact.sa_handler = (void *)handler;
|
||||||
@ -155,36 +149,29 @@ my_signal(int sig, void * handler)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void
|
static void my_signal(int sig, void *handler) { signal(sig, handler); }
|
||||||
my_signal(int sig, void *handler)
|
|
||||||
{
|
|
||||||
signal(sig, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void my_signal_info(int sig, void *handler) {
|
||||||
my_signal_info(int sig, void *handler)
|
|
||||||
{
|
|
||||||
if (signal(sig, (void *)handler) == SIG_ERR)
|
if (signal(sig, (void *)handler) == SIG_ERR)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* SWI emulation */
|
/* SWI emulation */
|
||||||
int
|
int Yap_signal_index(const char *name) {
|
||||||
Yap_signal_index(const char *name)
|
struct signame *sn = signames;
|
||||||
{ struct signame *sn = signames;
|
|
||||||
char tmp[12];
|
char tmp[12];
|
||||||
|
|
||||||
if ( strncmp(name, "SIG", 3) == 0 && strlen(name) < 12 )
|
if (strncmp(name, "SIG", 3) == 0 && strlen(name) < 12) {
|
||||||
{ char *p = (char *)name+3, *q = tmp;
|
char *p = (char *)name + 3, *q = tmp;
|
||||||
while ((*q++ = tolower(*p++))) {};
|
while ((*q++ = tolower(*p++))) {
|
||||||
|
};
|
||||||
name = tmp;
|
name = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ; sn->name; sn++ )
|
for (; sn->name; sn++) {
|
||||||
{ if ( !strcmp(sn->name, name) )
|
if (!strcmp(sn->name, name))
|
||||||
return sn->sig;
|
return sn->sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,9 +186,7 @@ Yap_signal_index(const char *name)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_SIGSEGV
|
#if HAVE_SIGSEGV
|
||||||
static void
|
static void SearchForTrailFault(void *ptr, int sure) {
|
||||||
SearchForTrailFault(void *ptr, int sure)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* If the TRAIL is very close to the top of mmaped allocked space,
|
/* If the TRAIL is very close to the top of mmaped allocked space,
|
||||||
then we can try increasing the TR space and restarting the
|
then we can try increasing the TR space and restarting the
|
||||||
@ -212,7 +197,8 @@ SearchForTrailFault(void *ptr, int sure)
|
|||||||
if ((ptr > (void *)LOCAL_TrailTop - 1024 &&
|
if ((ptr > (void *)LOCAL_TrailTop - 1024 &&
|
||||||
TR < (tr_fr_ptr)LOCAL_TrailTop + (64 * 1024))) {
|
TR < (tr_fr_ptr)LOCAL_TrailTop + (64 * 1024))) {
|
||||||
if (!Yap_growtrail(64 * 1024, TRUE)) {
|
if (!Yap_growtrail(64 * 1024, TRUE)) {
|
||||||
Yap_Error(RESOURCE_ERROR_TRAIL, TermNil, "YAP failed to reserve %ld bytes in growtrail", K64);
|
Yap_Error(RESOURCE_ERROR_TRAIL, TermNil,
|
||||||
|
"YAP failed to reserve %ld bytes in growtrail", K64);
|
||||||
}
|
}
|
||||||
/* just in case, make sure the OS keeps the signal handler. */
|
/* just in case, make sure the OS keeps the signal handler. */
|
||||||
/* my_signal_info(SIGSEGV, HandleSIGSEGV); */
|
/* my_signal_info(SIGSEGV, HandleSIGSEGV); */
|
||||||
@ -226,24 +212,21 @@ SearchForTrailFault(void *ptr, int sure)
|
|||||||
"likely bug in YAP, segmentation violation");
|
"likely bug in YAP, segmentation violation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This routine believes there is a continuous space starting from the
|
/* This routine believes there is a continuous space starting from the
|
||||||
HeapBase and ending on TrailTop */
|
HeapBase and ending on TrailTop */
|
||||||
static void
|
static void HandleSIGSEGV(int sig, void *sipv, void *uap) {
|
||||||
HandleSIGSEGV(int sig, void *sipv, void *uap)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
void *ptr = TR;
|
void *ptr = TR;
|
||||||
int sure = FALSE;
|
int sure = FALSE;
|
||||||
if (LOCAL_PrologMode & ExtendStackMode) {
|
if (LOCAL_PrologMode & ExtendStackMode) {
|
||||||
Yap_Error(SYSTEM_ERROR_FATAL, TermNil, "OS memory allocation crashed at address %p, bailing out\n",LOCAL_TrailTop);
|
Yap_Error(SYSTEM_ERROR_FATAL, TermNil,
|
||||||
|
"OS memory allocation crashed at address %p, bailing out\n",
|
||||||
|
LOCAL_TrailTop);
|
||||||
}
|
}
|
||||||
#if (defined(__svr4__) || defined(__SVR4))
|
#if (defined(__svr4__) || defined(__SVR4))
|
||||||
siginfo_t *sip = sipv;
|
siginfo_t *sip = sipv;
|
||||||
if (
|
if (sip->si_code != SI_NOINFO && sip->si_code == SEGV_MAPERR) {
|
||||||
sip->si_code != SI_NOINFO &&
|
|
||||||
sip->si_code == SEGV_MAPERR) {
|
|
||||||
ptr = sip->si_addr;
|
ptr = sip->si_addr;
|
||||||
sure = TRUE;
|
sure = TRUE;
|
||||||
}
|
}
|
||||||
@ -262,20 +245,21 @@ HandleSIGSEGV(int sig, void *sipv, void *uap)
|
|||||||
#include <fpu_control.h>
|
#include <fpu_control.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* by default Linux with glibc is IEEE compliant anyway..., but we will pretend it is not. */
|
/* by default Linux with glibc is IEEE compliant anyway..., but we will pretend
|
||||||
static bool
|
* it is not. */
|
||||||
set_fpu_exceptions(Term flag)
|
static bool set_fpu_exceptions(Term flag) {
|
||||||
{
|
|
||||||
if (flag == TermTrue) {
|
if (flag == TermTrue) {
|
||||||
#if HAVE_FESETEXCEPTFLAG
|
#if HAVE_FESETEXCEPTFLAG
|
||||||
fexcept_t excepts;
|
fexcept_t excepts;
|
||||||
return fesetexceptflag(&excepts, FE_DIVBYZERO| FE_UNDERFLOW|FE_OVERFLOW) == 0;
|
return fesetexceptflag(&excepts,
|
||||||
|
FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW) == 0;
|
||||||
#elif HAVE_FEENABLEEXCEPT
|
#elif HAVE_FEENABLEEXCEPT
|
||||||
/* I shall ignore de-normalization and precision errors */
|
/* I shall ignore de-normalization and precision errors */
|
||||||
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
|
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
|
||||||
#elif _WIN32
|
#elif _WIN32
|
||||||
// Enable zero-divide, overflow and underflow exception
|
// Enable zero-divide, overflow and underflow exception
|
||||||
_controlfp_s(0, ~(_EM_ZERODIVIDE|_EM_UNDERFLOW|_EM_OVERFLOW), _MCW_EM); // Line B
|
_controlfp_s(0, ~(_EM_ZERODIVIDE | _EM_UNDERFLOW | _EM_OVERFLOW),
|
||||||
|
_MCW_EM); // Line B
|
||||||
#elif defined(__hpux)
|
#elif defined(__hpux)
|
||||||
#if HAVE_FESETTRAPENABLE
|
#if HAVE_FESETTRAPENABLE
|
||||||
/* From HP-UX 11.0 onwards: */
|
/* From HP-UX 11.0 onwards: */
|
||||||
@ -295,7 +279,8 @@ set_fpu_exceptions(Term flag)
|
|||||||
#endif /* __hpux */
|
#endif /* __hpux */
|
||||||
#if HAVE_FPU_CONTROL_H && i386 && defined(__GNUC__)
|
#if HAVE_FPU_CONTROL_H && i386 && defined(__GNUC__)
|
||||||
/* I shall ignore denormalization and precision errors */
|
/* I shall ignore denormalization and precision errors */
|
||||||
int v = _FPU_IEEE & ~(_FPU_MASK_IM|_FPU_MASK_ZM|_FPU_MASK_OM|_FPU_MASK_UM);
|
int v = _FPU_IEEE &
|
||||||
|
~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM);
|
||||||
_FPU_SETCW(v);
|
_FPU_SETCW(v);
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_FETESTEXCEPT
|
#if HAVE_FETESTEXCEPT
|
||||||
@ -314,7 +299,8 @@ set_fpu_exceptions(Term flag)
|
|||||||
feenableexcept(0);
|
feenableexcept(0);
|
||||||
#elif _WIN32
|
#elif _WIN32
|
||||||
// Enable zero-divide, overflow and underflow exception
|
// Enable zero-divide, overflow and underflow exception
|
||||||
_controlfp_s(0, (_EM_ZERODIVIDE|_EM_UNDERFLOW|_EM_OVERFLOW), _MCW_EM); // Line B
|
_controlfp_s(0, (_EM_ZERODIVIDE | _EM_UNDERFLOW | _EM_OVERFLOW),
|
||||||
|
_MCW_EM); // Line B
|
||||||
#elif defined(__hpux)
|
#elif defined(__hpux)
|
||||||
#if HAVE_FESETTRAPENABLE
|
#if HAVE_FESETTRAPENABLE
|
||||||
fesettrapenable(FE_ALL_EXCEPT);
|
fesettrapenable(FE_ALL_EXCEPT);
|
||||||
@ -334,16 +320,9 @@ set_fpu_exceptions(Term flag)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool Yap_set_fpu_exceptions(Term flag) { return set_fpu_exceptions(flag); }
|
||||||
Yap_set_fpu_exceptions(Term flag)
|
|
||||||
{
|
|
||||||
return set_fpu_exceptions(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
yap_error_number Yap_MathException__(USES_REGS1) {
|
||||||
yap_error_number
|
|
||||||
Yap_MathException__( USES_REGS1 )
|
|
||||||
{
|
|
||||||
#if HAVE_FETESTEXCEPT
|
#if HAVE_FETESTEXCEPT
|
||||||
int raised;
|
int raised;
|
||||||
|
|
||||||
@ -415,9 +394,7 @@ Yap_MathException__( USES_REGS1 )
|
|||||||
return LOCAL_matherror;
|
return LOCAL_matherror;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int fpe_error(USES_REGS1) {
|
||||||
p_fpe_error( USES_REGS1 )
|
|
||||||
{
|
|
||||||
Yap_Error(LOCAL_matherror, LOCAL_mathtt, LOCAL_mathstring);
|
Yap_Error(LOCAL_matherror, LOCAL_mathtt, LOCAL_mathstring);
|
||||||
LOCAL_matherror = YAP_NO_ERROR;
|
LOCAL_matherror = YAP_NO_ERROR;
|
||||||
LOCAL_mathtt = TermNil;
|
LOCAL_mathtt = TermNil;
|
||||||
@ -425,9 +402,7 @@ p_fpe_error( USES_REGS1 )
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void HandleMatherr(int sig, void *sipv, void *uapv) {
|
||||||
HandleMatherr(int sig, void *sipv, void *uapv)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_matherror = Yap_MathException();
|
LOCAL_matherror = Yap_MathException();
|
||||||
/* reset the registers so that we don't have trash in abstract machine */
|
/* reset the registers so that we don't have trash in abstract machine */
|
||||||
@ -436,17 +411,12 @@ HandleMatherr(int sig, void *sipv, void *uapv)
|
|||||||
|
|
||||||
#endif /* SIGFPE */
|
#endif /* SIGFPE */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
|
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
|
||||||
static RETSIGTYPE
|
static RETSIGTYPE ReceiveSignal(int s, void *x, void *y) {
|
||||||
ReceiveSignal (int s, void *x, void *y)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_PrologMode |= InterruptMode;
|
LOCAL_PrologMode |= InterruptMode;
|
||||||
my_signal(s, ReceiveSignal);
|
my_signal(s, ReceiveSignal);
|
||||||
switch (s)
|
switch (s) {
|
||||||
{
|
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
// always direct SIGINT to console
|
// always direct SIGINT to console
|
||||||
Yap_external_signal(0, YAP_INT_SIGNAL);
|
Yap_external_signal(0, YAP_INT_SIGNAL);
|
||||||
@ -505,8 +475,7 @@ ReceiveSignal (int s, void *x, void *y)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (_MSC_VER || defined(__MINGW32__))
|
#if (_MSC_VER || defined(__MINGW32__))
|
||||||
static BOOL WINAPI
|
static BOOL WINAPI MSCHandleSignal(DWORD dwCtrlType) {
|
||||||
MSCHandleSignal(DWORD dwCtrlType) {
|
|
||||||
if (
|
if (
|
||||||
#if THREADS
|
#if THREADS
|
||||||
REMOTE_InterruptsDisabled(0)
|
REMOTE_InterruptsDisabled(0)
|
||||||
@ -533,11 +502,8 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* SIGINT can cause problems, if caught before full initialization */
|
/* SIGINT can cause problems, if caught before full initialization */
|
||||||
void
|
void Yap_InitOSSignals(int wid) {
|
||||||
Yap_InitOSSignals (int wid)
|
|
||||||
{
|
|
||||||
if (GLOBAL_PrologShouldHandleInterrupts) {
|
if (GLOBAL_PrologShouldHandleInterrupts) {
|
||||||
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
|
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) && !defined(LIGHT)
|
||||||
my_signal(SIGQUIT, ReceiveSignal);
|
my_signal(SIGQUIT, ReceiveSignal);
|
||||||
@ -571,13 +537,10 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
|
|
||||||
#endif /* HAVE_SIGNAL */
|
#endif /* HAVE_SIGNAL */
|
||||||
|
|
||||||
|
|
||||||
/* wrapper for alarm system call */
|
/* wrapper for alarm system call */
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
|
|
||||||
static DWORD WINAPI
|
static DWORD WINAPI DoTimerThread(LPVOID targ) {
|
||||||
DoTimerThread(LPVOID targ)
|
|
||||||
{
|
|
||||||
Int *time = (Int *)targ;
|
Int *time = (Int *)targ;
|
||||||
HANDLE htimer;
|
HANDLE htimer;
|
||||||
LARGE_INTEGER liDueTime;
|
LARGE_INTEGER liDueTime;
|
||||||
@ -604,9 +567,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Int
|
static Int enable_interrupts(USES_REGS1) {
|
||||||
enable_interrupts( USES_REGS1 )
|
|
||||||
{
|
|
||||||
LOCAL_InterruptsDisabled--;
|
LOCAL_InterruptsDisabled--;
|
||||||
if (LOCAL_Signals && !LOCAL_InterruptsDisabled) {
|
if (LOCAL_Signals && !LOCAL_InterruptsDisabled) {
|
||||||
CreepFlag = Unsigned(LCL0);
|
CreepFlag = Unsigned(LCL0);
|
||||||
@ -616,17 +577,13 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int disable_interrupts(USES_REGS1) {
|
||||||
disable_interrupts( USES_REGS1 )
|
|
||||||
{
|
|
||||||
LOCAL_InterruptsDisabled++;
|
LOCAL_InterruptsDisabled++;
|
||||||
CalculateStackGap(PASS_REGS1);
|
CalculateStackGap(PASS_REGS1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int alarm4(USES_REGS1) {
|
||||||
alarm4( USES_REGS1 )
|
|
||||||
{
|
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
Int i1, i2;
|
Int i1, i2;
|
||||||
@ -667,8 +624,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
DWORD dwThreadId;
|
DWORD dwThreadId;
|
||||||
HANDLE hThread;
|
HANDLE hThread;
|
||||||
|
|
||||||
hThread = CreateThread(
|
hThread = CreateThread(NULL, /* no security attributes */
|
||||||
NULL, /* no security attributes */
|
|
||||||
0, /* use default stack size */
|
0, /* use default stack size */
|
||||||
DoTimerThread, /* thread function */
|
DoTimerThread, /* thread function */
|
||||||
(LPVOID)time, /* argument to thread function */
|
(LPVOID)time, /* argument to thread function */
|
||||||
@ -693,7 +649,8 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
new.it_value.tv_usec = i2;
|
new.it_value.tv_usec = i2;
|
||||||
if (setitimer(ITIMER_REAL, &new, &old) < 0) {
|
if (setitimer(ITIMER_REAL, &new, &old) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer %d", errno);
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer %d", errno);
|
||||||
#endif
|
#endif
|
||||||
@ -721,9 +678,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int virtual_alarm(USES_REGS1) {
|
||||||
virtual_alarm( USES_REGS1 )
|
|
||||||
{
|
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
@ -754,8 +709,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
DWORD dwThreadId;
|
DWORD dwThreadId;
|
||||||
HANDLE hThread;
|
HANDLE hThread;
|
||||||
|
|
||||||
hThread = CreateThread(
|
hThread = CreateThread(NULL, /* no security attributes */
|
||||||
NULL, /* no security attributes */
|
|
||||||
0, /* use default stack size */
|
0, /* use default stack size */
|
||||||
DoTimerThread, /* thread function */
|
DoTimerThread, /* thread function */
|
||||||
(LPVOID)time, /* argument to thread function */
|
(LPVOID)time, /* argument to thread function */
|
||||||
@ -780,7 +734,8 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
new.it_value.tv_usec = IntegerOfTerm(t2);
|
new.it_value.tv_usec = IntegerOfTerm(t2);
|
||||||
if (setitimer(ITIMER_VIRTUAL, &new, &old) < 0) {
|
if (setitimer(ITIMER_VIRTUAL, &new, &old) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer %d", errno);
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1, "setitimer %d", errno);
|
||||||
#endif
|
#endif
|
||||||
@ -799,15 +754,13 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef VAX
|
#ifdef VAX
|
||||||
|
|
||||||
/* avoid longjmp botch */
|
/* avoid longjmp botch */
|
||||||
|
|
||||||
int vax_absmi_fp;
|
int vax_absmi_fp;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
int eh;
|
int eh;
|
||||||
int flgs;
|
int flgs;
|
||||||
int ap;
|
int ap;
|
||||||
@ -825,16 +778,12 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
|
|
||||||
* VaxFramePtr;
|
* VaxFramePtr;
|
||||||
|
|
||||||
|
VaxFixFrame(dummy) {
|
||||||
VaxFixFrame (dummy)
|
|
||||||
{
|
|
||||||
int maxframes = 100;
|
int maxframes = 100;
|
||||||
VaxFramePtr fp = (VaxFramePtr)(((int *)&dummy) - 6);
|
VaxFramePtr fp = (VaxFramePtr)(((int *)&dummy) - 6);
|
||||||
while (--maxframes)
|
while (--maxframes) {
|
||||||
{
|
|
||||||
fp = (VaxFramePtr)fp->fp;
|
fp = (VaxFramePtr)fp->fp;
|
||||||
if (fp->flgs == 0)
|
if (fp->flgs == 0) {
|
||||||
{
|
|
||||||
if (fp->oldfp >= ®S[6] && fp->oldfp < ®S[REG_SIZE])
|
if (fp->oldfp >= ®S[6] && fp->oldfp < ®S[REG_SIZE])
|
||||||
fp->oldfp = vax_absmi_fp;
|
fp->oldfp = vax_absmi_fp;
|
||||||
return;
|
return;
|
||||||
@ -844,17 +793,14 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
int WINAPI win_yap(HANDLE, DWORD, LPVOID);
|
int WINAPI win_yap(HANDLE, DWORD, LPVOID);
|
||||||
|
|
||||||
int WINAPI win_yap(HANDLE hinst, DWORD reason, LPVOID reserved)
|
int WINAPI win_yap(HANDLE hinst, DWORD reason, LPVOID reserved) {
|
||||||
{
|
switch (reason) {
|
||||||
switch (reason)
|
|
||||||
{
|
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
break;
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
@ -872,13 +818,12 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
#ifdef sparc
|
#ifdef sparc
|
||||||
void rw_lock_voodoo(void);
|
void rw_lock_voodoo(void);
|
||||||
|
|
||||||
void
|
void rw_lock_voodoo(void) {
|
||||||
rw_lock_voodoo(void) {
|
|
||||||
/* code taken from the Linux kernel, it handles shifting between locks */
|
/* code taken from the Linux kernel, it handles shifting between locks */
|
||||||
/* Read/writer locks, as usual this is overly clever to make it as fast as possible. */
|
/* Read/writer locks, as usual this is overly clever to make it as fast as
|
||||||
|
* possible. */
|
||||||
/* caches... */
|
/* caches... */
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__("___rw_read_enter_spin_on_wlock:\n"
|
||||||
"___rw_read_enter_spin_on_wlock:\n"
|
|
||||||
" orcc %g2, 0x0, %g0\n"
|
" orcc %g2, 0x0, %g0\n"
|
||||||
" be,a ___rw_read_enter\n"
|
" be,a ___rw_read_enter\n"
|
||||||
" ldstub [%g1 + 3], %g2\n"
|
" ldstub [%g1 + 3], %g2\n"
|
||||||
@ -926,21 +871,17 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
" bne,a ___rw_write_enter_spin_on_wlock\n"
|
" bne,a ___rw_write_enter_spin_on_wlock\n"
|
||||||
" stb %g0, [%g1 + 3]\n"
|
" stb %g0, [%g1 + 3]\n"
|
||||||
" retl\n"
|
" retl\n"
|
||||||
" mov %g4, %o7\n"
|
" mov %g4, %o7\n");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
#endif /* sparc */
|
#endif /* sparc */
|
||||||
|
|
||||||
|
|
||||||
#endif /* YAPOR || THREADS */
|
#endif /* YAPOR || THREADS */
|
||||||
|
|
||||||
void
|
void Yap_InitSignalPreds(void) {
|
||||||
Yap_InitSignalPreds(void)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term cm = CurrentModule;
|
Term cm = CurrentModule;
|
||||||
|
|
||||||
Yap_InitCPred ("$fpe_error", 0, p_fpe_error, 0);
|
Yap_InitCPred("$fpe_error", 0, fpe_error, 0);
|
||||||
Yap_InitCPred("$alarm", 4, alarm4, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("$alarm", 4, alarm4, SafePredFlag | SyncPredFlag);
|
||||||
CurrentModule = HACKS_MODULE;
|
CurrentModule = HACKS_MODULE;
|
||||||
Yap_InitCPred("virtual_alarm", 4, virtual_alarm, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("virtual_alarm", 4, virtual_alarm, SafePredFlag | SyncPredFlag);
|
||||||
@ -948,6 +889,3 @@ MSCHandleSignal(DWORD dwCtrlType) {
|
|||||||
Yap_InitCPred("disable_interrupts", 0, disable_interrupts, SafePredFlag);
|
Yap_InitCPred("disable_interrupts", 0, disable_interrupts, SafePredFlag);
|
||||||
CurrentModule = cm;
|
CurrentModule = cm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -635,6 +635,7 @@ static Term
|
|||||||
do_glob(const char *spec, bool glob_vs_wordexp) {
|
do_glob(const char *spec, bool glob_vs_wordexp) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
char u[YAP_FILENAME_MAX + 1];
|
char u[YAP_FILENAME_MAX + 1];
|
||||||
|
char *espec = u;
|
||||||
if (spec == NULL) {
|
if (spec == NULL) {
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
@ -642,7 +643,6 @@ static Term
|
|||||||
{
|
{
|
||||||
WIN32_FIND_DATA find;
|
WIN32_FIND_DATA find;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
const char *espec;
|
|
||||||
CELL *dest;
|
CELL *dest;
|
||||||
Term tf;
|
Term tf;
|
||||||
|
|
||||||
@ -673,7 +673,6 @@ static Term
|
|||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
#elif HAVE_WORDEXP || HAVE_GLOB
|
#elif HAVE_WORDEXP || HAVE_GLOB
|
||||||
char *espec = u;
|
|
||||||
strncpy(espec, spec, sizeof(u));
|
strncpy(espec, spec, sizeof(u));
|
||||||
/* Expand the string for the program to run. */
|
/* Expand the string for the program to run. */
|
||||||
size_t pathcount;
|
size_t pathcount;
|
||||||
|
273
os/ypsocks.c
273
os/ypsocks.c
@ -15,7 +15,6 @@
|
|||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "sysbits.h"
|
#include "sysbits.h"
|
||||||
|
|
||||||
#if HAVE_SOCKET
|
#if HAVE_SOCKET
|
||||||
@ -176,21 +175,19 @@
|
|||||||
#define invalid_socket_fd(fd) (fd) < 0
|
#define invalid_socket_fd(fd) (fd) < 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void Yap_init_socks(char *host, long interface_port) {
|
||||||
Yap_init_socks(char *host, long interface_port)
|
|
||||||
{
|
|
||||||
int s;
|
int s;
|
||||||
int r;
|
int r;
|
||||||
struct sockaddr_in soadr;
|
struct sockaddr_in soadr;
|
||||||
struct in_addr adr;
|
struct in_addr adr;
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_SOCKET
|
#if HAVE_SOCKET
|
||||||
he = gethostbyname(host);
|
he = gethostbyname(host);
|
||||||
if (he == NULL) {
|
if (he == NULL) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "can not get address for host %s: %s", host, strerror(h_errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"can not get address for host %s: %s", host, strerror(h_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "can not get address for host");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "can not get address for host");
|
||||||
#endif
|
#endif
|
||||||
@ -202,8 +199,7 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
soadr.sin_port = htons((short)interface_port);
|
soadr.sin_port = htons((short)interface_port);
|
||||||
|
|
||||||
if (he != NULL) {
|
if (he != NULL) {
|
||||||
memcpy((char *) &adr,
|
memcpy((char *)&adr, (char *)he->h_addr_list[0], (size_t)he->h_length);
|
||||||
(char *) he->h_addr_list[0], (size_t) he->h_length);
|
|
||||||
} else {
|
} else {
|
||||||
adr.s_addr = inet_addr(host);
|
adr.s_addr = inet_addr(host);
|
||||||
}
|
}
|
||||||
@ -212,7 +208,8 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not create socket: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not create socket: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not create socket");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not create socket");
|
||||||
#endif
|
#endif
|
||||||
@ -223,11 +220,11 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
struct linger ling; /* disables socket lingering. */
|
struct linger ling; /* disables socket lingering. */
|
||||||
ling.l_onoff = 1;
|
ling.l_onoff = 1;
|
||||||
ling.l_linger = 0;
|
ling.l_linger = 0;
|
||||||
if (setsockopt(s, SOL_SOCKET, SO_LINGER, (void *) &ling,
|
if (setsockopt(s, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling)) < 0) {
|
||||||
sizeof(ling)) < 0) {
|
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (setsockopt_linger: %s)", strerror(socket_errno));
|
"socket_connect/3 (setsockopt_linger: %s)",
|
||||||
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (setsockopt_linger)");
|
"socket_connect/3 (setsockopt_linger)");
|
||||||
@ -239,9 +236,12 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
r = connect(s, (struct sockaddr *)&soadr, sizeof(soadr));
|
r = connect(s, (struct sockaddr *)&soadr, sizeof(soadr));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "connect failed, could not connect to interface: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"connect failed, could not connect to interface: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "connect failed, could not connect to interface");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"connect failed, could not connect to interface");
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -249,7 +249,8 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
#if HAVE_DUP2 && !defined(__MINGW32__)
|
#if HAVE_DUP2 && !defined(__MINGW32__)
|
||||||
if (dup2(s, 0) < 0) {
|
if (dup2(s, 0) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdin: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdin: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdin");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdin");
|
||||||
#endif
|
#endif
|
||||||
@ -257,7 +258,8 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
}
|
}
|
||||||
if (dup2(s, 1) < 0) {
|
if (dup2(s, 1) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdout: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdout: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdout");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stdout");
|
||||||
#endif
|
#endif
|
||||||
@ -265,7 +267,8 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
}
|
}
|
||||||
if (dup2(s, 2) < 0) {
|
if (dup2(s, 2) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stderr: %s", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stderr: %s",
|
||||||
|
strerror(errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stderr");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "could not dup2 stderr");
|
||||||
#endif
|
#endif
|
||||||
@ -311,13 +314,12 @@ Yap_init_socks(char *host, long interface_port)
|
|||||||
close(s);
|
close(s);
|
||||||
#endif
|
#endif
|
||||||
#else /* HAVE_SOCKET */
|
#else /* HAVE_SOCKET */
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "sockets not installed", strerror(errno));
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "sockets not installed",
|
||||||
|
strerror(errno));
|
||||||
#endif /* HAVE_SOCKET */
|
#endif /* HAVE_SOCKET */
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket(USES_REGS1) {
|
||||||
p_socket(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
Term t3 = Deref(ARG3);
|
Term t3 = Deref(ARG3);
|
||||||
@ -425,7 +427,8 @@ p_socket(USES_REGS1)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stype = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
stype = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
||||||
if (stype[0] != 'S' || stype[1] != 'O' || stype[2] != 'C' || stype[3] != 'K' || stype[4] != '_')
|
if (stype[0] != 'S' || stype[1] != 'O' || stype[2] != 'C' ||
|
||||||
|
stype[3] != 'K' || stype[4] != '_')
|
||||||
return (FALSE); /* Error */
|
return (FALSE); /* Error */
|
||||||
stype += 5;
|
stype += 5;
|
||||||
if (strcmp(stype, "STREAM") == 0)
|
if (strcmp(stype, "STREAM") == 0)
|
||||||
@ -448,11 +451,10 @@ p_socket(USES_REGS1)
|
|||||||
fd = socket(domain, type, protocol);
|
fd = socket(domain, type, protocol);
|
||||||
if (invalid_socket_fd(fd)) {
|
if (invalid_socket_fd(fd)) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket/4 (socket: %s)",
|
||||||
"socket/4 (socket: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket/4 (socket)");
|
||||||
"socket/4 (socket)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -469,67 +471,60 @@ p_socket(USES_REGS1)
|
|||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if (out == TermNil) return(FALSE);
|
if (out == TermNil)
|
||||||
|
return (FALSE);
|
||||||
return (Yap_unify(out, ARG4));
|
return (Yap_unify(out, ARG4));
|
||||||
}
|
}
|
||||||
|
|
||||||
Int
|
Int Yap_CloseSocket(int fd, socket_info status, socket_domain domain) {
|
||||||
Yap_CloseSocket(int fd, socket_info status, socket_domain domain)
|
|
||||||
{
|
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
/* prevent further writing
|
/* prevent further writing
|
||||||
to the socket */
|
to the socket */
|
||||||
if (status == server_session_socket ||
|
if (status == server_session_socket || status == client_socket) {
|
||||||
status == client_socket) {
|
|
||||||
char bfr;
|
char bfr;
|
||||||
|
|
||||||
if (shutdown(fd, 1) != 0) {
|
if (shutdown(fd, 1) != 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (close)");
|
||||||
"socket_close/1 (close)");
|
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
/* read all pending characters
|
/* read all pending characters
|
||||||
from the socket */
|
from the socket */
|
||||||
while( recv( fd, &bfr, 1, 0 ) > 0 );
|
while (recv(fd, &bfr, 1, 0) > 0)
|
||||||
|
;
|
||||||
/* prevent further reading
|
/* prevent further reading
|
||||||
from the socket */
|
from the socket */
|
||||||
if (shutdown(fd, 0) < 0) {
|
if (shutdown(fd, 0) < 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (close)");
|
||||||
"socket_close/1 (close)");
|
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close the socket */
|
/* close the socket */
|
||||||
if (closesocket(fd) != 0) {
|
if (closesocket(fd) != 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (close: %s)",
|
||||||
"socket_close/1 (close: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (close)");
|
||||||
"socket_close/1 (close)");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (status == server_session_socket ||
|
if (status == server_session_socket || status == client_socket) {
|
||||||
status == client_socket) {
|
|
||||||
if (shutdown(fd, 2) < 0) {
|
if (shutdown(fd, 2) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (shutdown: %s)",
|
||||||
"socket_close/1 (shutdown: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (shutdown)");
|
||||||
"socket_close/1 (shutdown)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (close(fd) != 0) {
|
if (close(fd) != 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (close: %s)",
|
||||||
"socket_close/1 (close: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_close/1 (close)");
|
||||||
"socket_close/1 (close)");
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@ -537,9 +532,7 @@ Yap_CloseSocket(int fd, socket_info status, socket_domain domain)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_close(USES_REGS1) {
|
||||||
p_socket_close(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
int sno;
|
int sno;
|
||||||
|
|
||||||
@ -550,9 +543,7 @@ p_socket_close(USES_REGS1)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_bind(USES_REGS1) {
|
||||||
p_socket_bind(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
int sno;
|
int sno;
|
||||||
@ -601,16 +592,13 @@ p_socket_bind(USES_REGS1)
|
|||||||
}
|
}
|
||||||
sock.sun_family = AF_UNIX;
|
sock.sun_family = AF_UNIX;
|
||||||
strcpy(sock.sun_path, s);
|
strcpy(sock.sun_path, s);
|
||||||
if (bind(fd,
|
if (bind(fd, (struct sockaddr *)(&sock),
|
||||||
(struct sockaddr *)(&sock),
|
((size_t)(((struct sockaddr_un *)0)->sun_path) + len)) < 0) {
|
||||||
((size_t) (((struct sockaddr_un *) 0)->sun_path) + len))
|
|
||||||
< 0) {
|
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_bind/2 (bind: %s)",
|
||||||
"socket_bind/2 (bind: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_bind/2 (bind)");
|
||||||
"socket_bind/2 (bind)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -655,11 +643,10 @@ p_socket_bind(USES_REGS1)
|
|||||||
saddr.sin_family = AF_INET;
|
saddr.sin_family = AF_INET;
|
||||||
if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
|
if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_bind/2 (bind: %s)",
|
||||||
"socket_bind/2 (bind: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_bind/2 (bind)");
|
||||||
"socket_bind/2 (bind)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -669,7 +656,7 @@ p_socket_bind(USES_REGS1)
|
|||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
int namelen;
|
int namelen;
|
||||||
#else
|
#else
|
||||||
unsigned int namelen;
|
socklen_t namelen;
|
||||||
#endif
|
#endif
|
||||||
Term t;
|
Term t;
|
||||||
if (getsockname(fd, (struct sockaddr *)&saddr, &namelen) < 0) {
|
if (getsockname(fd, (struct sockaddr *)&saddr, &namelen) < 0) {
|
||||||
@ -691,9 +678,7 @@ p_socket_bind(USES_REGS1)
|
|||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_connect(USES_REGS1) {
|
||||||
p_socket_connect(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
Functor fun;
|
Functor fun;
|
||||||
@ -744,16 +729,14 @@ p_socket_connect(USES_REGS1)
|
|||||||
}
|
}
|
||||||
sock.sun_family = AF_UNIX;
|
sock.sun_family = AF_UNIX;
|
||||||
strcpy(sock.sun_path, s);
|
strcpy(sock.sun_path, s);
|
||||||
if ((flag = connect(fd,
|
if ((flag = connect(
|
||||||
(struct sockaddr *)(&sock),
|
fd, (struct sockaddr *)(&sock),
|
||||||
((size_t) (((struct sockaddr_un *) 0)->sun_path) + len)))
|
((size_t)(((struct sockaddr_un *)0)->sun_path) + len))) < 0) {
|
||||||
< 0) {
|
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (connect: %s)", strerror(socket_errno));
|
"socket_connect/3 (connect: %s)", strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_connect/3 (connect)");
|
||||||
"socket_connect/3 (connect)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -780,7 +763,8 @@ p_socket_connect(USES_REGS1)
|
|||||||
if ((he = gethostbyname(shost)) == NULL) {
|
if ((he = gethostbyname(shost)) == NULL) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (gethostbyname: %s)", strerror(socket_errno));
|
"socket_connect/3 (gethostbyname: %s)",
|
||||||
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (gethostbyname)");
|
"socket_connect/3 (gethostbyname)");
|
||||||
@ -803,14 +787,16 @@ p_socket_connect(USES_REGS1)
|
|||||||
#if ENABLE_SO_LINGER
|
#if ENABLE_SO_LINGER
|
||||||
{
|
{
|
||||||
struct linger ling; /* For making sockets linger. */
|
struct linger ling; /* For making sockets linger. */
|
||||||
/* disabled: I see why no reason why we should throw things away by default!! */
|
/* disabled: I see why no reason why we should throw things away by
|
||||||
|
* default!! */
|
||||||
ling.l_onoff = 1;
|
ling.l_onoff = 1;
|
||||||
ling.l_linger = 0;
|
ling.l_linger = 0;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (void *) &ling,
|
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling)) <
|
||||||
sizeof(ling)) < 0) {
|
0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (setsockopt_linger: %s)", strerror(socket_errno));
|
"socket_connect/3 (setsockopt_linger: %s)",
|
||||||
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (setsockopt_linger)");
|
"socket_connect/3 (setsockopt_linger)");
|
||||||
@ -826,7 +812,8 @@ p_socket_connect(USES_REGS1)
|
|||||||
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (void *)&one, sizeof(one))) {
|
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (void *)&one, sizeof(one))) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (setsockopt_broadcast: %s)", strerror(socket_errno));
|
"socket_connect/3 (setsockopt_broadcast: %s)",
|
||||||
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (setsockopt_broadcast)");
|
"socket_connect/3 (setsockopt_broadcast)");
|
||||||
@ -841,8 +828,7 @@ p_socket_connect(USES_REGS1)
|
|||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_connect/3 (connect: %s)", strerror(socket_errno));
|
"socket_connect/3 (connect: %s)", strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_connect/3 (connect)");
|
||||||
"socket_connect/3 (connect)");
|
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -853,9 +839,7 @@ p_socket_connect(USES_REGS1)
|
|||||||
return (Yap_unify(out, ARG3));
|
return (Yap_unify(out, ARG3));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_listen(USES_REGS1) {
|
||||||
p_socket_listen(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
int sno;
|
int sno;
|
||||||
@ -887,19 +871,16 @@ p_socket_listen(USES_REGS1)
|
|||||||
}
|
}
|
||||||
if (listen(fd, j) < 0) {
|
if (listen(fd, j) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_listen/2 (listen: %s)",
|
||||||
"socket_listen/2 (listen: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_listen/2 (listen)");
|
||||||
"socket_listen/2 (listen)");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_accept(USES_REGS1) {
|
||||||
p_socket_accept(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
int sno;
|
int sno;
|
||||||
socket_info status;
|
socket_info status;
|
||||||
@ -920,16 +901,15 @@ p_socket_accept(USES_REGS1)
|
|||||||
#if HAVE_SYS_UN_H
|
#if HAVE_SYS_UN_H
|
||||||
if (domain == af_unix) {
|
if (domain == af_unix) {
|
||||||
struct sockaddr_un caddr;
|
struct sockaddr_un caddr;
|
||||||
unsigned int len;
|
socklen_t len;
|
||||||
|
|
||||||
memset((void *)&caddr, (int)0, sizeof(caddr));
|
memset((void *)&caddr, (int)0, sizeof(caddr));
|
||||||
if ((fd = accept(ofd, (struct sockaddr *)&caddr, &len)) < 0) {
|
if ((fd = accept(ofd, (struct sockaddr *)&caddr, &len)) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_accept/3 (accept: %s)",
|
||||||
"socket_accept/3 (accept: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_accept/3 (accept)");
|
||||||
"socket_accept/3 (accept)");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* ignore 2nd argument */
|
/* ignore 2nd argument */
|
||||||
@ -940,21 +920,16 @@ p_socket_accept(USES_REGS1)
|
|||||||
struct sockaddr_in caddr;
|
struct sockaddr_in caddr;
|
||||||
Term tcli;
|
Term tcli;
|
||||||
char *s;
|
char *s;
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
socklen_t len;
|
||||||
int len;
|
|
||||||
#else
|
|
||||||
unsigned int len;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
len = sizeof(caddr);
|
len = sizeof(caddr);
|
||||||
memset((void *)&caddr, (int)0, sizeof(caddr));
|
memset((void *)&caddr, (int)0, sizeof(caddr));
|
||||||
if (invalid_socket_fd(fd = accept(ofd, (struct sockaddr *)&caddr, &len))) {
|
if (invalid_socket_fd(fd = accept(ofd, (struct sockaddr *)&caddr, &len))) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_accept/3 (accept: %s)",
|
||||||
"socket_accept/3 (accept: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_accept/3 (accept)");
|
||||||
"socket_accept/3 (accept)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -963,8 +938,7 @@ p_socket_accept(USES_REGS1)
|
|||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"socket_accept/3 (inet_ntoa: %s)", strerror(socket_errno));
|
"socket_accept/3 (inet_ntoa: %s)", strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_accept/3 (inet_ntoa)");
|
||||||
"socket_accept/3 (inet_ntoa)");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
tcli = MkAtomTerm(Yap_LookupAtom(s));
|
tcli = MkAtomTerm(Yap_LookupAtom(s));
|
||||||
@ -973,13 +947,12 @@ p_socket_accept(USES_REGS1)
|
|||||||
out = Yap_InitSocketStream(fd, server_session_socket, af_inet);
|
out = Yap_InitSocketStream(fd, server_session_socket, af_inet);
|
||||||
} else
|
} else
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
if (out == TermNil) return(FALSE);
|
if (out == TermNil)
|
||||||
|
return (FALSE);
|
||||||
return (Yap_unify(out, ARG3));
|
return (Yap_unify(out, ARG3));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_buffering(USES_REGS1) {
|
||||||
p_socket_buffering(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
Term t4 = Deref(ARG4);
|
Term t4 = Deref(ARG4);
|
||||||
@ -988,12 +961,11 @@ p_socket_buffering(USES_REGS1)
|
|||||||
int writing;
|
int writing;
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
int bufsize;
|
int bufsize;
|
||||||
int len;
|
|
||||||
#else
|
#else
|
||||||
unsigned int bufsize;
|
unsigned int bufsize;
|
||||||
unsigned int len;
|
|
||||||
#endif
|
#endif
|
||||||
int sno;
|
int sno;
|
||||||
|
socklen_t len;
|
||||||
|
|
||||||
if ((sno = Yap_CheckSocketStream(t1, "socket_buffering/4")) < 0) {
|
if ((sno = Yap_CheckSocketStream(t1, "socket_buffering/4")) < 0) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@ -1046,9 +1018,7 @@ p_socket_buffering(USES_REGS1)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term
|
static Term select_out_list(Term t1, fd_set *readfds_ptr USES_REGS) {
|
||||||
select_out_list(Term t1, fd_set *readfds_ptr USES_REGS)
|
|
||||||
{
|
|
||||||
if (t1 == TermNil) {
|
if (t1 == TermNil) {
|
||||||
return (TermNil);
|
return (TermNil);
|
||||||
} else {
|
} else {
|
||||||
@ -1066,9 +1036,7 @@ select_out_list(Term t1, fd_set *readfds_ptr USES_REGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_socket_select(USES_REGS1) {
|
||||||
p_socket_select(USES_REGS1)
|
|
||||||
{
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
Term t3 = Deref(ARG3);
|
Term t3 = Deref(ARG3);
|
||||||
@ -1143,11 +1111,10 @@ p_socket_select(USES_REGS1)
|
|||||||
/* do the real work */
|
/* do the real work */
|
||||||
if (select(fdmax + 1, &readfds, &writefds, &exceptfds, ptime) < 0) {
|
if (select(fdmax + 1, &readfds, &writefds, &exceptfds, ptime) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_select/5 (select: %s)",
|
||||||
"socket_select/5 (select: %s)", strerror(socket_errno));
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "socket_select/5 (select)");
|
||||||
"socket_select/5 (select)");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
tout = select_out_list(t1, &readfds PASS_REGS);
|
tout = select_out_list(t1, &readfds PASS_REGS);
|
||||||
@ -1155,9 +1122,7 @@ p_socket_select(USES_REGS1)
|
|||||||
return (Yap_unify(ARG4, tout));
|
return (Yap_unify(ARG4, tout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int p_current_host(USES_REGS1) {
|
||||||
static Int
|
|
||||||
p_current_host(USES_REGS1) {
|
|
||||||
char oname[MAXHOSTNAMELEN], *name;
|
char oname[MAXHOSTNAMELEN], *name;
|
||||||
Term t1 = Deref(ARG1), out;
|
Term t1 = Deref(ARG1), out;
|
||||||
|
|
||||||
@ -1171,8 +1136,7 @@ p_current_host(USES_REGS1) {
|
|||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"current_host/2 (gethostname: %s)", strerror(socket_errno));
|
"current_host/2 (gethostname: %s)", strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "current_host/2 (gethostname)");
|
||||||
"current_host/2 (gethostname)");
|
|
||||||
#endif
|
#endif
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -1209,7 +1173,8 @@ p_current_host(USES_REGS1) {
|
|||||||
"current_host/2 (input longer than longest FAQ host name)");
|
"current_host/2 (input longer than longest FAQ host name)");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if (name[isize] != '.') return(FALSE);
|
if (name[isize] != '.')
|
||||||
|
return (FALSE);
|
||||||
name[isize] = '\0';
|
name[isize] = '\0';
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
return (_stricmp(name, sin) == 0);
|
return (_stricmp(name, sin) == 0);
|
||||||
@ -1223,8 +1188,7 @@ p_current_host(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_hostname_address(USES_REGS1) {
|
||||||
p_hostname_address(USES_REGS1) {
|
|
||||||
char *s;
|
char *s;
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term t2 = Deref(ARG2);
|
Term t2 = Deref(ARG2);
|
||||||
@ -1235,20 +1199,23 @@ p_hostname_address(USES_REGS1) {
|
|||||||
if (!IsAtomTerm(t1)) {
|
if (!IsAtomTerm(t1)) {
|
||||||
Yap_Error(TYPE_ERROR_ATOM, t1, "hostname_address/2");
|
Yap_Error(TYPE_ERROR_ATOM, t1, "hostname_address/2");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
} else tin = t1;
|
} else
|
||||||
|
tin = t1;
|
||||||
} else if (IsVarTerm(t2)) {
|
} else if (IsVarTerm(t2)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, t1, "hostname_address/5");
|
Yap_Error(INSTANTIATION_ERROR, t1, "hostname_address/5");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
} else if (!IsAtomTerm(t2)) {
|
} else if (!IsAtomTerm(t2)) {
|
||||||
Yap_Error(TYPE_ERROR_ATOM, t2, "hostname_address/2");
|
Yap_Error(TYPE_ERROR_ATOM, t2, "hostname_address/2");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
} else tin = t2;
|
} else
|
||||||
|
tin = t2;
|
||||||
s = RepAtom(AtomOfTerm(tin))->StrOfAE;
|
s = RepAtom(AtomOfTerm(tin))->StrOfAE;
|
||||||
if (IsVarTerm(t1)) {
|
if (IsVarTerm(t1)) {
|
||||||
if ((he = gethostbyaddr(s, strlen(s), AF_INET)) == NULL) {
|
if ((he = gethostbyaddr(s, strlen(s), AF_INET)) == NULL) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"hostname_address/2 (gethostbyname: %s)", strerror(socket_errno));
|
"hostname_address/2 (gethostbyname: %s)",
|
||||||
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"hostname_address/2 (gethostbyname)");
|
"hostname_address/2 (gethostbyname)");
|
||||||
@ -1261,32 +1228,35 @@ p_hostname_address(USES_REGS1) {
|
|||||||
if ((he = gethostbyname(s)) == NULL) {
|
if ((he = gethostbyname(s)) == NULL) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"hostname_address/2 (gethostbyname: %s)", strerror(socket_errno));
|
"hostname_address/2 (gethostbyname: %s)",
|
||||||
|
strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
"hostname_address/2 (gethostbyname)");
|
"hostname_address/2 (gethostbyname)");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
memcpy((char *) &adr,
|
memcpy((char *)&adr, (char *)he->h_addr_list[0], (size_t)he->h_length);
|
||||||
(char *) he->h_addr_list[0], (size_t) he->h_length);
|
|
||||||
out = MkAtomTerm(Yap_LookupAtom(inet_ntoa(adr)));
|
out = MkAtomTerm(Yap_LookupAtom(inet_ntoa(adr)));
|
||||||
return (Yap_unify(out, ARG2));
|
return (Yap_unify(out, ARG2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void Yap_InitSocketLayer(void) {
|
||||||
Yap_InitSocketLayer(void)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_SOCKET
|
#ifdef HAVE_SOCKET
|
||||||
Yap_InitCPred("socket", 4, p_socket, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("socket", 4, p_socket, SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("socket_close", 1, p_socket_close, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("socket_close", 1, p_socket_close, SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("socket_bind", 2, p_socket_bind, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("socket_bind", 2, p_socket_bind, SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("socket_connect", 3, p_socket_connect, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("socket_connect", 3, p_socket_connect,
|
||||||
Yap_InitCPred("socket_listen", 2, p_socket_listen, SafePredFlag|SyncPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("socket_accept", 3, p_socket_accept, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("socket_listen", 2, p_socket_listen,
|
||||||
Yap_InitCPred("$socket_buffering", 4, p_socket_buffering, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("$socket_select", 4, p_socket_select, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Yap_InitCPred("socket_accept", 3, p_socket_accept,
|
||||||
|
SafePredFlag | SyncPredFlag);
|
||||||
|
Yap_InitCPred("$socket_buffering", 4, p_socket_buffering,
|
||||||
|
SafePredFlag | SyncPredFlag | HiddenPredFlag);
|
||||||
|
Yap_InitCPred("$socket_select", 4, p_socket_select,
|
||||||
|
SafePredFlag | SyncPredFlag | HiddenPredFlag);
|
||||||
Yap_InitCPred("current_host", 1, p_current_host, SafePredFlag);
|
Yap_InitCPred("current_host", 1, p_current_host, SafePredFlag);
|
||||||
Yap_InitCPred("hostname_address", 2, p_hostname_address, SafePredFlag);
|
Yap_InitCPred("hostname_address", 2, p_hostname_address, SafePredFlag);
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
@ -1298,4 +1268,3 @@ Yap_InitSocketLayer(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user