Index: libc/Makefile
===================================================================
--- libc/Makefile	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ libc/Makefile	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -70,5 +70,7 @@
 	generic/libadt/list.o \
 	generic/libadt/hash_table.o \
-	generic/time.c
+	generic/time.c \
+	generic/err.c \
+	generic/stdlib.c
 
 ARCH_SOURCES += \
Index: libc/generic/err.c
===================================================================
--- libc/generic/err.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
+++ libc/generic/err.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void errx (int __status, __const char *__format, ...)
+{
+	printf("TODO...errx\n");
+	_exit(0);
+}
Index: libc/generic/stdlib.c
===================================================================
--- libc/generic/stdlib.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
+++ libc/generic/stdlib.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+static long glbl_seed = 1;
+
+long int random(void)
+{
+	return glbl_seed = ((1366*glbl_seed + 150889) % RAND_MAX);
+}
+
+void srandom(unsigned int seed)
+{
+	glbl_seed = seed;
+}
Index: libc/generic/string.c
===================================================================
--- libc/generic/string.c	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ libc/generic/string.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -247,2 +247,14 @@
 	return (sgn?-number:number);
 }
+
+char *strcpy(char *dest, const char *src)
+{
+	while (*(dest++) = *(src++))
+		;
+}
+
+char *strncpy(char *dest, const char *src, size_t n)
+{
+	while (*(dest++) = *(src++) && --n)
+		;
+}
Index: libc/include/async.h
===================================================================
--- libc/include/async.h	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ libc/include/async.h	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -1,2 +1,30 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #ifndef _libc_ASYNC_H_
 #define _libc_ASYNC_H_
Index: libc/include/err.h
===================================================================
--- libc/include/err.h	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
+++ libc/include/err.h	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _libc__ERR_H_
+#define _libc__ERR_H_
+
+extern void errx (int __status, __const char *__format, ...)
+        __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)));
+
+#endif
Index: libc/include/stdlib.h
===================================================================
--- libc/include/stdlib.h	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ libc/include/stdlib.h	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -36,3 +36,18 @@
 #define exit(status)	_exit((status))
 
+#define RAND_MAX 714025
+
+extern long int random(void);
+extern void srandom(unsigned int seed);
+
+static inline int rand(void)
+{
+	return random();
+}
+static inline void srand(unsigned int seed)
+{
+	srandom(seed);
+}
+
+
 #endif
Index: libc/include/string.h
===================================================================
--- libc/include/string.h	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ libc/include/string.h	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -40,7 +40,9 @@
 int strcmp(const char *, const char *);
 
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, size_t n);
+
 size_t strlen(const char *str);
 
-int strcmp(const char *str1, const char *str2);
 char *strchr(const char *str, int c);
 char *strrchr(const char *str, int c);
Index: tetris/screen.c
===================================================================
--- tetris/screen.c	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ tetris/screen.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -43,6 +43,6 @@
 
 #include <err.h>
-#include <setjmp.h>
-#include <signal.h>
+//#include <setjmp.h>
+//#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -205,29 +205,29 @@
 
 /* this foolery is needed to modify tty state `atomically' */
