Index: uspace/lib/c/generic/stats.c
===================================================================
--- uspace/lib/c/generic/stats.c	(revision 9696b01a9508667ab9b8592345fd6523e0ce3e76)
+++ uspace/lib/c/generic/stats.c	(revision 3da166f05b0e0513fe18f82b34f75ef99bef955a)
@@ -291,18 +291,4 @@
 }
 
-/** Get system uptime
- *
- * @return System uptime (in seconds).
- *
- */
-sysarg_t stats_get_uptime(void)
-{
-	sysarg_t uptime;
-	if (sysinfo_get_value("system.uptime", &uptime) != EOK)
-		uptime = 0;
-	
-	return uptime;
-}
-
 /** Print load fixed-point value
  *
Index: uspace/lib/c/generic/time.c
===================================================================
--- uspace/lib/c/generic/time.c	(revision 9696b01a9508667ab9b8592345fd6523e0ce3e76)
+++ uspace/lib/c/generic/time.c	(revision 3da166f05b0e0513fe18f82b34f75ef99bef955a)
@@ -54,5 +54,12 @@
 #include <malloc.h>
 
-#define ASCTIME_BUF_LEN 26
+#define ASCTIME_BUF_LEN  26
+
+#define HOURS_PER_DAY  24
+#define MINS_PER_HOUR  60
+#define SECS_PER_MIN   60
+#define MINS_PER_DAY   (MINS_PER_HOUR * HOURS_PER_DAY)
+#define SECS_PER_HOUR  (SECS_PER_MIN * MINS_PER_HOUR)
+#define SECS_PER_DAY   (SECS_PER_HOUR * HOURS_PER_DAY)
 
 /** Pointer to kernel shared variables with time */
@@ -63,113 +70,126 @@
 } *ktime = NULL;
 
-/* Helper functions ***********************************************************/
-
-#define HOURS_PER_DAY (24)
-#define MINS_PER_HOUR (60)
-#define SECS_PER_MIN (60)
-#define MINS_PER_DAY (MINS_PER_HOUR * HOURS_PER_DAY)
-#define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR)
-#define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY)
-
-/**
- * Checks whether the year is a leap year.
+static async_sess_t *clock_conn = NULL;
+
+/** Check whether the year is a leap year.
  *
  * @param year Year since 1900 (e.g. for 1970, the value is 70).
+ *
  * @return true if year is a leap year, false otherwise
- */
-static bool _is_leap_year(time_t year)
+ *
+ */
+static bool is_leap_year(time_t year)
 {
 	year += 1900;
-
+	
 	if (year % 400 == 0)
 		return true;
+	
 	if (year % 100 == 0)
 		return false;
+	
 	if (year % 4 == 0)
 		return true;
+	
 	return false;
 }
 
