Index: trunk/src/emx/src/include/libc_private.h
===================================================================
--- trunk/src/emx/src/include/libc_private.h	(revision 928)
+++ trunk/src/emx/src/include/libc_private.h	(revision 929)
@@ -1,1 +1,3 @@
 /* placeholder */
+extern const char *__progname;
+
Index: trunk/src/emx/src/include/namespace.h
===================================================================
--- trunk/src/emx/src/include/namespace.h	(revision 928)
+++ trunk/src/emx/src/include/namespace.h	(revision 929)
@@ -6,4 +6,11 @@
 #define _NAMESPACE_H_
 #include "libc-alias.h"
+/* kill these as they're handles by alias/aliasbsdfuncs.awk */
+#define __weak_reference(a,b)
+#define __make_alias(a,b)
+
+#define err _err
+#define warn _warn
+#define getprogname _getprogname
 #endif
 
Index: trunk/src/emx/src/include/un-namespace.h
===================================================================
--- trunk/src/emx/src/include/un-namespace.h	(revision 928)
+++ trunk/src/emx/src/include/un-namespace.h	(revision 929)
@@ -6,4 +6,9 @@
 #ifndef _UN_NAMESPACE_H_
 #define _UN_NAMESPACE_H_
+
+#undef err
+#undef warn
+#undef getprogname
+
 #endif
 
Index: trunk/src/emx/src/lib/alias/alias.smak
===================================================================
--- trunk/src/emx/src/lib/alias/alias.smak	(revision 928)
+++ trunk/src/emx/src/lib/alias/alias.smak	(revision 929)
@@ -15,4 +15,11 @@
 ALIAS.FUNCS = $(shell gawk -f src/lib/alias/aliasfuncs.awk $.)
 ALIAS._FUNCS = $(shell gawk -f src/lib/alias/aliasfuncs.awk $. _)
+# list of alias pairs:
+ALIAS.ALIASES = $(shell gawk -f src/lib/alias/aliasbsdfuncs.awk $.) \
+	_strcasecmp 	__std_stricmp \
+	_strncasecmp 	__std_strnicmp \
+	_itoa			__std_ltoa \
+	__itoa			__std_ltoa \
+	__Exit			__exit
 
 DO.STDALIAS = \
