bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

xctime()


From: Robert Millan
Subject: xctime()
Date: Sun, 24 Jan 2010 18:53:32 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

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

[Prev in Thread] Current Thread [Next in Thread]