Index: uspace/lib/libc/include/adt/gcdlcm.h
===================================================================
--- uspace/lib/libc/include/adt/gcdlcm.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
+++ uspace/lib/libc/include/adt/gcdlcm.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2009 Martin Decky
+ * 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.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_GCDLCM_H_
+#define LIBC_GCDLCM_H_
+
+#include <sys/types.h>
+
+#define DECLARE_GCD(type, name) \
+	static inline type name(type a, type b) \
+	{ \
+		if (a == 0) \
+			return b; \
+		 \
+		while (b != 0) { \
+			if (a > b) \
+				a -= b; \
+			else \
+				b -= a; \
+		} \
+		 \
+		return a; \
+	}
+
+#define DECLARE_LCM(type, name, gcd) \
+	static inline type name(type a, type b) \
+	{ \
+		return (a * b) / gcd(a, b); \
+	}
+
+DECLARE_GCD(uint32_t, gcd32);
+DECLARE_GCD(uint64_t, gcd64);
+DECLARE_GCD(size_t, gcd);
+
+DECLARE_LCM(uint32_t, lcm32, gcd32);
+DECLARE_LCM(uint64_t, lcm64, gcd64);
+DECLARE_LCM(size_t, lcm, gcd);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/async.h
===================================================================
--- uspace/lib/libc/include/async.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/async.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -47,14 +47,15 @@
 extern atomic_t async_futex;
 
+extern int __async_init(void);
+extern ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs);
+
+static inline ipc_callid_t async_get_call(ipc_call_t *data)
+{
+	return async_get_call_timeout(data, 0);
+}
+
 static inline void async_manager(void)
 {
 	fibril_switch(FIBRIL_TO_MANAGER);
-}
-
-extern ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs);
-
-static inline ipc_callid_t async_get_call(ipc_call_t *data)
-{
-	return async_get_call_timeout(data, 0);
 }
 
@@ -95,5 +96,4 @@
 extern void async_create_manager(void);
 extern void async_destroy_manager(void);
-extern int _async_init(void);
 
 extern void async_set_client_connection(async_client_conn_t conn);
Index: uspace/lib/libc/include/bitops.h
===================================================================
--- uspace/lib/libc/include/bitops.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/bitops.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic	
+/** @addtogroup generic
  * @{
  */
@@ -43,8 +43,8 @@
  * If number is zero, it returns 0
  */
-static inline int fnzb32(uint32_t arg)
+static inline unsigned int fnzb32(uint32_t arg)
 {
-	int n = 0;
-
+	unsigned int n = 0;
+	
 	if (arg >> 16) {
 		arg >>= 16;
@@ -75,8 +75,8 @@
 }
 
-static inline int fnzb64(uint64_t arg)
+static inline unsigned int fnzb64(uint64_t arg)
 {
-	int n = 0;
-
+	unsigned int n = 0;
+	
 	if (arg >> 32) {
 		arg >>= 32;
@@ -84,8 +84,11 @@
 	}
 	
-	return n + fnzb32((uint32_t) arg);
+	return (n + fnzb32((uint32_t) arg));
 }
 
-#define fnzb(x) fnzb32(x)
+static inline unsigned int fnzb(size_t arg)
+{
+	return fnzb64(arg);
+}
 
 #endif
Index: uspace/lib/libc/include/errno.h
===================================================================
--- uspace/lib/libc/include/errno.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/errno.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -36,9 +36,10 @@
 #define LIBC_ERRNO_H_
 
-/* TODO: support threads/fibrils */
+#include <kernel/errno.h>
+#include <fibril.h>
+
 extern int _errno;
+
 #define errno _errno
-
-#include <kernel/errno.h>
 
 #define EMFILE        (-17)
Index: uspace/lib/libc/include/getopt.h
===================================================================
--- uspace/lib/libc/include/getopt.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/getopt.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -59,5 +59,5 @@
 
 /* HelenOS Port - These need to be exposed for legacy getopt() */
-extern char *optarg;
+extern const char *optarg;
 extern int optind, opterr, optopt;
 extern int optreset;
Index: uspace/lib/libc/include/macros.h
===================================================================
--- uspace/lib/libc/include/macros.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/macros.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -36,4 +36,7 @@
 #define LIBC_MACROS_H_
 
+#define min(a, b)  ((a) < (b) ? (a) : (b))
+#define max(a, b)  ((a) > (b) ? (a) : (b))
+
 #define SIZE2KB(size)  ((size) >> 10)
 #define SIZE2MB(size)  ((size) >> 20)
Index: uspace/lib/libc/include/mem.h
===================================================================
--- uspace/lib/libc/include/mem.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/mem.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -40,7 +40,7 @@
 #define bzero(ptr, len)  memset((ptr), 0, (len))
 
-extern void * memset(void *, int, size_t);
-extern void * memcpy(void *, const void *, size_t);
-extern void * memmove(void *, const void *, size_t);
+extern void *memset(void *, int, size_t);
+extern void *memcpy(void *, const void *, size_t);
+extern void *memmove(void *, const void *, size_t);
 
 extern int bcmp(const char *, const char *, size_t);
Index: uspace/lib/libc/include/stdio.h
===================================================================
--- uspace/lib/libc/include/stdio.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/stdio.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -38,4 +38,5 @@
 #include <sys/types.h>
 #include <stdarg.h>
+#include <string.h>
 #include <adt/list.h>
 
@@ -43,13 +44,13 @@
 
 /** Default size for stream I/O buffers */
-#define BUFSIZ 4096
+#define BUFSIZ  4096
 
 #define DEBUG(fmt, ...) \
-{ \
-	char buf[256]; \
-	int n = snprintf(buf, sizeof(buf), fmt, ##__VA_ARGS__); \
-	if (n > 0) \
-		(void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, str_size(buf)); \
-}
+	{ \
+		char _buf[256]; \
+		int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
+		if (_n > 0) \
+			(void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) _buf, str_size(_buf)); \
+	}
 
 #ifndef SEEK_SET
Index: uspace/lib/libc/include/stdlib.h
===================================================================
--- uspace/lib/libc/include/stdlib.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/stdlib.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -39,8 +39,8 @@
 #include <malloc.h>
 
-#define abort() _exit(1)
-#define exit(status)	_exit((status))
+#define abort()       _exit(1)
+#define exit(status)  _exit((status))
 
-#define RAND_MAX 714025
+#define RAND_MAX  714025
 
 extern long int random(void);
@@ -51,4 +51,5 @@
 	return random();
 }
+
 static inline void srand(unsigned int seed)
 {
Index: uspace/lib/libc/include/unistd.h
===================================================================
--- uspace/lib/libc/include/unistd.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/unistd.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -66,5 +66,4 @@
 
 extern void _exit(int status) __attribute__ ((noreturn));
-extern void *sbrk(ssize_t incr);
 extern int usleep(unsigned long usec);
 extern unsigned int sleep(unsigned int seconds);
Index: uspace/lib/libc/include/vfs/vfs.h
===================================================================
--- uspace/lib/libc/include/vfs/vfs.h	(revision ae75080a5ce2bb96f96900f6378c82b9e33dbd7c)
+++ uspace/lib/libc/include/vfs/vfs.h	(revision db24058f476a95ab9afb349b07aba2936c53ed79)
@@ -56,6 +56,6 @@
     unsigned int);
 
-extern void stdio_init(int filc, fdi_node_t *filv[]);
-extern void stdio_done(void);
+extern void __stdio_init(int filc, fdi_node_t *filv[]);
+extern void __stdio_done(void);
 
 extern int open_node(fdi_node_t *, int);