-static jmp_buf scr_onstop;
-
-static void
-stopset(int sig)
-{
-	sigset_t sigset;
-
-	(void) signal(sig, SIG_DFL);
-	(void) kill(getpid(), sig);
-	sigemptyset(&sigset);
-	sigaddset(&sigset, sig);
-	(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0);
-	longjmp(scr_onstop, 1);
-}
+//static jmp_buf scr_onstop;
+
+/* static void */
+/* stopset(int sig) */
+/* { */
+/* 	sigset_t sigset; */
+
+/* 	(void) signal(sig, SIG_DFL); */
+/* 	(void) kill(getpid(), sig); */
+/* 	sigemptyset(&sigset); */
+/* 	sigaddset(&sigset, sig); */
+/* 	(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
+/* 	longjmp(scr_onstop, 1); */
+/* } */
 
 static void
 scr_stop(int sig)
 {
-	sigset_t sigset;
+//	sigset_t sigset;
 
 	scr_end();
-	(void) kill(getpid(), sig);
-	sigemptyset(&sigset);
-	sigaddset(&sigset, sig);
-	(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0);
+/* 	(void) kill(getpid(), sig); */
+/* 	sigemptyset(&sigset); */
+/* 	sigaddset(&sigset, sig); */
+/* 	(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
 	scr_set();
 	scr_msg(key_msg, 1);
@@ -242,22 +242,22 @@
 	struct winsize ws;
 	struct termios newtt;
-	sigset_t sigset, osigset;
+//	sigset_t sigset, osigset;
 	void (*ttou)(int);
 
-	sigemptyset(&sigset);
-	sigaddset(&sigset, SIGTSTP);
-	sigaddset(&sigset, SIGTTOU);
-	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
-	if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN)
-		(void) signal(SIGTSTP, SIG_IGN);
-	if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN)
-		(void) signal(SIGTTOU, SIG_IGN);
-	/*
-	 * At last, we are ready to modify the tty state.  If
-	 * we stop while at it, stopset() above will longjmp back
-	 * to the setjmp here and we will start over.
-	 */
-	(void) setjmp(scr_onstop);
-	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
+/* 	sigemptyset(&sigset); */
+/* 	sigaddset(&sigset, SIGTSTP); */
+/* 	sigaddset(&sigset, SIGTTOU); */
+/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
+/* 	if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) */
+/* 		(void) signal(SIGTSTP, SIG_IGN); */
+/* 	if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) */
+/* 		(void) signal(SIGTTOU, SIG_IGN); */
+/* 	/\* */
+/* 	 * At last, we are ready to modify the tty state.  If */
+/* 	 * we stop while at it, stopset() above will longjmp back */
+/* 	 * to the setjmp here and we will start over. */
+/* 	 *\/ */
+/* 	(void) setjmp(scr_onstop); */
+/* 	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
 	Rows = 0, Cols = 0;
 	if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
@@ -284,5 +284,5 @@
 	if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
 		stop("tcsetattr() fails");
-	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
+/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
 	/*
@@ -292,11 +292,11 @@
 	if (TIstr)
 		putstr(TIstr);	/* termcap(5) says this is not padded */
-	if (tstp != SIG_IGN)
-		(void) signal(SIGTSTP, scr_stop);
-	if (ttou != SIG_IGN)
-		(void) signal(SIGTTOU, ttou);
+/* 	if (tstp != SIG_IGN) */
+/* 		(void) signal(SIGTSTP, scr_stop); */
+/* 	if (ttou != SIG_IGN) */
+/* 		(void) signal(SIGTTOU, ttou); */
 
 	isset = 1;
-	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
+//	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
 	scr_clear();
 }
@@ -308,10 +308,10 @@
 scr_end(void)
 {
-	sigset_t sigset, osigset;
-
-	sigemptyset(&sigset);
-	sigaddset(&sigset, SIGTSTP);
-	sigaddset(&sigset, SIGTTOU);
-	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
+//	sigset_t sigset, osigset;
+
+/* 	sigemptyset(&sigset); */
+/* 	sigaddset(&sigset, SIGTSTP); */
+/* 	sigaddset(&sigset, SIGTTOU); */
+/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 	/* move cursor to last line */
 	if (LLstr)
@@ -322,10 +322,10 @@
 	if (TEstr)
 		putstr(TEstr);	/* termcap(5) says this is not padded */
-	(void) fflush(stdout);
+//	(void) fflush(stdout);
 	(void) tcsetattr(0, TCSADRAIN, &oldtt);
 	isset = 0;
 	/* restore signals */
-	(void) signal(SIGTSTP, tstp);
-	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
+/* 	(void) signal(SIGTSTP, tstp); */
+/* 	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
 }
 
@@ -366,10 +366,10 @@
 	regcell so, cur_so = 0;
 	int i, ccol, j;
-	sigset_t sigset, osigset;
+//	sigset_t sigset, osigset;
 	static const struct shape *lastshape;
 
-	sigemptyset(&sigset);
-	sigaddset(&sigset, SIGTSTP);
-	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
+/* 	sigemptyset(&sigset); */
+/* 	sigaddset(&sigset, SIGTSTP); */
+/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
 	/* always leave cursor after last displayed point */
@@ -466,6 +466,6 @@
 	if (cur_so)
 		putpad(SEstr);
-	(void) fflush(stdout);
-	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
+/* 	(void) fflush(stdout); */
+/* 	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
 }
 
Index: tetris/tetris.c
===================================================================
--- tetris/tetris.c	(revision 1c20e22039efe5771c032256df826a90532bb308)
+++ tetris/tetris.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
@@ -46,5 +46,5 @@
  */
 
-#include <sys/param.h>
+//#include <sys/param.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -152,5 +152,12 @@
 	return (tmp);
 }
-	
+
+static void srandomdev(void)
+{
+	struct timeval tv;
+
+	gettimeofday(&tv, NULL);
+	srandom(tv.tv_sec + tv.tv_usec / 100000);
+}
 
 int
@@ -217,5 +224,5 @@
 		}
 		if (keys[i] == ' ')
-			strlcpy(key_write[i], "<space>", sizeof key_write[i]);
+			strncpy(key_write[i], "<space>", sizeof key_write[i]);
 		else {
 			key_write[i][0] = keys[i];
@@ -292,5 +299,5 @@
 				scr_msg(key_msg, 0);
 				scr_msg(msg, 1);
-				(void) fflush(stdout);
+//				(void) fflush(stdout);
 			} while (rwait((struct timeval *)NULL) == -1);
 			scr_msg(msg, 0);
