Hi,

I implemented xctime for GNU isofsmk.  xctime is an alternative to ctime()
that:

  - Uses dynamic allocation
  - Is thread-safe
  - Returns localized strings

char *
xctime (const time_t *time)
{
  struct tm *loctime;
  char *str;
  size_t len;

  loctime = localtime (time);

  len = strftime (NULL, INT32_MAX, "%c", loctime) + sizeof ("");

  str = xmalloc (len);
  strftime (str, len, "%c", loctime);

  return str;
}

I find it much more comfortable than having to deal with strftime() every
time.  If you're interested, I could make a Gnulib module out of it.

-- 
Robert Millan

  "Be the change you want to see in the world" -- Gandhi


Reply via email to