Re: g_strdup_strftime
- From: Owen Taylor <otaylor redhat com>
- To: gtk-devel-list redhat com
- Cc: John Sullivan <sullivan eazel com>
- Subject: Re: g_strdup_strftime
- Date: 26 Jan 2000 20:22:48 -0500
Darin Adler <darin@eazel.com> writes:
> I'd like to see a function named g_strdup_strftime added to <glib.h>. With
> glibc, it's trivial to implement:
>
> gchar *
> g_strdup_strftime (const gchar *format, const struct tm *time)
> {
> size_t size;
> gchar *result;
>
> size = strftime (NULL, UINT_MAX, format, time);
> result = g_malloc (size + 1);
> strftime (result, size + 1, format, time);
> return result;
> }
>
> But it might be trickier to do with non-Gnu versions of strftime.
>
> What do you all think?
Sounds like a good addition to me.
I think what you'd have to do is allocate an initial size buffer
that was most likely large enough (say 256 chararacters) - that
could be automatic on the stack, and then if necessary, increase
the size of that buffer until strftime succeeded.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]