diff -ruN klic-3.003-2001-11-25/runtime/gunix.kl1 klic-3.003-2001-11-26/runtime/gunix.kl1
--- klic-3.003-2001-11-25/runtime/gunix.kl1	Sun Nov 25 21:05:15 2001
+++ klic-3.003-2001-11-26/runtime/gunix.kl1	Mon Nov 26 12:48:49 2001
@@ -8,6 +8,7 @@
 :- inline:"
 #include <string.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -29,25 +30,23 @@
 #include <signal.h>
 #endif
 
-#ifdef ASYNCIO
-#ifndef FASYNC
+#if defined(ASYNCIO) && !defined(FASYNC)
 #include <fcntl.h>
 #ifndef USESTREAMINCLUDEDIR
 #include <stropts.h>
 #endif
-#endif
-#endif
+#endif /* defined(ASYNCIO) && !defined(FASYNC) */
 
 #ifndef O_NONBLOCK
 #define O_NONBLOCK FNDELAY
 #endif
 
-extern char *malloc_check();
+extern char* malloc_check();
 GD_USE_CLASS(pointer);
-q *register_streamed_signal();
+extern q* register_streamed_signal();
 
-extern char *generic_string_body();
-extern char *convert_klic_string_to_c_string();
+extern char* generic_string_body();
+extern char* convert_klic_string_to_c_string();
 extern q convert_c_string_to_klic_string();
 extern q convert_binary_c_string_to_klic_string();
 
@@ -57,29 +56,29 @@
 
 extern q gd_new_pointer();
 #define FilePointer(x) \\
-  ((FILE*)((struct pointer_object *)(data_objectp(x)))->pointer)
+  ((FILE*) ((struct pointer_object*) (data_objectp(x)))->pointer)
 
-#define MakeFilePointer(klicvar,file) \\
-{ \\
-  klicvar = gd_new_pointer((q)file, allocp); \\
+#define MakeFilePointer(klicvar, file) \\
+do{ \\
+  (klicvar) = gd_new_pointer((q) (file), allocp); \\
   allocp = heapp; \\
-}
+}while(0)
 
 #define Fopen(P,F,L,M) \\
-{ \\
-  char *path = KLIC2C(P); \\
-  FILE *file = fopen(path, M); \\
+do{ \\
+  char* path = KLIC2C(P); \\
+  FILE* file = fopen(path, (M)); \\
   free(path); \\
   if (file==NULL) goto L; \\
-  MakeFilePointer(F, file); \\
-}
+  MakeFilePointer((F), file); \\
+}while(0)
 
 #define Fdopen(Fd,F,L,M) \\
-{ \\
-  FILE *file = fdopen(Fd, M); \\
+do{ \\
+  FILE* file = fdopen((Fd), (M)); \\
   if (file==NULL) goto L; \\
-  MakeFilePointer(F, file); \\
-}
+  MakeFilePointer((F), file); \\
+}while(0)
 
 struct iobuf {
   unsigned char *ptr, *lim, *buf;
@@ -87,19 +86,17 @@
   int bufsize;
 };
 
-static struct iobuf *make_iobuf(fd, size, isout)
-     int fd, size, isout;
+static struct iobuf* make_iobuf(
+  int fd,
+  int size,
+  int isout )
 {
-  struct iobuf *iob = (struct iobuf *)malloc_check(sizeof(struct iobuf));
+  struct iobuf* iob = (struct iobuf*) malloc_check(sizeof(struct iobuf));
   iob->fd = fd;
   iob->bufsize = size;
-  iob->buf = (unsigned char *)malloc_check(iob->bufsize);
+  iob->buf = (unsigned char*) malloc_check(iob->bufsize);
   iob->ptr = iob->buf;
-  if (isout) {
-    iob->lim = iob->buf+size;
-  } else {
-    iob->lim = iob->buf;
-  }
+  iob->lim = iob->buf + (isout ? size : 0);
   return iob;
 }
 
@@ -108,22 +105,24 @@
   struct iobuf obuf;
 };
 
