Index: uspace/lib/c/generic/time.c
===================================================================
--- uspace/lib/c/generic/time.c	(revision 3a583476f7f81cc2ee89360a957e865dc5a1080e)
+++ uspace/lib/c/generic/time.c	(revision f7ea54007c430389f32534f3b3ec662f2dad8fe7)
@@ -841,25 +841,51 @@
 }
 
-struct tm *gmtime(const time_t *timer)
-{
-	assert(timer != NULL);
-
-	static struct tm result;
+
+/** 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
+ */
+int utctime2tm(const time_t time, struct tm *restrict result)
+{
+	assert(result != NULL);
 
 	/* Set result to epoch. */
-	result.tm_sec = 0;
-	result.tm_min = 0;
-	result.tm_hour = 0;
-	result.tm_mday = 1;
-	result.tm_mon = 0;
-	result.tm_year = 70; /* 1970 */
-
-	if (_normalize_time(&result, *timer) == -1) {
-		errno = EOVERFLOW;
-		return NULL;
-	}
-
-	return &result;
-}
+	result->tm_sec = 0;
+	result->tm_min = 0;
+	result->tm_hour = 0;
+	result->tm_mday = 1;
+	result->tm_mon = 0;
+	result->tm_year = 70; /* 1970 */
+
+	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.
+ */
+int utctime2str(const time_t time, char *restrict buf)
+{
+	struct tm t;
+	int r;
+
+	if ((r = utctime2tm(time, &t)) != EOK)
+		return r;
+
+	tm2str(&t, buf);
+	return EOK;
+}
+
 
 /**
@@ -868,11 +894,11 @@
  *
  * @param timeptr Broken-down time structure.
- * @return Pointer to a statically allocated string.
- */
-char *asctime(const struct tm *timeptr)
-{
-	static char buf[ASCTIME_BUF_LEN];
-
+ * @param buf     Buffer to store string to, must be at least ASCTIME_BUF_LEN
+ *                bytes long.
+ */
+void tm2str(const struct tm *restrict timeptr, char *restrict buf)
+{
 	assert(timeptr != NULL);
+	assert(buf != NULL);
 
 	static const char *wday[] = {
@@ -890,51 +916,56 @@
 	    timeptr->tm_min, timeptr->tm_sec,
 	    1900 + timeptr->tm_year);
-
-	return buf;
-
-}
-
-/**
- * Converts a time value to a broken-down local time.
- *
- * @param timer Time to convert.
- * @return Normalized broken-down time in local timezone, NULL on overflow.
- */
-struct tm *localtime(const time_t *timer)
+}
+
+/**
+ * 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.
+ */
+int localtime2tm(const time_t time, struct tm *restrict result)
 {
 	// TODO: deal with timezone
 	// currently assumes system and all times are in GMT
 
-	static struct tm result;
-
 	/* Set result to epoch. */
-	result.tm_sec = 0;
-	result.tm_min = 0;
-	result.tm_hour = 0;
-	result.tm_mday = 1;
-	result.tm_mon = 0;
-	result.tm_year = 70; /* 1970 */
-
-	if (_normalize_time(&result, *timer) == -1) {
-		errno = EOVERFLOW;
-		return NULL;
-	}
-
-	return &result;
-}
-
-/**
- * Equivalent to asctime(localtime(clock)).
+	result->tm_sec = 0;
+	result->tm_min = 0;
+	result->tm_hour = 0;
+	result->tm_mday = 1;
+	result->tm_mon = 0;
+	result->tm_year = 70; /* 1970 */
+
+	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
+ * user's specified timezone.
  * 
- * @param timer Time to convert.
- * @return Pointer to a statically allocated string holding the date.
- */
-char *ctime(const time_t *timer)
-{
-	struct tm *loctime = localtime(timer);
-	if (loctime == NULL) {
-		return NULL;
-	}
-	return asctime(loctime);
+ * @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 localtime2str(const time_t time, char *buf)
+{
+	struct tm loctime;
+	int r;
+
+	if ((r = localtime2tm(time, &loctime)) != EOK)
+		return r;
+
+	tm2str(&loctime, buf);
+
+	return EOK;
 }
 
