use usleep if avail.
authorClaus Gittinger <cg@exept.de>
Tue, 22 Sep 2015 00:53:07 +0200
changeset 18758 fd717520a5ef
parent 18753 941d99755164
child 18760 9b0b0c157e4c
use usleep if avail.
UnixOperatingSystem.st
--- a/UnixOperatingSystem.st	Wed Sep 16 14:50:26 2015 +0200
+++ b/UnixOperatingSystem.st	Tue Sep 22 00:53:07 2015 +0200
@@ -708,103 +708,103 @@
     sigset_t block, omask;
 
     if (line == NULL)
-        return -1;
+	return -1;
 
     sa.sa_handler = SIG_IGN;
     sa.sa_flags = 0;
     __sigemptyset (&sa.sa_mask);
 
     if (__sigaction (SIGINT, &sa, &intr) < 0) {
-        DPRINTF(("1: errno=%d\n", errno));
-        return -1;
+	DPRINTF(("1: errno=%d\n", errno));
+	return -1;
     }
     if (__sigaction (SIGQUIT, &sa, &quit) < 0) {
-        save = errno;
-        (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
-        errno = save;
-        DPRINTF(("2: errno=%d\n", errno));
-        return -1;
+	save = errno;
+	(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
+	errno = save;
+	DPRINTF(("2: errno=%d\n", errno));
+	return -1;
     }
 
     __sigemptyset (&block);
     __sigaddset (&block, SIGCHLD);
     save = errno;
     if (__sigprocmask(SIG_BLOCK, &block, &omask) < 0) {
-        if (errno == ENOSYS)
-            errno = save;
-        else {
-            save = errno;
-            (void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL);
-            (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
-            errno = save;
-            DPRINTF(("3: errno=%d\n", errno));
-            return -1;
-        }
+	if (errno == ENOSYS)
+	    errno = save;
+	else {
+	    save = errno;
+	    (void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL);
+	    (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
+	    errno = save;
+	    DPRINTF(("3: errno=%d\n", errno));
+	    return -1;
+	}
     }
 
     pid = FORK ();
     if (pid == (pid_t) 0) {
-        /* Child side.  */
-        CONST char *new_argv[4];
-        new_argv[0] = SHELL_NAME;
-        new_argv[1] = "-c";
-        new_argv[2] = line;
-        new_argv[3] = NULL;
-
-        /* Restore the signals.  */
-        (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
-        (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
-        (void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL);
-
-        /* Exec the shell.  */
-        (void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ);
-        _exit (127);
+	/* Child side.  */
+	CONST char *new_argv[4];
+	new_argv[0] = SHELL_NAME;
+	new_argv[1] = "-c";
+	new_argv[2] = line;
+	new_argv[3] = NULL;
+
+	/* Restore the signals.  */
+	(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
+	(void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
+	(void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL);
+
+	/* Exec the shell.  */
+	(void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ);
+	_exit (127);
     } else {
-        if (pid < (pid_t) 0) {
-            /* The fork failed.  */
-            DPRINTF(("4: errno=%d\n", errno));
-            status = -1;
-        } else {
-            /* Parent side.  */
+	if (pid < (pid_t) 0) {
+	    /* The fork failed.  */
+	    DPRINTF(("4: errno=%d\n", errno));
+	    status = -1;
+	} else {
+	    /* Parent side.  */
 #ifdef  NO_WAITPID
-            pid_t child;
-
-            do {
-                __BEGIN_INTERRUPTABLE__
-                child = __wait (&status);
-                __END_INTERRUPTABLE__
-                if (child < 0 && errno != EINTR) {
-                    DPRINTF(("5: errno=%d\n", errno));
-                    status = -1;
-                    break;
-                }
-            } while (child != pid);
+	    pid_t child;
+
+	    do {
+		__BEGIN_INTERRUPTABLE__
+		child = __wait (&status);
+		__END_INTERRUPTABLE__
+		if (child < 0 && errno != EINTR) {
+		    DPRINTF(("5: errno=%d\n", errno));
+		    status = -1;
+		    break;
+		}
+	    } while (child != pid);
 #else
-            pid_t child;
-
-            /* claus: the original did not care for EINTR here ... */
-            do {
-                __BEGIN_INTERRUPTABLE__
-                child = __waitpid (pid, &status, 0);
-                __END_INTERRUPTABLE__
-            } while ((child != pid) && (errno == EINTR));
-            if (child != pid) {
-                DPRINTF(("6: errno=%d\n", errno));
-                status = -1;
-            }
+	    pid_t child;
+
+	    /* claus: the original did not care for EINTR here ... */
+	    do {
+		__BEGIN_INTERRUPTABLE__
+		child = __waitpid (pid, &status, 0);
+		__END_INTERRUPTABLE__
+	    } while ((child != pid) && (errno == EINTR));
+	    if (child != pid) {
+		DPRINTF(("6: errno=%d\n", errno));
+		status = -1;
+	    }
 #endif /* NO_WAITPID */
-        }
+	}
     }
     save = errno;
     if ((__sigaction (SIGINT, &intr, (struct sigaction *) NULL)
      | __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL)
      | __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL)) != 0) {
-        if (errno == ENOSYS) {
-            errno = save;
-        } else {
-            status = -1;
-            DPRINTF(("7: errno=%d\n", errno));
-        }
+	if (errno == ENOSYS) {
+	    errno = save;
+	} else {
+	    status = -1;
+	    DPRINTF(("7: errno=%d\n", errno));
+	}
     }
 
     return status;
@@ -843,123 +843,123 @@
 static char *
 realpath(const char *path, char *resolved_path)
 {
-        char copy_path[MAXPATHLEN];
-        char link_path[MAXPATHLEN];
-        char *new_path, *max_path, *mallocedPath;
-        int readlinks = 0;
-        int n;
-
-        if (resolved_path == NULL) {
-            mallocedPath = resolved_path = malloc(MAXPATHLEN+1);
-        }
-        new_path = resolved_path;
-
-        /* Make a copy of the source path since we may need to modify it. */
-        strcpy(copy_path, path);
-        path = copy_path;
-        max_path = copy_path + MAXPATHLEN - 2;
-        /* If it's a relative pathname use getwd for starters. */
-        if (*path != '/') {
+	char copy_path[MAXPATHLEN];
+	char link_path[MAXPATHLEN];
+	char *new_path, *max_path, *mallocedPath;
+	int readlinks = 0;
+	int n;
+
+	if (resolved_path == NULL) {
+	    mallocedPath = resolved_path = malloc(MAXPATHLEN+1);
+	}
+	new_path = resolved_path;
+
+	/* Make a copy of the source path since we may need to modify it. */
+	strcpy(copy_path, path);
+	path = copy_path;
+	max_path = copy_path + MAXPATHLEN - 2;
+	/* If it's a relative pathname use getwd for starters. */
+	if (*path != '/') {
 #ifdef HAS_GETCWD
-                new_path = getcwd(new_path, MAXPATHLEN - 1);
+		new_path = getcwd(new_path, MAXPATHLEN - 1);
 #else
-                new_path = getwd(new_path);
-#endif
-                if (new_path == NULL) {
-                    if (mallocedPath) free(mallocedPath);
-                    return(NULL);
-                }
-
-                new_path += strlen(new_path);
-                if (new_path[-1] != '/')
-                        *new_path++ = '/';
-        }
-        else {
-                *new_path++ = '/';
-                path++;
-        }
-        /* Expand each slash-separated pathname component. */
-        while (*path != '\0') {
-                /* Ignore stray "/". */
-                if (*path == '/') {
-                        path++;
-                        continue;
-                }
-                if (*path == '.') {
-                        /* Ignore ".". */
-                        if (path[1] == '\0' || path[1] == '/') {
-                                path++;
-                                continue;
-                        }
-                        if (path[1] == '.') {
-                                if (path[2] == '\0' || path[2] == '/') {
-                                        path += 2;
-                                        /* Ignore ".." at root. */
-                                        if (new_path == resolved_path + 1)
-                                                continue;
-                                        /* Handle ".." by backing up. */
-                                        while ((--new_path)[-1] != '/')
-                                                ;
-                                        continue;
-                                }
-                        }
-                }
-                /* Safely copy the next pathname component. */
-                while (*path != '\0' && *path != '/') {
-                        if (path > max_path) {
-                            if (mallocedPath) free(mallocedPath);
-                            errno = ENAMETOOLONG;
-                            return NULL;
-                        }
-                        *new_path++ = *path++;
-                }
+		new_path = getwd(new_path);
+#endif
+		if (new_path == NULL) {
+		    if (mallocedPath) free(mallocedPath);
+		    return(NULL);
+		}
+
+		new_path += strlen(new_path);
+		if (new_path[-1] != '/')
+			*new_path++ = '/';
+	}
+	else {
+		*new_path++ = '/';
+		path++;
+	}
+	/* Expand each slash-separated pathname component. */
+	while (*path != '\0') {
+		/* Ignore stray "/". */
+		if (*path == '/') {
+			path++;
+			continue;
+		}
+		if (*path == '.') {
+			/* Ignore ".". */
+			if (path[1] == '\0' || path[1] == '/') {
+				path++;
+				continue;
+			}
+			if (path[1] == '.') {
+				if (path[2] == '\0' || path[2] == '/') {
+					path += 2;
+					/* Ignore ".." at root. */
+					if (new_path == resolved_path + 1)
+						continue;
+					/* Handle ".." by backing up. */
+					while ((--new_path)[-1] != '/')
+						;
+					continue;
+				}
+			}
+		}
+		/* Safely copy the next pathname component. */
+		while (*path != '\0' && *path != '/') {
+			if (path > max_path) {
+			    if (mallocedPath) free(mallocedPath);
+			    errno = ENAMETOOLONG;
+			    return NULL;
+			}
+			*new_path++ = *path++;
+		}
 #ifdef S_IFLNK
-                /* Protect against infinite loops. */
-                if (readlinks++ > MAX_READLINKS) {
-                    if (mallocedPath) free(mallocedPath);
-                    errno = ELOOP;
-                    return NULL;
-                }
-                /* See if latest pathname component is a symlink. */
-                *new_path = '\0';
-                n = readlink(resolved_path, link_path, MAXPATHLEN - 1);
-                if (n < 0) {
-                        /* EINVAL means the file exists but isn't a symlink. */
-                        if (errno != EINVAL) {
-                            if (mallocedPath) free(mallocedPath);
-                            return NULL;
-                        }
-                }
-                else {
-                        /* Note: readlink doesn't add the null byte. */
-                        link_path[n] = '\0';
-                        if (*link_path == '/')
-                                /* Start over for an absolute symlink. */
-                                new_path = resolved_path;
-                        else
-                                /* Otherwise back up over this component. */
-                                while (*(--new_path) != '/')
-                                        ;
-                        /* Safe sex check. */
-                        if (strlen(path) + n >= MAXPATHLEN) {
-                            if (mallocedPath) free(mallocedPath);
-                            errno = ENAMETOOLONG;
-                            return NULL;
-                        }
-                        /* Insert symlink contents into path. */
-                        strcat(link_path, path);
-                        strcpy(copy_path, link_path);
-                        path = copy_path;
-                }
+		/* Protect against infinite loops. */
+		if (readlinks++ > MAX_READLINKS) {
+		    if (mallocedPath) free(mallocedPath);
+		    errno = ELOOP;
+		    return NULL;
+		}
+		/* See if latest pathname component is a symlink. */
+		*new_path = '\0';
+		n = readlink(resolved_path, link_path, MAXPATHLEN - 1);
+		if (n < 0) {
+			/* EINVAL means the file exists but isn't a symlink. */
+			if (errno != EINVAL) {
+			    if (mallocedPath) free(mallocedPath);
+			    return NULL;
+			}
+		}
+		else {
+			/* Note: readlink doesn't add the null byte. */
+			link_path[n] = '\0';
+			if (*link_path == '/')
+				/* Start over for an absolute symlink. */
+				new_path = resolved_path;
+			else
+				/* Otherwise back up over this component. */
+				while (*(--new_path) != '/')
+					;
+			/* Safe sex check. */
+			if (strlen(path) + n >= MAXPATHLEN) {
+			    if (mallocedPath) free(mallocedPath);
+			    errno = ENAMETOOLONG;
+			    return NULL;
+			}
+			/* Insert symlink contents into path. */
+			strcat(link_path, path);
+			strcpy(copy_path, link_path);
+			path = copy_path;
+		}
 #endif /* S_IFLNK */
-                *new_path++ = '/';
-        }
-        /* Delete trailing slash but don't whomp a lone slash. */
-        if (new_path != resolved_path + 1 && new_path[-1] == '/')
-                new_path--;
-        /* Make sure it's null terminated. */
-        *new_path = '\0';
-        return resolved_path;
+		*new_path++ = '/';
+	}
+	/* Delete trailing slash but don't whomp a lone slash. */
+	if (new_path != resolved_path + 1 && new_path[-1] == '/')
+		new_path--;
+	/* Make sure it's null terminated. */
+	*new_path = '\0';
+	return resolved_path;
 }
 # define HAS_REALPATH
 #endif /* WANT_REALPATH && not HAS_REALPATH */
@@ -7544,15 +7544,15 @@
 
 getNetworkAddressInfo
     "return a Dictionary of network interface information.
-        key -> name of interface
-        value -> a Set of network address
-                information for the interface - a dictionaries containing the
-                information about the configuration of each interface in the system.
-                The dictionary keys are:
-                    #address
-                    #netmask
-                    #flags
-                    #destAddress"
+	key -> name of interface
+	value -> a Set of network address
+		information for the interface - a dictionaries containing the
+		information about the configuration of each interface in the system.
+		The dictionary keys are:
+		    #address
+		    #netmask
+		    #flags
+		    #destAddress"
 
     |returnArray addressArray nameArray noOfIf retDictionary error retIndex|
 
@@ -7572,8 +7572,8 @@
     OBJ t;
 
     if (getifaddrs(&ifap) < 0) {
-        error = __MKSTRING("getifaddrs() failed");
-        goto out;
+	error = __MKSTRING("getifaddrs() failed");
+	goto out;
     }
 
     for (ifaLoop = ifap; ifaLoop != 0; ifaLoop = ifaLoop->ifa_next) n_ifa++;
@@ -7582,52 +7582,52 @@
     returnArray = __ARRAY_NEW_INT(n_ifa*6);
 
     if (returnArray == nil) {
-        /* Creating a string wouldn't work here */
-        error = @symbol(allocationFailure);
-        goto bad;
+	/* Creating a string wouldn't work here */
+	error = @symbol(allocationFailure);
+	goto bad;
     }
 
     for (ifaLoop = ifap; ifaLoop != 0; ifaLoop = ifaLoop->ifa_next) {
-        int family, len;
-
-        if (ifaLoop->ifa_addr == 0)
-               continue;
-        family = ifaLoop->ifa_addr->sa_family;
-        switch (family) {
-        case AF_INET:
-            len = sizeof(struct sockaddr_in);
-            break;
-        case AF_INET6:
-            len = sizeof(struct sockaddr_in6);
-            break;
+	int family, len;
+
+	if (ifaLoop->ifa_addr == 0)
+	       continue;
+	family = ifaLoop->ifa_addr->sa_family;
+	switch (family) {
+	case AF_INET:
+	    len = sizeof(struct sockaddr_in);
+	    break;
+	case AF_INET6:
+	    len = sizeof(struct sockaddr_in6);
+	    break;
 #if 0
-        case AF_PACKET:
-            len = sizeof(sockaddr_ll);
-            break;
-#endif
-        default:
-            /* skip */
-            continue;
-        };
-        t = __MKSTRING(ifaLoop->ifa_name);
-        __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
-        t = __MKUINT(ifaLoop->ifa_flags);
-        __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
-        t = __MKBYTEARRAY((char *)ifaLoop->ifa_addr, len);
-        __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
-        if (ifaLoop->ifa_netmask != 0) {
-            t = __MKBYTEARRAY((char *)ifaLoop->ifa_netmask, len);
-            __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
-        }
-        retI++;
-        if ((ifaLoop->ifa_flags&IFF_POINTOPOINT) && ifaLoop->ifa_dstaddr != 0) {
-            t = __MKBYTEARRAY((char *)ifaLoop->ifa_dstaddr, len);
-            __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
-        } else if (retI++, ifaLoop->ifa_broadaddr != 0) {
-            t = __MKBYTEARRAY((char *)ifaLoop->ifa_broadaddr, len);
-            __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
-        }
-        retI++;
+	case AF_PACKET:
+	    len = sizeof(sockaddr_ll);
+	    break;
+#endif
+	default:
+	    /* skip */
+	    continue;
+	};
+	t = __MKSTRING(ifaLoop->ifa_name);
+	__arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
+	t = __MKUINT(ifaLoop->ifa_flags);
+	__arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
+	t = __MKBYTEARRAY((char *)ifaLoop->ifa_addr, len);
+	__arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
+	if (ifaLoop->ifa_netmask != 0) {
+	    t = __MKBYTEARRAY((char *)ifaLoop->ifa_netmask, len);
+	    __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
+	}
+	retI++;
+	if ((ifaLoop->ifa_flags&IFF_POINTOPOINT) && ifaLoop->ifa_dstaddr != 0) {
+	    t = __MKBYTEARRAY((char *)ifaLoop->ifa_dstaddr, len);
+	    __arrayVal(returnArray)[retI++] = t; __STORE(returnArray, t);
+	} else if (retI++, ifaLoop->ifa_broadaddr != 0) {
+	    t = __MKBYTEARRAY((char *)ifaLoop->ifa_broadaddr, len);
+	    __arrayVal(returnArray)[retI] = t; __STORE(returnArray, t);
+	}
+	retI++;
     }
 
 bad:
@@ -7640,40 +7640,40 @@
 %}.
 
     error notNil ifTrue:[
-        self primitiveFailed:error.
-        "return empty dictionary if proceeding from error"
-        ^  Dictionary new.
+	self primitiveFailed:error.
+	"return empty dictionary if proceeding from error"
+	^  Dictionary new.
     ].
 
     retDictionary := Dictionary new:noOfIf.
     retIndex := 1.
 
     1 to:noOfIf do:[:cnt|
-        |name addressBytes set dict|
-
-        name := returnArray at:retIndex.
-        addressBytes := returnArray at:retIndex+2.
-
-        addressBytes notNil ifTrue:[
-            set := retDictionary at:name ifAbsentPut:[Set new].
-            dict := Dictionary new:5.
-            dict at:#flags put:(returnArray at:retIndex+1).
-            dict at:#address put:(SocketAddress fromBytes:addressBytes).
-            addressBytes := returnArray at:retIndex+3.
-            addressBytes notNil ifTrue:[
-                dict at:#netMask put:(SocketAddress fromBytes:addressBytes).
-            ].
-            addressBytes := returnArray at:retIndex+4.
-            addressBytes notNil ifTrue:[
-                dict at:#destAddress put:(SocketAddress fromBytes:addressBytes).
-            ].
-            addressBytes := returnArray at:retIndex+5.
-            addressBytes notNil ifTrue:[
-                dict at:#broadcastAddress put:(SocketAddress fromBytes:addressBytes).
-            ].
-            set add:dict.
-        ].
-        retIndex := retIndex + 6.
+	|name addressBytes set dict|
+
+	name := returnArray at:retIndex.
+	addressBytes := returnArray at:retIndex+2.
+
+	addressBytes notNil ifTrue:[
+	    set := retDictionary at:name ifAbsentPut:[Set new].
+	    dict := Dictionary new:5.
+	    dict at:#flags put:(returnArray at:retIndex+1).
+	    dict at:#address put:(SocketAddress fromBytes:addressBytes).
+	    addressBytes := returnArray at:retIndex+3.
+	    addressBytes notNil ifTrue:[
+		dict at:#netMask put:(SocketAddress fromBytes:addressBytes).
+	    ].
+	    addressBytes := returnArray at:retIndex+4.
+	    addressBytes notNil ifTrue:[
+		dict at:#destAddress put:(SocketAddress fromBytes:addressBytes).
+	    ].
+	    addressBytes := returnArray at:retIndex+5.
+	    addressBytes notNil ifTrue:[
+		dict at:#broadcastAddress put:(SocketAddress fromBytes:addressBytes).
+	    ].
+	    set add:dict.
+	].
+	retIndex := retIndex + 6.
     ].
 
     ^ retDictionary
@@ -9081,11 +9081,11 @@
 
 randomBytesInto:bufferOrInteger
     "If bufferOrInteger is a String or a ByteArray,
-        fill a given buffer with random bytes from the RtlGenRandom function
-        and answer the buffer.
+	fill a given buffer with random bytes from the RtlGenRandom function
+	and answer the buffer.
 
      If bufferOrInteger is a SmallInteger,
-        return this many bytes (max 4) as a SmallInteger.
+	return this many bytes (max 4) as a SmallInteger.
 
      Return nil on error (may raise PrimitiveFailure, too).
 
@@ -9101,51 +9101,51 @@
     char *buffer;
 
     if (__isSmallInteger(bufferOrInteger) && (wanted = __smallIntegerVal(bufferOrInteger) <= 4)) {
-        int buf = 0;
-
-        do {
-            cnt = getrandom(&buf + gotSoFar, wanted - gotSoFar, 0);
-            if (cnt < 0) {
-                if (errno != EINTR && errno != EAGAIN)
-                    goto error;
-            } else {
-                gotSoFar = gotSoFar + cnt;
-            }
-        } while (gotSoFar < wanted);
-        RETURN(__mkSmallInteger(buf));
+	int buf = 0;
+
+	do {
+	    cnt = getrandom(&buf + gotSoFar, wanted - gotSoFar, 0);
+	    if (cnt < 0) {
+		if (errno != EINTR && errno != EAGAIN)
+		    goto error;
+	    } else {
+		gotSoFar = gotSoFar + cnt;
+	    }
+	} while (gotSoFar < wanted);
+	RETURN(__mkSmallInteger(buf));
     } else if (__isByteArray(bufferOrInteger)) {
-        wanted = __byteArraySize(bufferOrInteger);
-        buffer = __byteArrayVal(bufferOrInteger);
+	wanted = __byteArraySize(bufferOrInteger);
+	buffer = __byteArrayVal(bufferOrInteger);
     } else if (__isString(bufferOrInteger)) {
-        wanted = __stringSize(bufferOrInteger);
-        buffer = __stringVal(bufferOrInteger);
+	wanted = __stringSize(bufferOrInteger);
+	buffer = __stringVal(bufferOrInteger);
     } else
-        goto error;
+	goto error;
 
     do {
-        cnt = getrandom(buffer + gotSoFar, wanted - gotSoFar, 0);
-        if (cnt < 0) {
-            if (errno != EINTR && errno != EAGAIN)
-                goto error;
-            buffer = __isByteArray(bufferOrInteger) ?
-                        __byteArrayVal(bufferOrInteger) : __stringVal(bufferOrInteger);
-        } else {
-            gotSoFar = gotSoFar + cnt;
-        }
+	cnt = getrandom(buffer + gotSoFar, wanted - gotSoFar, 0);
+	if (cnt < 0) {
+	    if (errno != EINTR && errno != EAGAIN)
+		goto error;
+	    buffer = __isByteArray(bufferOrInteger) ?
+			__byteArrayVal(bufferOrInteger) : __stringVal(bufferOrInteger);
+	} else {
+	    gotSoFar = gotSoFar + cnt;
+	}
     } while (gotSoFar < wanted);
     RETURN(bufferOrInteger);
 
 # endif // GRND_RANDOM
-#endif  
+#endif
 error: ;
 %}.
 
     ^ self primitiveFailed.
 
     "
-        self randomBytesInto:2.
-        self randomBytesInto:(ByteArray new:16).
-        self randomBytesInto:(String new:16).
+	self randomBytesInto:2.
+	self randomBytesInto:(ByteArray new:16).
+	self randomBytesInto:(String new:16).
     "
 !
 
@@ -10073,6 +10073,17 @@
     uLow := micros // 1000000.
     uHigh := micros \\ 1000000.
 %{
+#ifdef HAS_USLEEP
+    INT secs, usecs;
+
+    secs = __intVal(uLow);
+    usecs = __intVal(uHigh);
+    if (secs > 0) {
+	sleep(secs);
+    }
+    usleep(usecs);
+    RETURN (true);
+#else
     struct timeval tv;
     fd_set dummy;
     int success;
@@ -10085,6 +10096,7 @@
     success = (0 == select(0, 0, 0, &dummy, &tv));
     close(s);
     RETURN (success ? true : false);
+#endif
 %}
 
     "