summaryrefslogtreecommitdiffstats
path: root/otherlibs
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs')
-rw-r--r--otherlibs/unix/connect.c7
-rw-r--r--otherlibs/unix/gethost.c13
-rw-r--r--otherlibs/unix/read.c1
-rw-r--r--otherlibs/unix/sendrecv.c4
-rw-r--r--otherlibs/unix/unix.h19
-rw-r--r--otherlibs/unix/unixsupport.c13
-rw-r--r--otherlibs/unix/write.c1
7 files changed, 38 insertions, 20 deletions
diff --git a/otherlibs/unix/connect.c b/otherlibs/unix/connect.c
index 66f20ae66..b69396b4b 100644
--- a/otherlibs/unix/connect.c
+++ b/otherlibs/unix/connect.c
@@ -21,9 +21,12 @@
value unix_connect(socket, address) /* ML */
value socket, address;
{
+ int retcode;
get_sockaddr(address);
- if (connect(Int_val(socket), &sock_addr.s_gen, sock_addr_len) == -1)
- uerror("connect", Nothing);
+ enter_blocking_section();
+ retcode = connect(Int_val(socket), &sock_addr.s_gen, sock_addr_len);
+ leave_blocking_section();
+ if (retcode == -1) uerror("connect", Nothing);
return Val_unit;
}
diff --git a/otherlibs/unix/gethost.c b/otherlibs/unix/gethost.c
index 999cdc2ca..a634d2a43 100644
--- a/otherlibs/unix/gethost.c
+++ b/otherlibs/unix/gethost.c
@@ -61,8 +61,12 @@ static value alloc_host_entry(entry)
value unix_gethostbyaddr(a) /* ML */
value a;
{
+ uint32 addr;
struct hostent * entry;
- entry = gethostbyaddr((char *) &GET_INET_ADDR(a), 4, AF_INET);
+ addr = GET_INET_ADDR(a);
+ enter_blocking_section();
+ entry = gethostbyaddr((char *) &addr, 4, AF_INET);
+ leave_blocking_section();
if (entry == (struct hostent *) NULL) raise_not_found();
return alloc_host_entry(entry);
}
@@ -70,8 +74,13 @@ value unix_gethostbyaddr(a) /* ML */
value unix_gethostbyname(name) /* ML */
value name;
{
+ char hostname[256];
struct hostent * entry;
- entry = gethostbyname(String_val(name));
+ strncpy(hostname, String_val(name), sizeof(hostname) - 1);
+ hostname[sizeof(hostname) - 1] = 0;
+ enter_blocking_section();
+ entry = gethostbyname(hostname);
+ leave_blocking_section();
if (entry == (struct hostent *) NULL) raise_not_found();
return alloc_host_entry(entry);
}
diff --git a/otherlibs/unix/read.c b/otherlibs/unix/read.c
index 49485ce43..f7870a821 100644
--- a/otherlibs/unix/read.c
+++ b/otherlibs/unix/read.c
@@ -18,6 +18,7 @@ value unix_read(fd, buf, ofs, len) /* ML */
value fd, buf, ofs, len;
{
int ret;
+ buf = unix_freeze_buffer(buf);
enter_blocking_section();
ret = read(Int_val(fd), &Byte(buf, Long_val(ofs)), Int_val(len));
leave_blocking_section();
diff --git a/otherlibs/unix/sendrecv.c b/otherlibs/unix/sendrecv.c
index dfa54c902..8b9f7452a 100644
--- a/otherlibs/unix/sendrecv.c
+++ b/otherlibs/unix/sendrecv.c
@@ -30,6 +30,7 @@ value unix_recv(sock, buff, ofs, len, flags) /* ML */
value sock, buff, ofs, len, flags;
{
int ret;
+ buff = unix_freeze_buffer(buff);
enter_blocking_section();
ret = recv(Int_val(sock), &Byte(buff, Long_val(ofs)), Int_val(len),
convert_flag_list(flags, msg_flag_table));
@@ -45,6 +46,7 @@ value unix_recvfrom(sock, buff, ofs, len, flags) /* ML */
value res;
Push_roots(a, 1);
+ buff = unix_freeze_buffer(buff);
sock_addr_len = sizeof(sock_addr);
enter_blocking_section();
retcode = recvfrom(Int_val(sock), &Byte(buff, Long_val(ofs)), Int_val(len),
@@ -64,6 +66,7 @@ value unix_send(sock, buff, ofs, len, flags) /* ML */
value sock, buff, ofs, len, flags;
{
int ret;
+ buff = unix_freeze_buffer(buff);
enter_blocking_section();
ret = send(Int_val(sock), &Byte(buff, Long_val(ofs)), Int_val(len),
convert_flag_list(flags, msg_flag_table));
@@ -77,6 +80,7 @@ value unix_sendto_native(sock, buff, ofs, len, flags, dest)
{
int ret;
get_sockaddr(dest);
+ buff = unix_freeze_buffer(buff);
enter_blocking_section();
ret = sendto(Int_val(sock), &Byte(buff, Long_val(ofs)),
Int_val(len), convert_flag_list(flags, msg_flag_table),
diff --git a/otherlibs/unix/unix.h b/otherlibs/unix/unix.h
index 5a26a7c3d..8783328f8 100644
--- a/otherlibs/unix/unix.h
+++ b/otherlibs/unix/unix.h
@@ -13,19 +13,6 @@
#define Nothing ((value) 0)
-#ifndef NULL
-#ifdef __STDC__
-#define NULL ((void *) 0)
-#else
-#define NULL ((char *) 0)
-#endif
-#endif
-
-#ifdef __STDC__
-extern void unix_error(int errcode, char * cmdname, value arg);
-extern void uerror(char * cmdname, value arg);
-#else
-void unix_error();
-void uerror();
-#endif
-
+extern void unix_error P((int errcode, char * cmdname, value arg));
+extern void uerror P((char * cmdname, value arg));
+extern value unix_freeze_buffer P((value));
diff --git a/otherlibs/unix/unixsupport.c b/otherlibs/unix/unixsupport.c
index 2f79f906f..08942454b 100644
--- a/otherlibs/unix/unixsupport.c
+++ b/otherlibs/unix/unixsupport.c
@@ -298,3 +298,16 @@ void uerror(cmdname, cmdarg)
{
unix_error(errno, cmdname, cmdarg);
}
+
+value unix_freeze_buffer(buf)
+ value buf;
+{
+ if (Is_young(buf)) {
+ Push_roots(r, 1);
+ r[0] = buf;
+ minor_collection();
+ buf = r[0];
+ Pop_roots();
+ }
+ return buf;
+}
diff --git a/otherlibs/unix/write.c b/otherlibs/unix/write.c
index 99ab72131..db7ab276c 100644
--- a/otherlibs/unix/write.c
+++ b/otherlibs/unix/write.c
@@ -18,6 +18,7 @@ value unix_write(fd, buf, ofs, len) /* ML */
value fd, buf, ofs, len;
{
int ret;
+ buf = unix_freeze_buffer(buf);
enter_blocking_section();
ret = write(Int_val(fd), &Byte(buf, Long_val(ofs)), Int_val(len));
leave_blocking_section();