@@ -30,9 +37,4 @@
 	$(call RM,$.aliases/*.o)
 	$(call RM,$.aliases/*.s)
-	@$(call DO.STDALIAS,_strcasecmp,__std_stricmp,$.aliases/strcasecmp.o)
-	@$(call DO.STDALIAS,_strncasecmp,__std_strnicmp,$.aliases/strncasecmp.o)
-	@$(call DO.STDALIAS,_itoa,__std_ltoa,$.aliases/itoa.o)
-	@$(call DO.STDALIAS,__itoa,__std_ltoa,$.aliases/_itoa.o)
-	@$(call DO.STDALIAS,__Exit,__exit,$.aliases/__Exit.o)
 	for i in $(ALIAS.FUNCS); do \
 		echo "Aliasing _$$i to __std_$$i ..."; \
@@ -49,4 +51,17 @@
 		fi \
 	done
+	fun2=; \
+	for fun in $(ALIAS.ALIASES); do \
+	    if test -z "$$fun2"; then \
+			fun2=$$fun; \
+		else \
+			echo "Aliasing $$fun to $$fun2 ..."; \
+			echo ".stabs \"_$$fun\",11,0,0,0;.stabs \"_$$fun2\",1,0,0,0;" > $.aliases/_$$fun.s; \
+			if as -o $.aliases/_$$fun.o $.aliases/_$$fun.s; then \
+			else false; \
+			fi \
+			fun2=; \
+		fi \	
+	done
 	$(AR) $(ARFLAGS) $@ $.aliases/*.o
 
Index: trunk/src/emx/src/lib/alias/aliasbsdfuncs.awk
===================================================================
--- trunk/src/emx/src/lib/alias/aliasbsdfuncs.awk	(revision 929)
+++ trunk/src/emx/src/lib/alias/aliasbsdfuncs.awk	(revision 929)
@@ -0,0 +1,32 @@
+#
+# This simple script looks through libc-std.h file and collects either all
+# bsd aliases.
+#
+# ARG1: path to libc-std.h
+# ARG2: "" or "_".
+#
+
+BEGIN {
+  fn = ARGV [1]"libc-std.h";
+  want_underscore = (ARGV [2] == "_");
+
+  while ((getline < fn) > 0)
+    if (match($0, "_BSDALIAS\\(") != 0)
+    {
+       blank = match($0, " ");
+       fun = substr($0, blank + 1, 255);
+       blank = match(fun, " ");
+       if (blank > 0)
+         fun = substr(fun, 1, blank - 1);
+
+       par = match($0, "\\(");
+       fun2 = substr($0, par+1, 255);
+       par = match(fun2, "\\)");
+       if (par > 0)
+         fun2 = substr(fun2, 1, par - 1);
+
+       print fun " " fun2 " "
+    }
+
+  exit;
+}
Index: trunk/src/emx/src/lib/mkstd.awk
===================================================================
--- trunk/src/emx/src/lib/mkstd.awk	(revision 928)
+++ trunk/src/emx/src/lib/mkstd.awk	(revision 929)
@@ -17,5 +17,5 @@
   print "#ifndef __LIBC_STD_H__"
   print "#define __LIBC_STD_H__\n"
-
+  print ""
   for (fun in std_fun)
   {
@@ -23,4 +23,12 @@
     if (!(fun in std_fun2))
       print "/*#define _" fun " _STD(" fun ")*/"
+  }
+
+  print ""
+  print "/* BSD aliasing */"
+  for (fun in bsd_aliases)
+  {
+    fun2 = bsd_aliases[fun];
+    print "/*#define " fun2 " _BSDALIAS(" fun ")*/"
   }
 
@@ -35,4 +43,25 @@
   }
 }
+
+/__weak_reference\( *[_0-9A-Za-z]+ *, *[_0-9A-Za-z]+ *\)/{
+  while (match($0, "__weak_reference\\( *[_0-9A-Za-z ]+ *, *[_0-9A-Za-z ]+ *\\)"))
+  {
+    fun1 = gensub("__weak_reference\\( *([_0-9A-Za-z]+) *, *[_0-9A-Za-z]+ *\\).*", "\\1", "", substr($0,RSTART,RLENGTH));
+    fun2 = gensub("__weak_reference\\( *[_0-9A-Za-z]+ *, *([_0-9A-Za-z]+) *\\).*", "\\1", "", substr($0,RSTART,RLENGTH));
+    bsd_aliases[fun1] = fun2;
+    $0 = substr($0, 1, RSTART-1) substr($0, RSTART+RLENGTH);
+  }
+}
+
+/__weak_alias\( *[_0-9A-Za-z]+ *, *[_0-9A-Za-z]+ *\)/{
+  while (match($0, "__weak_alias\\( *[_0-9A-Za-z ]+ *, *[_0-9A-Za-z ]+ *\\)"))
+  {
+    fun1 = gensub("__weak_alias\\( *([_0-9A-Za-z]+) *, *[_0-9A-Za-z]+ *\\).*", "\\1", "", substr($0,RSTART,RLENGTH));
+    fun2 = gensub("__weak_alias\\( *[_0-9A-Za-z]+ *, *([_0-9A-Za-z]+) *\\).*", "\\1", "", substr($0,RSTART,RLENGTH));
+    bsd_aliases[fun1] = fun2;
+    $0 = substr($0, 1, RSTART-1) substr($0, RSTART+RLENGTH);
+  }
+}
+
 
 /MATHSUFFIX1\( *[_0-9A-Za-z]+ *\)/{