-/**
- * Returns how many days there are in the given month of the given year.
+/** How many days there are in the given month
+ *
+ * Return how many days there are in the given month of the given year.
  * Note that year is only taken into account if month is February.
  *
  * @param year Year since 1900 (can be negative).
- * @param mon Month of the year. 0 for January, 11 for December.
+ * @param mon  Month of the year. 0 for January, 11 for December.
+ *
  * @return Number of days in the specified month.
- */
-static int _days_in_month(time_t year, time_t mon)
-{
-	assert(mon >= 0 && mon <= 11);
-
-	static int month_days[] =
-		{ 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-
+ *
+ */
+static int days_in_month(time_t year, time_t mon)
+{
+	assert(mon >= 0);
+	assert(mon <= 11);
+	
+	static int month_days[] = {
+		31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+	};
+	
 	if (mon == 1) {
+		/* February */
 		year += 1900;
-		/* february */
-		return _is_leap_year(year) ? 29 : 28;
-	} else {
-		return month_days[mon];
-	}
-}
-
-/**
- * For specified year, month and day of month, returns which day of that year
+		return is_leap_year(year) ? 29 : 28;
+	}
+	
+	return month_days[mon];
+}
+
+/** Which day of that year it is.
+ *
+ * For specified year, month and day of month, return which day of that year
  * it is.
  *
  * For example, given date 2011-01-03, the corresponding expression is:
- *     _day_of_year(111, 0, 3) == 2
+ * day_of_year(111, 0, 3) == 2
  *
  * @param year Year (year 1900 = 0, can be negative).
- * @param mon Month (January = 0).
+ * @param mon  Month (January = 0).
  * @param mday Day of month (First day is 1).
+ *
  * @return Day of year (First day is 0).
- */
-static int _day_of_year(time_t year, time_t mon, time_t mday)
-{
-	static int mdays[] =
-	    { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
-	static int leap_mdays[] =
-	    { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
-
-	return (_is_leap_year(year) ? leap_mdays[mon] : mdays[mon]) + mday - 1;
-}
-
-/**
- * Integer division that rounds to negative infinity.
- * Used by some functions in this file.
+ *
+ */
+static int day_of_year(time_t year, time_t mon, time_t mday)
+{
+	static int mdays[] = {
+		0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+	};
+	
+	static int leap_mdays[] = {
+		0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
+	};
+	
+	return (is_leap_year(year) ? leap_mdays[mon] : mdays[mon]) + mday - 1;
+}
+
+/** Integer division that rounds to negative infinity.
+ *
+ * Used by some functions in this module.
  *
  * @param op1 Dividend.
  * @param op2 Divisor.
+ *
  * @return Rounded quotient.
- */
-static time_t _floor_div(time_t op1, time_t op2)
-{
-	if (op1 >= 0 || op1 % op2 == 0) {
+ *
+ */
+static time_t floor_div(time_t op1, time_t op2)
+{
+	if ((op1 >= 0) || (op1 % op2 == 0))
 		return op1 / op2;
-	} else {
-		return op1 / op2 - 1;
-	}
-}
-
-/**
- * Modulo that rounds to negative infinity.
- * Used by some functions in this file.
+	
+	return op1 / op2 - 1;
+}
+
+/** Modulo that rounds to negative infinity.
+ *
+ * Used by some functions in this module.
  *
  * @param op1 Dividend.
  * @param op2 Divisor.
+ *
  * @return Remainder.
- */
-static time_t _floor_mod(time_t op1, time_t op2)
-{
-	int div = _floor_div(op1, op2);
-
-	/* (a / b) * b + a % b == a */
-	/* thus, a % b == a - (a / b) * b */
-
-	int result = op1 - div * op2;
-	
-	/* Some paranoid checking to ensure I didn't make a mistake here. */
+ *
+ */
+static time_t floor_mod(time_t op1, time_t op2)
+{
+	time_t div = floor_div(op1, op2);
+	
+	/*
+	 * (a / b) * b + a % b == a
+	 * Thus: a % b == a - (a / b) * b
+	 */
+	
+	time_t result = op1 - div * op2;
+	
+	/* Some paranoid checking to ensure there is mistake here. */
 	assert(result >= 0);
 	assert(result < op2);
@@ -179,59 +199,67 @@
 }
 
-/**
- * Number of days since the Epoch.
+/** Number of days since the Epoch.
+ *
  * Epoch is 1970-01-01, which is also equal to day 0.
  *
  * @param year Year (year 1900 = 0, may be negative).
- * @param mon Month (January = 0).
+ * @param mon  Month (January = 0).
  * @param mday Day of month (first day = 1).
+ *
  * @return Number of days since the Epoch.
- */
-static time_t _days_since_epoch(time_t year, time_t mon, time_t mday)
-{
-	return (year - 70) * 365 + _floor_div(year - 69, 4) -
-	    _floor_div(year - 1, 100) + _floor_div(year + 299, 400) +
-	    _day_of_year(year, mon, mday);
-}
-
-/**
- * Seconds since the Epoch. see also _days_since_epoch().
- * 
+ *
+ */
+static time_t days_since_epoch(time_t year, time_t mon, time_t mday)
+{
+	return (year - 70) * 365 + floor_div(year - 69, 4) -
+	    floor_div(year - 1, 100) + floor_div(year + 299, 400) +
+	    day_of_year(year, mon, mday);
+}
+
+/** Seconds since the Epoch.
+ *
+ * See also days_since_epoch().
+ *
  * @param tm Normalized broken-down time.
+ *
  * @return Number of seconds since the epoch, not counting leap seconds.
- */
-static time_t _secs_since_epoch(const struct tm *tm)
-{
-	return _days_since_epoch(tm->tm_year, tm->tm_mon, tm->tm_mday) *
+ *
+ */
+static time_t secs_since_epoch(const struct tm *tm)
+{
+	return days_since_epoch(tm->tm_year, tm->tm_mon, tm->tm_mday) *
 	    SECS_PER_DAY + tm->tm_hour * SECS_PER_HOUR +
 	    tm->tm_min * SECS_PER_MIN + tm->tm_sec;
 }
 
-/**
- * Which day of week the specified date is.
- * 
+/** Which day of week the specified date is.
+ *
  * @param year Year (year 1900 = 0).
- * @param mon Month (January = 0).
+ * @param mon  Month (January = 0).
  * @param mday Day of month (first = 1).
+ *
  * @return Day of week (Sunday = 0).
- */
-static int _day_of_week(time_t year, time_t mon, time_t mday)
+ *
+ */
+static time_t day_of_week(time_t year, time_t mon, time_t mday)
 {
 	/* 1970-01-01 is Thursday */
-	return _floor_mod((_days_since_epoch(year, mon, mday) + 4), 7);
-}
-
-/**
- * Normalizes the broken-down time and optionally adds specified amount of
- * seconds.
- * 
- * @param tm Broken-down time to normalize.
+	return floor_mod(days_since_epoch(year, mon, mday) + 4, 7);
+}
+
+/** Normalize the broken-down time.
+ *
+ * Optionally add specified amount of seconds.
+ *
+ * @param tm      Broken-down time to normalize.
  * @param sec_add Seconds to add.
+ *
  * @return 0 on success, -1 on overflow
- */
-static int _normalize_time(struct tm *tm, time_t sec_add)
+ *
+ */
+static int normalize_time(struct tm *tm, time_t sec_add)
 {
 	// TODO: DST correction
-
+	
 	/* Set initial values. */
 	time_t sec = tm->tm_sec + sec_add;
@@ -241,22 +269,22 @@
 	time_t mon = tm->tm_mon;
 	time_t year = tm->tm_year;
-
+	
 	/* Adjust time. */
-	min += _floor_div(sec, SECS_PER_MIN);
-	sec = _floor_mod(sec, SECS_PER_MIN);
-	hour += _floor_div(min, MINS_PER_HOUR);
-	min = _floor_mod(min, MINS_PER_HOUR);
-	day += _floor_div(hour, HOURS_PER_DAY);
-	hour = _floor_mod(hour, HOURS_PER_DAY);
-
+	min += floor_div(sec, SECS_PER_MIN);
+	sec = floor_mod(sec, SECS_PER_MIN);
+	hour += floor_div(min, MINS_PER_HOUR);
+	min = floor_mod(min, MINS_PER_HOUR);
+	day += floor_div(hour, HOURS_PER_DAY);
+	hour = floor_mod(hour, HOURS_PER_DAY);
+	
 	/* Adjust month. */
-	year += _floor_div(mon, 12);
-	mon = _floor_mod(mon, 12);
-
+	year += floor_div(mon, 12);
+	mon = floor_mod(mon, 12);
+	
 	/* Now the difficult part - days of month. */
 	
 	/* First, deal with whole cycles of 400 years = 146097 days. */
-	year += _floor_div(day, 146097) * 400;
-	day = _floor_mod(day, 146097);
+	year += floor_div(day, 146097) * 400;
+	day = floor_mod(day, 146097);
 	
 	/* Then, go in one year steps. */
@@ -264,5 +292,5 @@
 		/* January and February. */
 		while (day > 365) {
-			day -= _is_leap_year(year) ? 366 : 365;
+			day -= is_leap_year(year) ? 366 : 365;
 			year++;
 		}
@@ -270,5 +298,5 @@
 		/* Rest of the year. */
 		while (day > 365) {
-			day -= _is_leap_year(year + 1) ? 366 : 365;
+			day -= is_leap_year(year + 1) ? 366 : 365;
 			year++;
 		}
@@ -276,7 +304,8 @@
 	
 	/* Finally, finish it off month per month. */
-	while (day >= _days_in_month(year, mon)) {
-		day -= _days_in_month(year, mon);
+	while (day >= days_in_month(year, mon)) {
+		day -= days_in_month(year, mon);
 		mon++;
+		
 		if (mon >= 12) {
 			mon -= 12;
@@ -286,6 +315,6 @@
 	
 	/* Calculate the remaining two fields. */
-	tm->tm_yday = _day_of_year(year, mon, day + 1);
-	tm->tm_wday = _day_of_week(year, mon, day + 1);
+	tm->tm_yday = day_of_year(year, mon, day + 1);
+	tm->tm_wday = day_of_week(year, mon, day + 1);
 	
 	/* And put the values back to the struct. */
@@ -296,7 +325,7 @@
 	tm->tm_mon = (int) mon;
 	
-	/* Casts to work around libc brain-damage. */
-	if (year > ((int)INT_MAX) || year < ((int)INT_MIN)) {
-		tm->tm_year = (year < 0) ? ((int)INT_MIN) : ((int)INT_MAX);
+	/* Casts to work around POSIX brain-damage. */
+	if (year > ((int) INT_MAX) || year < ((int) INT_MIN)) {
+		tm->tm_year = (year < 0) ? ((int) INT_MIN) : ((int) INT_MAX);
 		return -1;
 	}
@@ -306,93 +335,110 @@
 }
 
-/**
- * Which day the week-based year starts on, relative to the first calendar day.
- * E.g. if the year starts on December 31st, the return value is -1.
+/** Which day the week-based year starts on.
+ *
+ * Relative to the first calendar day. E.g. if the year starts
+ * on December 31st, the return value is -1.
  *
  * @param Year since 1900.
+ *
  * @return Offset of week-based year relative to calendar year.
- */
-static int _wbyear_offset(int year)
-{
-	int start_wday = _day_of_week(year, 0, 1);
-	return _floor_mod(4 - start_wday, 7) - 3;
-}
-
-/**
- * Returns week-based year of the specified time.
+ *
+ */
+static int wbyear_offset(int year)
+{
+	int start_wday = day_of_week(year, 0, 1);
+	
+	return floor_mod(4 - start_wday, 7) - 3;
+}
+
+/** Week-based year of the specified time.
  *
  * @param tm Normalized broken-down time.
+ *
  * @return Week-based year.
- */
-static int _wbyear(const struct tm *tm)
-{
-	int day = tm->tm_yday - _wbyear_offset(tm->tm_year);
+ *
+ */
+static int wbyear(const struct tm *tm)
+{
+	int day = tm->tm_yday - wbyear_offset(tm->tm_year);
+	
 	if (day < 0) {
 		/* Last week of previous year. */
 		return tm->tm_year - 1;
 	}
-	if (day > 364 + _is_leap_year(tm->tm_year)) {
+	
+	if (day > 364 + is_leap_year(tm->tm_year)) {
 		/* First week of next year. */
 		return tm->tm_year + 1;
 	}
+	
 	/* All the other days are in the calendar year. */
 	return tm->tm_year;
 }
 
-/**
- * Week number of the year, assuming weeks start on sunday.
+/** Week number of the year (assuming weeks start on Sunday).
+ *
  * The first Sunday of January is the first day of week 1;
  * days in the new year before this are in week 0.
  *
  * @param tm Normalized broken-down time.
+ *
  * @return The week number (0 - 53).
- */
-static int _sun_week_number(const struct tm *tm)
-{
-	int first_day = (7 - _day_of_week(tm->tm_year, 0, 1)) % 7;
+ *
+ */
+static int sun_week_number(const struct tm *tm)
+{
+	int first_day = (7 - day_of_week(tm->tm_year, 0, 1)) % 7;
+	
 	return (tm->tm_yday - first_day + 7) / 7;
 }
 
-/**
- * Week number of the year, assuming weeks start on monday.
- * If the week containing January 1st has four or more days in the new year,
- * then it is considered week 1. Otherwise, it is the last week of the previous
- * year, and the next week is week 1. Both January 4th and the first Thursday
+/** Week number of the year (assuming weeks start on Monday).
+ *
+ * If the week containing January 1st has four or more days
+ * in the new year, then it is considered week 1. Otherwise,
+ * it is the last week of the previous year, and the next week
+ * is week 1. Both January 4th and the first Thursday
  * of January are always in week 1.
  *
  * @param tm Normalized broken-down time.
+ *
  * @return The week number (1 - 53).
- */
-static int _iso_week_number(const struct tm *tm)
-{
-	int day = tm->tm_yday - _wbyear_offset(tm->tm_year);
+ *
+ */
+static int iso_week_number(const struct tm *tm)
+{
+	int day = tm->tm_yday - wbyear_offset(tm->tm_year);
+	
 	if (day < 0) {
 		/* Last week of previous year. */
 		return 53;
 	}
-	if (day > 364 + _is_leap_year(tm->tm_year)) {
+	
+	if (day > 364 + is_leap_year(tm->tm_year)) {
 		/* First week of next year. */
 		return 1;
 	}
+	
 	/* All the other days give correct answer. */
 	return (day / 7 + 1);
 }
 
-/**
- * Week number of the year, assuming weeks start on monday.
+/** Week number of the year (assuming weeks start on Monday).
+ *
  * The first Monday of January is the first day of week 1;
- * days in the new year before this are in week 0. 
+ * days in the new year before this are in week 0.
  *
  * @param tm Normalized broken-down time.
+ *
  * @return The week number (0 - 53).
- */
-static int _mon_week_number(const struct tm *tm)
-{
-	int first_day = (1 - _day_of_week(tm->tm_year, 0, 1)) % 7;
+ *
+ */
+static int mon_week_number(const struct tm *tm)
+{
+	int first_day = (1 - day_of_week(tm->tm_year, 0, 1)) % 7;
+	
 	return (tm->tm_yday - first_day + 7) / 7;
 }
-
-/******************************************************************************/
-
 
 /** Add microseconds to given timeval.
@@ -468,5 +514,5 @@
 }
 
-/** Get time of day
+/** Get time of day.
  *
  * The time variables are memory mapped (read-only) from kernel which
@@ -482,68 +528,59 @@
  *
  */
-int gettimeofday(struct timeval *tv, struct timezone *tz)
-{
-	int rc;
-	struct tm t;
-	category_id_t cat_id;
-	size_t svc_cnt;
-	service_id_t *svc_ids = NULL;
-	service_id_t svc_id;
-	char *svc_name = NULL;
-
-	static async_sess_t *clock_conn = NULL;
-
+void gettimeofday(struct timeval *tv, struct timezone *tz)
+{
 	if (tz) {
 		tz->tz_minuteswest = 0;
 		tz->tz_dsttime = DST_NONE;
 	}
-
+	
 	if (clock_conn == NULL) {
-		rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING);
+		category_id_t cat_id;
+		int rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING);
 		if (rc != EOK)
-			goto ret_uptime;
-
+			goto fallback;
+		
+		service_id_t *svc_ids;
+		size_t svc_cnt;
 		rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt);
 		if (rc != EOK)
-			goto ret_uptime;
-
+			goto fallback;
+		
 		if (svc_cnt == 0)
-			goto ret_uptime;
-
+			goto fallback;
+		
+		char *svc_name;
 		rc = loc_service_get_name(svc_ids[0], &svc_name);
+		free(svc_ids);
 		if (rc != EOK)
-			goto ret_uptime;
-
+			goto fallback;
+		
+		service_id_t svc_id;
 		rc = loc_service_get_id(svc_name, &svc_id, 0);
+		free(svc_name);
 		if (rc != EOK)
-			goto ret_uptime;
-
+			goto fallback;
+		
 		clock_conn = loc_service_connect(EXCHANGE_SERIALIZE,
 		    svc_id, IPC_FLAG_BLOCKING);
 		if (!clock_conn)
-			goto ret_uptime;
-	}
-
-	rc = clock_dev_time_get(clock_conn, &t);
+			goto fallback;
+	}
+	
+	struct tm time;
+	int rc = clock_dev_time_get(clock_conn, &time);
 	if (rc != EOK)
-		goto ret_uptime;
-
+		goto fallback;
+	
 	tv->tv_usec = 0;
-	tv->tv_sec = mktime(&t);
-
-	free(svc_name);
-	free(svc_ids);
-
-	return EOK;
-
-ret_uptime:
-
-	free(svc_name);
-	free(svc_ids);
-
-	return getuptime(tv);
-}
-
-int getuptime(struct timeval *tv)
+	tv->tv_sec = mktime(&time);
+	
+	return;
+	
+fallback:
+	getuptime(tv);
+}
+
+void getuptime(struct timeval *tv)
 {
 	if (ktime == NULL) {
@@ -552,5 +589,5 @@
 		if (rc != EOK) {
 			errno = rc;
-			return -1;
+			goto fallback;
 		}
 		
@@ -561,5 +598,5 @@
 			as_area_destroy(addr);
 			errno = rc;
-			return -1;
+			goto fallback;
 		}
 		
@@ -580,6 +617,10 @@
 	} else
 		tv->tv_sec = s1;
-
-	return 0;
+	
+	return;
+	
+fallback:
+	tv->tv_sec = 0;
+	tv->tv_usec = 0;
 }
 
@@ -587,6 +628,5 @@
 {
 	struct timeval tv;
-	if (gettimeofday(&tv, NULL))
-		return (time_t) -1;
+	gettimeofday(&tv, NULL);
 	
 	if (tloc)
@@ -631,11 +671,16 @@
 }
 
-/**
- * This function first normalizes the provided broken-down time
- * (moves all values to their proper bounds) and then tries to
- * calculate the appropriate time_t representation.
+/** Get time from broken-down time.
+ *
+ * First normalize the provided broken-down time
+ * (moves all values to their proper bounds) and
+ * then try to calculate the appropriate time_t
+ * representation.
  *
  * @param tm Broken-down time.
- * @return time_t representation of the time, undefined value on overflow.
+ *
+ * @return time_t representation of the time.
+ * @return Undefined value on overflow.
+ *
  */
 time_t mktime(struct tm *tm)
@@ -643,18 +688,46 @@
 	// TODO: take DST flag into account
 	// TODO: detect overflow
-
-	_normalize_time(tm, 0);
-	return _secs_since_epoch(tm);
-}
-
-/**
- * Convert time and date to a string, based on a specified format and
- * current locale.
- * 
- * @param s Buffer to write string to.
+	
+	normalize_time(tm, 0);
+	return secs_since_epoch(tm);
+}
+
+/*
+ * FIXME: This requires POSIX-correct snprintf.
+ *        Otherwise it won't work with non-ASCII chars.
+ */
+#define APPEND(...) \
+	{ \
+		consumed = snprintf(ptr, remaining, __VA_ARGS__); \
+		if (consumed >= remaining) \
+			return 0; \
+		\
+		ptr += consumed; \
+		remaining -= consumed; \
+	}
+
+#define RECURSE(fmt) \
+	{ \
+		consumed = strftime(ptr, remaining, fmt, tm); \
+		if (consumed == 0) \
+			return 0; \
+		\
+		ptr += consumed; \
+		remaining -= consumed; \
+	}
+
+#define TO_12H(hour) \
+	(((hour) > 12) ? ((hour) - 12) : \
+	    (((hour) == 0) ? 12 : (hour)))
+
+/** Convert time and date to a string.
+ *
+ * @param s       Buffer to write string to.
  * @param maxsize Size of the buffer.
- * @param format Format of the output.
- * @param tm Broken-down time to format.
+ * @param format  Format of the output.
+ * @param tm      Broken-down time to format.
+ *
  * @return Number of bytes written.
+ *
  */
 size_t strftime(char *restrict s, size_t maxsize,
@@ -664,17 +737,21 @@
 	assert(format != NULL);
 	assert(tm != NULL);
-
+	
 	// TODO: use locale
+	
 	static const char *wday_abbr[] = {
 		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 	};
+	
 	static const char *wday[] = {
 		"Sunday", "Monday", "Tuesday", "Wednesday",
 		"Thursday", "Friday", "Saturday"
 	};
+	
 	static const char *mon_abbr[] = {
 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 	};
+	
 	static const char *mon[] = {
 		"January", "February", "March", "April", "May", "June", "July",
@@ -682,7 +759,6 @@
 	};
 	
-	if (maxsize < 1) {
+	if (maxsize < 1)
 		return 0;
-	}
 	
 	char *ptr = s;
@@ -690,30 +766,7 @@
 	size_t remaining = maxsize;
 	
-	#define append(...) { \
-		/* FIXME: this requires POSIX-correct snprintf */ \
-		/*        otherwise it won't work with non-ascii chars */ \
-		consumed = snprintf(ptr, remaining, __VA_ARGS__); \
-		if (consumed >= remaining) { \
-			return 0; \
-		} \
-		ptr += consumed; \
-		remaining -= consumed; \
-	}
-	
-	#define recurse(fmt) { \
-		consumed = strftime(ptr, remaining, fmt, tm); \
-		if (consumed == 0) { \
-			return 0; \
-		} \
-		ptr += consumed; \
-		remaining -= consumed; \
-	}
-	
-	#define TO_12H(hour) (((hour) > 12) ? ((hour) - 12) : \
-	    (((hour) == 0) ? 12 : (hour)))
-	
 	while (*format != '\0') {
 		if (*format != '%') {
-			append("%c", *format);
+			APPEND("%c", *format);
 			format++;
 			continue;
@@ -721,13 +774,15 @@
 		
 		format++;
-		if (*format == '0' || *format == '+') {
+		if ((*format == '0') || (*format == '+')) {
 			// TODO: padding
 			format++;
 		}
+		
 		while (isdigit(*format)) {
 			// TODO: padding
 			format++;
 		}
-		if (*format == 'O' || *format == 'E') {
+		
+		if ((*format == 'O') || (*format == 'E')) {
 			// TODO: locale's alternative format
 			format++;
@@ -736,83 +791,120 @@
 		switch (*format) {
 		case 'a':
-			append("%s", wday_abbr[tm->tm_wday]); break;
+			APPEND("%s", wday_abbr[tm->tm_wday]);
+			break;
 		case 'A':
-			append("%s", wday[tm->tm_wday]); break;
+			APPEND("%s", wday[tm->tm_wday]);
+			break;
 		case 'b':
-			append("%s", mon_abbr[tm->tm_mon]); break;
+			APPEND("%s", mon_abbr[tm->tm_mon]);
+			break;
 		case 'B':
-			append("%s", mon[tm->tm_mon]); break;
+			APPEND("%s", mon[tm->tm_mon]);
+			break;
 		case 'c':
 			// TODO: locale-specific datetime format
-			recurse("%Y-%m-%d %H:%M:%S"); break;
+			RECURSE("%Y-%m-%d %H:%M:%S");
+			break;
 		case 'C':
-			append("%02d", (1900 + tm->tm_year) / 100); break;
+			APPEND("%02d", (1900 + tm->tm_year) / 100);
+			break;
 		case 'd':
-			append("%02d", tm->tm_mday); break;
+			APPEND("%02d", tm->tm_mday);
+			break;
 		case 'D':
-			recurse("%m/%d/%y"); break;
+			RECURSE("%m/%d/%y");
+			break;
 		case 'e':
-			append("%2d", tm->tm_mday); break;
+			APPEND("%2d", tm->tm_mday);
+			break;
 		case 'F':
-			recurse("%+4Y-%m-%d"); break;
+			RECURSE("%+4Y-%m-%d");
+			break;
 		case 'g':
-			append("%02d", _wbyear(tm) % 100); break;
+			APPEND("%02d", wbyear(tm) % 100);
+			break;
 		case 'G':
-			append("%d", _wbyear(tm)); break;
+			APPEND("%d", wbyear(tm));
+			break;
 		case 'h':
-			recurse("%b"); break;
+			RECURSE("%b");
+			break;
 		case 'H':
-			append("%02d", tm->tm_hour); break;
+			APPEND("%02d", tm->tm_hour);
+			break;
 		case 'I':
-			append("%02d", TO_12H(tm->tm_hour)); break;
+			APPEND("%02d", TO_12H(tm->tm_hour));
+			break;
 		case 'j':
-			append("%03d", tm->tm_yday); break;
+			APPEND("%03d", tm->tm_yday);
+			break;
 		case 'k':
-			append("%2d", tm->tm_hour); break;
+			APPEND("%2d", tm->tm_hour);
+			break;
 		case 'l':
-			append("%2d", TO_12H(tm->tm_hour)); break;
+			APPEND("%2d", TO_12H(tm->tm_hour));
+			break;
 		case 'm':
-			append("%02d", tm->tm_mon); break;
+			APPEND("%02d", tm->tm_mon);
+			break;
 		case 'M':
-			append("%02d", tm->tm_min); break;
+			APPEND("%02d", tm->tm_min);
+			break;
 		case 'n':
-			append("\n"); break;
+			APPEND("\n");
+			break;
 		case 'p':
-			append("%s", tm->tm_hour < 12 ? "AM" : "PM"); break;
+			APPEND("%s", tm->tm_hour < 12 ? "AM" : "PM");
+			break;
 		case 'P':
-			append("%s", tm->tm_hour < 12 ? "am" : "PM"); break;
+			APPEND("%s", tm->tm_hour < 12 ? "am" : "PM");
+			break;
 		case 'r':
-			recurse("%I:%M:%S %p"); break;
+			RECURSE("%I:%M:%S %p");
+			break;
 		case 'R':
-			recurse("%H:%M"); break;
+			RECURSE("%H:%M");
+			break;
 		case 's':
-			append("%ld", _secs_since_epoch(tm)); break;
+			APPEND("%ld", secs_since_epoch(tm));
+			break;
 		case 'S':
-			append("%02d", tm->tm_sec); break;
+			APPEND("%02d", tm->tm_sec);
+			break;
 		case 't':
-			append("\t"); break;
+			APPEND("\t");
+			break;
 		case 'T':
-			recurse("%H:%M:%S"); break;
+			RECURSE("%H:%M:%S");
+			break;
 		case 'u':
-			append("%d", (tm->tm_wday == 0) ? 7 : tm->tm_wday);
+			APPEND("%d", (tm->tm_wday == 0) ? 7 : tm->tm_wday);
 			break;
 		case 'U':
-			append("%02d", _sun_week_number(tm)); break;
+			APPEND("%02d", sun_week_number(tm));
+			break;
 		case 'V':
-			append("%02d", _iso_week_number(tm)); break;
+			APPEND("%02d", iso_week_number(tm));
+			break;
 		case 'w':
-			append("%d", tm->tm_wday); break;
+			APPEND("%d", tm->tm_wday);
+			break;
 		case 'W':
-			append("%02d", _mon_week_number(tm)); break;
+			APPEND("%02d", mon_week_number(tm));
+			break;
 		case 'x':
 			// TODO: locale-specific date format
-			recurse("%Y-%m-%d"); break;
+			RECURSE("%Y-%m-%d");
+			break;
 		case 'X':
 			// TODO: locale-specific time format
-			recurse("%H:%M:%S"); break;
+			RECURSE("%H:%M:%S");
+			break;
 		case 'y':
-			append("%02d", tm->tm_year % 100); break;
+			APPEND("%02d", tm->tm_year % 100);
+			break;
 		case 'Y':
-			append("%d", 1900 + tm->tm_year); break;
+			APPEND("%d", 1900 + tm->tm_year);
+			break;
 		case 'z':
 			// TODO: timezone
@@ -822,35 +914,33 @@
 			break;
 		case '%':
-			append("%%");
+			APPEND("%%");
 			break;
 		default:
 			/* Invalid specifier, print verbatim. */
-			while (*format != '%') {
+			while (*format != '%')
 				format--;
-			}
-			append("%%");
+			
+			APPEND("%%");
 			break;
 		}
+		
 		format++;
 	}
 	
-	#undef append
-	#undef recurse
-	
 	return maxsize - remaining;
 }
 
-
-/** Converts a time value to a broken-down UTC time
- *
- * @param time    Time to convert
- * @param result  Structure to store the result to
- *
- * @return        EOK or a negative error code
+/** Convert a time value to a broken-down UTC time/
+ *
+ * @param time   Time to convert
+ * @param result Structure to store the result to
+ *
+ * @return EOK or a negative error code
+ *
  */
 int time_utc2tm(const time_t time, struct tm *restrict result)
 {
 	assert(result != NULL);
-
+	
 	/* Set result to epoch. */
 	result->tm_sec = 0;
@@ -860,40 +950,41 @@
 	result->tm_mon = 0;
 	result->tm_year = 70; /* 1970 */
-
-	if (_normalize_time(result, time) == -1)
+	
+	if (normalize_time(result, time) == -1)
 		return EOVERFLOW;
-
+	
 	return EOK;
 }
 
-/** Converts a time value to a null terminated string of the form
- *  "Wed Jun 30 21:49:08 1993\n" expressed in UTC.
- *
- * @param time   Time to convert.
- * @param buf    Buffer to store the string to, must be at least
- *               ASCTIME_BUF_LEN bytes long.
- *
- * @return       EOK or a negative error code.
+/** Convert a time value to a NULL-terminated string.
+ *
+ * The format is "Wed Jun 30 21:49:08 1993\n" expressed in UTC.
+ *
+ * @param time Time to convert.
+ * @param buf  Buffer to store the string to, must be at least
+ *             ASCTIME_BUF_LEN bytes long.
+ *
+ * @return EOK or a negative error code.
+ *
  */
 int time_utc2str(const time_t time, char *restrict buf)
 {
-	struct tm t;
-	int r;
-
-	if ((r = time_utc2tm(time, &t)) != EOK)
-		return r;
-
-	time_tm2str(&t, buf);
+	struct tm tm;
+	int ret = time_utc2tm(time, &tm);
+	if (ret != EOK)
+		return ret;
+	
+	time_tm2str(&tm, buf);
 	return EOK;
 }
 
-
-/**
- * Converts broken-down time to a string in format
- * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
+/** Convert broken-down time to a NULL-terminated string.
+ *
+ * The format is "Sun Jan 1 00:00:00 1970\n". (Obsolete)
  *
  * @param timeptr Broken-down time structure.
- * @param buf     Buffer to store string to, must be at least ASCTIME_BUF_LEN
- *                bytes long.
+ * @param buf     Buffer to store string to, must be at least
+ *                ASCTIME_BUF_LEN bytes long.
+ *
  */
 void time_tm2str(const struct tm *restrict timeptr, char *restrict buf)
@@ -901,13 +992,14 @@
 	assert(timeptr != NULL);
 	assert(buf != NULL);
-
+	
 	static const char *wday[] = {
 		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 	};
+	
 	static const char *mon[] = {
 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 	};
-
+	
 	snprintf(buf, ASCTIME_BUF_LEN, "%s %s %2d %02d:%02d:%02d %d\n",
 	    wday[timeptr->tm_wday],
@@ -918,18 +1010,19 @@
 }
 
-/**
- * Converts a time value to a broken-down local time, expressed relative
- * to the user's specified timezone.
- *
- * @param timer     Time to convert.
- * @param result    Structure to store the result to.
- *
- * @return          EOK on success or a negative error code.
+/** Converts a time value to a broken-down local time.
+ *
+ * Time is expressed relative to the user's specified timezone.
+ *
+ * @param timer  Time to convert.
+ * @param result Structure to store the result to.
+ *
+ * @return EOK on success or a negative error code.
+ *
  */
 int time_local2tm(const time_t time, struct tm *restrict result)
 {
-	// TODO: deal with timezone
-	// currently assumes system and all times are in GMT
-
+	// TODO: Deal with timezones.
+	//       Currently assumes system and all times are in UTC
+	
 	/* Set result to epoch. */
 	result->tm_sec = 0;
@@ -939,41 +1032,41 @@
 	result->tm_mon = 0;
 	result->tm_year = 70; /* 1970 */
-
-	if (_normalize_time(result, time) == -1)
+	
+	if (normalize_time(result, time) == -1)
 		return EOVERFLOW;
-
+	
 	return EOK;
 }
 
-/**
- * Converts the calendar time to a null terminated string
- * of the form "Wed Jun 30 21:49:08 1993\n" expressed relative to the
+/** Convert the calendar time to a NULL-terminated string.
+ *
+ * The format is "Wed Jun 30 21:49:08 1993\n" expressed relative to the
  * user's specified timezone.
- * 
- * @param timer  Time to convert.
- * @param buf    Buffer to store the string to. Must be at least
- *               ASCTIME_BUF_LEN bytes long.
- *
- * @return       EOK on success or a negative error code.
+ *
+ * @param timer Time to convert.
+ * @param buf   Buffer to store the string to. Must be at least
+ *              ASCTIME_BUF_LEN bytes long.
+ *
+ * @return EOK on success or a negative error code.
+ *
  */
 int time_local2str(const time_t time, char *buf)
 {
 	struct tm loctime;
-	int r;
-
-	if ((r = time_local2tm(time, &loctime)) != EOK)
-		return r;
-
+	int ret = time_local2tm(time, &loctime);
+	if (ret != EOK)
+		return ret;
+	
 	time_tm2str(&loctime, buf);
-
 	return EOK;
 }
 
-/**
- * Calculate the difference between two times, in seconds.
- * 
+/** Calculate the difference between two times, in seconds.
+ *
  * @param time1 First time.
  * @param time0 Second time.
- * @return Time in seconds.
+ *
+ * @return Time difference in seconds.
+ *
  */
 double difftime(time_t time1, time_t time0)
Index: uspace/lib/c/include/stats.h
===================================================================
--- uspace/lib/c/include/stats.h	(revision 9696b01a9508667ab9b8592345fd6523e0ce3e76)
+++ uspace/lib/c/include/stats.h	(revision 3da166f05b0e0513fe18f82b34f75ef99bef955a)
@@ -48,5 +48,4 @@
 extern stats_physmem_t *stats_get_physmem(void);
 extern load_t *stats_get_load(size_t *);
-extern sysarg_t stats_get_uptime(void);
 
 extern stats_task_t *stats_get_tasks(size_t *);
Index: uspace/lib/c/include/sys/time.h
===================================================================
--- uspace/lib/c/include/sys/time.h	(revision 9696b01a9508667ab9b8592345fd6523e0ce3e76)
+++ uspace/lib/c/include/sys/time.h	(revision 3da166f05b0e0513fe18f82b34f75ef99bef955a)
@@ -40,6 +40,6 @@
 #include <sys/types.h>
 
-#define DST_NONE 0
-#define ASCTIME_BUF_LEN 26
+#define DST_NONE  0
+#define ASCTIME_BUF_LEN  26
 
 typedef long time_t;
@@ -50,13 +50,13 @@
 
 struct tm {
-	int tm_sec;         /* Seconds [0,60]. */
-	int tm_min;         /* Minutes [0,59]. */
-	int tm_hour;        /* Hour [0,23]. */
-	int tm_mday;        /* Day of month [1,31]. */
-	int tm_mon;         /* Month of year [0,11]. */
-	int tm_year;        /* Years since 1900. */
-	int tm_wday;        /* Day of week [0,6] (Sunday = 0). */
-	int tm_yday;        /* Day of year [0,365]. */
-	int tm_isdst;       /* Daylight Savings flag. */
+	int tm_sec;    /* Seconds [0,60]. */
+	int tm_min;    /* Minutes [0,59]. */
+	int tm_hour;   /* Hour [0,23]. */
+	int tm_mday;   /* Day of month [1,31]. */
+	int tm_mon;    /* Month of year [0,11]. */
+	int tm_year;   /* Years since 1900. */
+	int tm_wday;   /* Day of week [0,6] (Sunday = 0). */
+	int tm_yday;   /* Day of year [0,365]. */
+	int tm_isdst;  /* Daylight Savings flag. */
 };
 
@@ -71,22 +71,22 @@
 };
 
-extern void tv_add(struct timeval *tv, suseconds_t usecs);
-extern suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2);
-extern int tv_gt(struct timeval *tv1, struct timeval *tv2);
-extern int tv_gteq(struct timeval *tv1, struct timeval *tv2);
-extern int gettimeofday(struct timeval *tv, struct timezone *tz);
-extern int getuptime(struct timeval *tv);
+extern void tv_add(struct timeval *, suseconds_t);
+extern suseconds_t tv_sub(struct timeval *, struct timeval *);
+extern int tv_gt(struct timeval *, struct timeval *);
+extern int tv_gteq(struct timeval *, struct timeval *);
+extern void gettimeofday(struct timeval *, struct timezone *);
+extern void getuptime(struct timeval *);
 
 extern void udelay(useconds_t);
 
-extern time_t mktime(struct tm *tm);
-extern int time_utc2tm(const time_t time, struct tm *result);
-extern int time_utc2str(const time_t time, char *buf);
-extern void time_tm2str(const struct tm *timeptr, char *buf);
-extern int time_local2tm(const time_t time, struct tm *result);
-extern int time_local2str(const time_t time, char *buf);
-extern double difftime(time_t time1, time_t time0);
-extern size_t strftime(char *restrict s, size_t maxsize,
-    const char *restrict format, const struct tm *restrict tm);
+extern time_t mktime(struct tm *);
+extern int time_utc2tm(const time_t, struct tm *);
+extern int time_utc2str(const time_t, char *);
+extern void time_tm2str(const struct tm *, char *);
+extern int time_local2tm(const time_t, struct tm *);
+extern int time_local2str(const time_t, char *);
+extern double difftime(time_t, time_t);
+extern size_t strftime(char *restrict, size_t, const char *restrict,
+    const struct tm *restrict);
 
 #endif