-static struct biobuf *make_biobuf(ifd, ofd, size)
-     int ifd, ofd, size;
-{
-  struct biobuf *biob = (struct biobuf *)malloc_check(sizeof(struct biobuf));
-  struct iobuf *ibuf = &(biob->ibuf);
-  struct iobuf *obuf = &(biob->obuf);
+static struct biobuf* make_biobuf(
+  int ifd,
+  int ofd,
+  int size )
+{
+  struct biobuf* biob = (struct biobuf*) malloc_check(sizeof(struct biobuf));
+  struct iobuf* ibuf = &(biob->ibuf);
+  struct iobuf* obuf = &(biob->obuf);
 
   ibuf->fd = ifd;
   ibuf->bufsize = size;
-  ibuf->buf = (unsigned char *)malloc_check(ibuf->bufsize);
+  ibuf->buf = (unsigned char*) malloc_check(ibuf->bufsize);
   ibuf->ptr = ibuf->buf;
   ibuf->lim = ibuf->buf;
 
   obuf->fd = ofd;
   obuf->bufsize = size;
-  obuf->buf = (unsigned char *)malloc_check(obuf->bufsize);
+  obuf->buf = (unsigned char*) malloc_check(obuf->bufsize);
   obuf->ptr = obuf->buf;
   obuf->lim = obuf->buf+size;
 
@@ -131,35 +130,41 @@
 }
 
 #define MakeInBuf(klicvar, fd, size) \\
-{ \\
-  klicvar = gd_new_pointer((q)make_iobuf(fd,size,0), allocp); \\
+do{ \\
+  (klicvar) = gd_new_pointer((q) make_iobuf((fd),(size),0), allocp); \\
   allocp = heapp; \\
-}
+}while(0)
 
 #define MakeOutBuf(klicvar, fd, size) \\
-{ \\
-  klicvar = gd_new_pointer((q)make_iobuf(fd,size,1), allocp); \\
+do{ \\
+  (klicvar) = gd_new_pointer((q) make_iobuf((fd),(size),1), allocp); \\
   allocp = heapp; \\
-}
+}while(0)
 
 #define IOBuf(x) \\
-  ((struct iobuf*)((struct pointer_object *)(data_objectp(x)))->pointer)
+  ((struct iobuf*) ((struct pointer_object*) (data_objectp(x)))->pointer)
 
 #define MakeBIOBuf(klicvar, ifd, ofd, size) \\
-{ \\
-  klicvar = gd_new_pointer((q)make_biobuf(ifd,ofd,size), allocp); \\
+do{ \\
+  (klicvar) = gd_new_pointer((q) make_biobuf((ifd),(ofd),(size)), allocp); \\
   allocp = heapp; \\
-}
+}while(0)
 
 #define BIOBuf(x) \\
-  ((struct biobuf*)((struct pointer_object *)(data_objectp(x)))->pointer)
+  ((struct biobuf*) ((struct pointer_object*) (data_objectp(x)))->pointer)
 
-static int fill_buf(iob)
-     struct iobuf *iob;
+static int fill_buf(
+  struct iobuf* iob )
 {
   while (1) {
     int result = read(iob->fd, iob->buf, iob->bufsize);
-    if (result < 0) {
+    if (result == 0) {
+      return 0;			/* end of file */
+    } else if (result > 0) {
+      iob->lim = iob->buf + result;
+      iob->ptr = iob->buf;
+      return 1;
+    } else {  /* result < 0 */
       switch (errno) {
       case EINTR: continue;
 #ifdef EPIPE
@@ -168,33 +173,34 @@
 #endif /* EPIPE */
 #ifdef ASYNCIO
       case EAGAIN:
-#ifdef EWOULDBLOCK
-#if EWOULDBLOCK != EAGAIN
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
       case EWOULDBLOCK:
 #endif
-#endif
 	return -1;
-#endif
+#endif /* ASINCIO */
       default:
 	fatalp(\"read\", \"Error in asynchronous input\");
       }
-    } else if (result == 0) {
-      return 0;			/* end of file */
-    } else {
-      iob->lim = iob->buf+result;
-      iob->ptr = iob->buf;
-      return 1;
     }
   }
 }
 
-static int write_buf(iob)
-     struct iobuf *iob;
+static int write_buf(
+  struct iobuf* iob )
 {
-  unsigned char *wp = iob->buf;
+  unsigned char* wp = iob->buf;
   while (1) {
     int result = write(iob->fd, wp, (iob->ptr - wp));
-    if (result < 0) {
+    if (result >= 0) {
+      wp += result;
+      if (wp != iob->ptr) {
+	continue;
+      } else {
+	iob->lim = iob->buf + iob->bufsize;
+	iob->ptr = iob->buf;
+	return 1;
+      }
+    } else {  /* result < 0 */
       switch (errno) {
       case EINTR: continue;
 #ifdef EPIPE
@@ -203,11 +209,9 @@
 #endif /* EPIPE */
 #ifdef ASYNCIO
       case EAGAIN:
-#ifdef EWOULDBLOCK
-#if EWOULDBLOCK != EAGAIN
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
       case EWOULDBLOCK:
 #endif
-#endif
 
 /*
   Patch to detour a suspected bug of SunOS 4.1.3
@@ -236,33 +240,24 @@
 #else
 	  fatal(\"Don't know how to obtaine file descriptor table size\");
 #endif
-#endif
+#endif /* USEGETDTABLESIZE */
 	  FD_ZERO(&fdsw);
 	  FD_SET(iob->fd, &fdsw);
 	  select(fd_setsize, 0, &fdsw, 0, 0);
 	}
 	continue;
 /* End of Patch */
-#endif
+#endif /* ASYNCIO */
       default:
 	fatalp(\"write\", \"Error in asynchronous output\");
       }
-    } else {
-      wp += result;
-      if (wp != iob->ptr) {
-	continue;
-      } else {
-	iob->lim = iob->buf + iob->bufsize;
-	iob->ptr = iob->buf;
-	return 1;
-      }
     }
   }
 }
 
-static void setasync(sock, msg)
-     int sock;
-     char *msg;
+static void setasync(
+  int sock,
+  char* msg )
 {
 #ifdef ASYNCIO
   if (fcntl(sock, F_SETOWN, getpid()) < -1) {
@@ -387,12 +382,12 @@
   char *path = KLIC2C(%0);
 
   addr =
-    (struct sockaddr *)malloc_check(sizeof(struct sockaddr)+strlen(path));
+    (struct sockaddr*) malloc_check(sizeof(struct sockaddr) + strlen(path));
   addr->sa_family = family;
   strcpy(addr->sa_data, path);
   free(path);
   %1 = makeint(family);
-  %2 = gd_new_pointer((q)addr, allocp);
+  %2 = gd_new_pointer((q) addr, allocp);
   allocp = heapp;
 #else
   goto %f;
@@ -403,16 +398,16 @@
 {
 #ifndef NO_USESOCKET
   int family = PF_INET;
-  struct sockaddr_in *addr;
-  char *host = KLIC2C(%0);
-  struct hostent *ent = gethostbyname(host);
+  struct sockaddr_in* addr;
+  char* host = KLIC2C(%0);
+  struct hostent* ent = gethostbyname(host);
 
-  if (ent == NULL) { fatalf(\"Unknown host %%s\", host); };
+  if (ent == NULL) { fatalf(\"Unknown host %%s\", host); }
   free(host);
-  addr = (struct sockaddr_in *)
+  addr = (struct sockaddr_in*)
     malloc_check(sizeof(struct sockaddr_in));
   addr->sin_family = family;
-  BCOPY((char*)*ent->h_addr_list, (char*)&addr->sin_addr,
+  BCOPY((char*) *ent->h_addr_list, (char*) &addr->sin_addr,
 	sizeof(struct in_addr));
 /*
   The following is not used as some systems don't understand it.
@@ -421,7 +416,7 @@
 */
   addr->sin_port = htons(intval(%1));
   %2 = makeint(family);
-  %3 = gd_new_pointer((q)addr, allocp);
+  %3 = gd_new_pointer((q) addr, allocp);
   allocp = heapp;
 #else
   goto %f;
@@ -433,19 +428,19 @@
 {
 #ifndef NO_USESOCKET
   int family = PF_INET;
-  struct sockaddr_in *addr;
+  struct sockaddr_in* addr;
   int b1, b2, b3, b4;
   unsigned long laddr;
   char buf[100];
 
-  addr = (struct sockaddr_in *)
+  addr = (struct sockaddr_in*)
     malloc_check(sizeof(struct sockaddr_in));
   addr->sin_family = family;
   b1 = intval(%0); b2 = intval(%1); b3 = intval(%2); b4 = intval(%3);
-  (void)sprintf(buf, \"%%d.%%d.%%d.%%d\", b1, b2, b3, b4);
+  (void) sprintf(buf, \"%%d.%%d.%%d.%%d\", b1, b2, b3, b4);
   laddr = inet_addr(buf);
   if (laddr == -1) goto %f;
-  BCOPY((char*)&laddr, (char*)&addr->sin_addr, sizeof(struct in_addr));
+  BCOPY((char*) &laddr, (char*) &addr->sin_addr, sizeof(struct in_addr));
 /*
   The following is not used as some systems don't understand it.
 
@@ -456,7 +451,7 @@
 */
   addr->sin_port = htons(intval(%4));
   %5 = makeint(family);
-  %6 = gd_new_pointer((q)addr, allocp);
+  %6 = gd_new_pointer((q) addr, allocp);
   allocp = heapp;
 #else
   goto %f;
@@ -492,8 +487,8 @@
 {
 #ifndef NO_USESOCKET
   int sock = intval(%0);
-  struct sockaddr *addr = (struct sockaddr*)
-    ((struct pointer_object *)(data_objectp(%1)))->pointer;
+  struct sockaddr* addr = (struct sockaddr*)
+    ((struct pointer_object*) (data_objectp(%1)))->pointer;
 
  again:
   if (connect(sock, addr, sizeof(struct sockaddr)) < 0) {
@@ -558,8 +553,8 @@
 {
 #ifndef NO_USESOCKET
   int sock = intval(%0);
-  struct sockaddr *addr = (struct sockaddr*)
-    ((struct pointer_object *)(data_objectp(%1)))->pointer;
+  struct sockaddr* addr = (struct sockaddr*)
+    ((struct pointer_object*) (data_objectp(%1)))->pointer;
 
  again2:
   if (connect(sock, addr, sizeof(struct sockaddr)) < 0) {
@@ -609,8 +604,8 @@
 #ifndef NO_USESOCKET
   int family = intval(%0);
   int reuse = 1;
-  struct sockaddr *addr = (struct sockaddr*)
-    ((struct pointer_object *)(data_objectp(%1)))->pointer;
+  struct sockaddr* addr = (struct sockaddr*)
+    ((struct pointer_object*) (data_objectp(%1)))->pointer;
   int sock = socket(family, SOCK_STREAM, 0);
 
   if (sock < 0) { fatalp(\"socket\", \"Socket creation error\"); }
@@ -620,7 +615,7 @@
 
   if (addr->sa_family == PF_INET) {
     if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-		   (char *)&reuse, sizeof(reuse))) {
+		   (char*) &reuse, sizeof(reuse))) {
       fatalp(\"setsockopt\", \"Socket reuse setting error for binding\");
     }
   }
@@ -650,7 +645,7 @@
 #ifndef NO_USESOCKET
   int fd = intval(%0);
   int namelen = 1000;
-  struct sockaddr *name = (struct sockaddr *)malloc_check(namelen);
+  struct sockaddr* name = (struct sockaddr*) malloc_check(namelen);
   getsockname(fd, name, &namelen);
   if (close(fd) != 0) {
     fatalp(\"close\", \"Error in closing bound socket\");
@@ -748,8 +743,8 @@
 async_io([],_Async,InB,OutB,_LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *outb = IOBuf(%0);
-  struct iobuf *inb = IOBuf(%1);
+  struct iobuf* outb = IOBuf(%0);
+  struct iobuf* inb = IOBuf(%1);
   if (outb->ptr != outb->buf) {
     switch (write_buf(outb)) {
     case -1: goto %f;
@@ -769,14 +764,15 @@
 async_io([C|S],Async,InB,OutB,LC) :- integer(C), inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *iob = IOBuf(%0);
+  struct iobuf* iob = IOBuf(%0);
   if (iob->ptr == iob->lim) {
     switch (write_buf(iob)) {
     case -1: goto %f;
     case 1: break;
     }
   }
-  *iob->ptr++ = intval(%1);
+  *iob->ptr = intval(%1);
+  iob->ptr++;
 #else
   goto %f;
 #endif
@@ -785,17 +781,18 @@
 async_io([getc(C)|S],Async,InB,OutB,LC0) :- inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *iob = IOBuf(%0);
+  struct iobuf* iob = IOBuf(%0);
   int c;
   if (iob->ptr == iob->lim) {
     switch (fill_buf(iob)) {
     case -1: goto %f;
     case -2: goto %f;
     case 0: c = -1; break;
-    case 1: c = *iob->ptr++; break;
+    case 1: c = *iob->ptr; iob->ptr++; break;
     }
   } else {
-    c = *iob->ptr++;
+    c = *iob->ptr;
+    iob->ptr++;
   }
   %3 = makeint(intval(%2) + ( c=='\\n' ? 1 : 0 ));
   %1 = makeint(c);
@@ -808,7 +805,7 @@
 async_io([fread(N,R)|S],Async,InB,OutB,LC0) :- inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *iob = IOBuf(%0);
+  struct iobuf* iob = IOBuf(%0);
   int toread = intval(%1);
   int k, nnl;
   int ready_bytes = iob->lim - iob->ptr;
@@ -822,9 +819,9 @@
     }
   }
   if (toread > iob->lim - iob->ptr) toread = iob->lim - iob->ptr;
-  if ((char *)allocp+
-      sizeof(struct byte_string_object)+toread+sizeof(long) >=
-      (char *)real_heaplimit) {
+  if ((char*) allocp +
+      sizeof(struct byte_string_object) + toread + sizeof(long) >=
+      (char*) real_heaplimit) {
     allocp = real_heaplimit;
     goto async__io_5_ext_interrupt;
   }
@@ -851,7 +848,7 @@
 async_io([feof(R)|S],Async,InB,OutB,LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *iob = IOBuf(%0);
+  struct iobuf* iob = IOBuf(%0);
   if (iob->ptr == iob->lim) {
     switch (fill_buf(iob)) {
     case -1: goto %f;
@@ -876,8 +873,8 @@
 async_io([fwrite(X,R)|S],Async,InB,OutB,LC) :- string(X,L,8), inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *iob = IOBuf(%0);
-  char *str = KLIC2C(%1);
+  struct iobuf* iob = IOBuf(%0);
+  char* str = KLIC2C(%1);
   int len =intval(%2);
   int room = iob->lim - iob->ptr;
   while (iob->ptr + len >= iob->lim) {
@@ -903,7 +900,7 @@
 async_io([fflush(R)|S],Async,InB,OutB,LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct iobuf *iob = IOBuf(%0);
+  struct iobuf* iob = IOBuf(%0);
   if (iob->ptr != iob->buf) {
     switch (write_buf(iob)) {
     case -1: goto %f;
@@ -919,7 +916,7 @@
 async_io([sync(R)|S],Async,InB,OutB,LC) :- inline:"
 #ifdef ASYNCIO
 {
-  struct iobuf *iob = IOBuf(%0);
+  struct iobuf* iob = IOBuf(%0);
   switch (write_buf(iob)) {
   case -1: goto %f;
   case 1: break;
@@ -936,9 +933,9 @@
 async_input([],_Async,IOB,_LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *inb = &(biob->ibuf);
-  struct iobuf *outb = &(biob->obuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* inb = &(biob->ibuf);
+  struct iobuf* outb = &(biob->obuf);
   if (inb->fd != outb->fd) {
     if (close(inb->fd) != 0) {
       fatalp(\"close\", \"Error in closing asynchronous input\");
@@ -957,18 +954,19 @@
 async_input([getc(C)|S],Async,IOB,LC0) :- inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *iob = &(biob->ibuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* iob = &(biob->ibuf);
   int c;
   if (iob->ptr == iob->lim) {
     switch (fill_buf(iob)) {
     case -1: goto %f;
     case -2: goto %f;
     case 0: c = -1; break;
-    case 1: c = *iob->ptr++; break;
+    case 1: c = *iob->ptr; iob->ptr++; break;
     }
   } else {
-    c = *iob->ptr++;
+    c = *iob->ptr;
+    iob->ptr++;
   }
   %3 = makeint(intval(%2) + ( c=='\\n' ? 1 : 0 ));
   %1 = makeint(c);
@@ -981,8 +979,8 @@
 async_input([fread(N,R)|S],Async,IOB,LC0) :- inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *iob = &(biob->ibuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* iob = &(biob->ibuf);
   int toread = intval(%1);
   int k, nnl;
   int ready_bytes = iob->lim - iob->ptr;
@@ -996,9 +994,9 @@
     }
   }
   if (toread > iob->lim - iob->ptr) toread = iob->lim - iob->ptr;
-  if ((char *)allocp+
-      sizeof(struct byte_string_object)+toread+sizeof(long) >=
-      (char *)real_heaplimit) {
+  if ((char*) allocp +
+      sizeof(struct byte_string_object) + toread + sizeof(long) >=
+      (char*) real_heaplimit) {
     allocp = real_heaplimit;
     goto async__input_4_ext_interrupt;
   }
@@ -1012,7 +1010,7 @@
   %2 = str;
   allocp = heapp;
   iob->ptr += toread;
-  %4 = makeint(intval(%3)+nnl);
+  %4 = makeint(intval(%3) + nnl);
 #else
   goto %f;
 #endif
@@ -1025,8 +1023,8 @@
 async_input([feof(R)|S],Async,IOB,LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *iob = &(biob->ibuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* iob = &(biob->ibuf);
   if (iob->ptr == iob->lim) {
     switch (fill_buf(iob)) {
     case -1: goto %f;
@@ -1050,9 +1048,9 @@
 async_output([],_Async,IOB,_LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *inb = &(biob->ibuf);
-  struct iobuf *outb = &(biob->obuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* inb = &(biob->ibuf);
+  struct iobuf* outb = &(biob->obuf);
   if (outb->ptr != outb->buf) {
     switch (write_buf(outb)) {
     case -1: goto %f;
@@ -1078,8 +1076,8 @@
 async_output([C|S],Async,IOB,LC) :- integer(C), inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *iob = &(biob->obuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* iob = &(biob->obuf);
   if (iob->ptr == iob->lim) {
     switch (write_buf(iob)) {
     case -1: goto %f;
@@ -1087,7 +1085,8 @@
     case 1: break;
     }
   }
-  *iob->ptr++ = intval(%1);
+  *iob->ptr = intval(%1);
+  iob->ptr++;
 #else
   goto %f;
 #endif
@@ -1104,10 +1103,10 @@
 async_output([fwrite(X,R)|S],Async,IOB,LC) :- string(X,L,8), inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *iob = &(biob->obuf);
-  char *str = KLIC2C(%1);
-  int len =intval(%2);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* iob = &(biob->obuf);
+  char* str = KLIC2C(%1);
+  int len = intval(%2);
   int room = iob->lim - iob->ptr;
   while (iob->ptr + len >= iob->lim) {
     BCOPY(str, iob->ptr, room);
@@ -1137,8 +1136,8 @@
 async_output([fflush(R)|S],Async,IOB,LC) :- inline:"
 {
 #ifdef ASYNCIO
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *iob = &(biob->obuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* iob = &(biob->obuf);
   if (iob->ptr != iob->buf) {
     switch (write_buf(iob)) {
     case -1: goto %f;
@@ -1159,8 +1158,8 @@
 async_output([sync(R)|S],Async,IOB,LC) :- inline:"
 #ifdef ASYNCIO
 {
-  struct biobuf *biob = BIOBuf(%0);
-  struct iobuf *outb = &(biob->obuf);
+  struct biobuf* biob = BIOBuf(%0);
+  struct iobuf* outb = &(biob->obuf);
   switch (write_buf(outb)) {
   case -1: goto %f;
   case -2: goto %f;
@@ -1185,35 +1184,33 @@
 
 system(S,R) :- inline:"
 {
-  char *buf = KLIC2C(%0);
+  char* buf = KLIC2C(%0);
   %1 = makeint(system(buf));
   free(buf);
 }":[S+object(byte_string),R0-int] | R = R0.
 
 cd(Dir,R) :- inline:"
 {
-  char *buf = KLIC2C(%0);
+  char* buf = KLIC2C(%0);
   %1 = makeint(chdir(buf));
   free(buf);
 }":[Dir+object(byte_string),R0-int] | R=R0.
 
 unlink(Path,R) :- inline:"
 {
-  char *path = KLIC2C(%0);
+  char* path = KLIC2C(%0);
   %1 = makeint(unlink(path));
   free(path);
 }":[Path+object(byte_string),R0-int] | R=R0.
 
 mktemp(Template,Filename) :- inline:"
 {
-  char *template = KLIC2C(%0);
-  char *real_template = (char *)malloc_check(strlen(template)+7);
-  char *mktemp();
-  char *result;
-  (void)strcpy(real_template, template);
-  (void)strcat(real_template, \"XXXXXX\");
-  result = mktemp(real_template);
-  %1 = C2KLIC(result, allocp);
+  char* template = KLIC2C(%0);
+  char* real_template = (char*) malloc_check(strlen(template) + 7);
+  (void) strcpy(real_template, template);
+  (void) strcat(real_template, \"XXXXXX\");
+  if(mkstemp(real_template) < 0) real_template[0] = '\0';
+  %1 = C2KLIC(real_template, allocp);
   allocp = heapp;
   free(template);
   free(real_template);
@@ -1222,14 +1219,14 @@
 
 access(Path,Mode,Result) :- inline:"
 {
-  char *path = KLIC2C(%0);
+  char* path = KLIC2C(%0);
   %2 = makeint(access(path, intval(%1)));
   free(path);
 }":[Path+object(byte_string),Mode+int,Result0-int] | Result=Result0.
 
 chmod(Path,New,Result) :- inline:"
 {
-  char *path = KLIC2C(%0);
+  char* path = KLIC2C(%0);
   %2 = makeint(chmod(path, intval(%1)));
   free(path);
 }":[Path+object(byte_string),New+int,Result0-int] | Result=Result0.
@@ -1248,9 +1245,9 @@
 
 getenv(Name,Value) :- inline:"
 {
-  extern char *getenv();
-  char *str = KLIC2C(%0);
-  char *value = getenv(str);
+  extern char* getenv();
+  char* str = KLIC2C(%0);
+  char* value = getenv(str);
   free(str);
   if (value==0) {
     %1 = makeint(0);
@@ -1262,7 +1259,7 @@
 
 putenv(Str,R) :- inline:"
 {
-  char *str = KLIC2C(%0);
+  char* str = KLIC2C(%0);
   %1 = makeint(putenv(str));
 }":[Str+object(byte_string),R0-int] | R=R0.
 
@@ -1278,9 +1275,11 @@
   int fd1[2], fd2[2];
   long pid;
   if (pipe(fd1) != 0) goto %f;
-  Fdopen(fd1[0],%1,%f,\"r\"); Fdopen(fd1[1],%2,%f,\"w\");
+  Fdopen(fd1[0], %1, %f, \"r\");
+  Fdopen(fd1[1], %2, %f, \"w\");
   if (pipe(fd2) != 0) goto %f;
-  Fdopen(fd2[0],%3,%f,\"r\"); Fdopen(fd2[1],%4,%f,\"w\");
+  Fdopen(fd2[0], %3, %f, \"r\");
+  Fdopen(fd2[1], %4, %f, \"w\");
   pid = fork();
   if (pid==0) {
     fclose(FilePointer(%1));
@@ -1336,10 +1335,10 @@
 #endif
   struct tms buf;
   (void) times(&buf);
-  %0 = makeint((int)(buf.tms_utime*1000.0/HZ));
-  %1 = makeint((int)(buf.tms_stime*1000.0/HZ));
-  %2 = makeint((int)(buf.tms_cutime*1000.0/HZ));
-  %3 = makeint((int)(buf.tms_cstime*1000.0/HZ));
+  %0 = makeint((int)(buf.tms_utime * 1000.0/HZ));
+  %1 = makeint((int)(buf.tms_stime * 1000.0/HZ));
+  %2 = makeint((int)(buf.tms_cutime * 1000.0/HZ));
+  %3 = makeint((int)(buf.tms_cstime * 1000.0/HZ));
 }":[U0-int,S0-int,CU0-int,CS0-int] |
     U=U0, S=S0, CU=CU0, CS=CS0.
 
