I guess why not, for printf, snprintf etc:- Similar to eina_stringshare* APIs
Best Regards, Shilpa Singh ------- Original Message ------- Sender : Daniel Kolesa<[email protected]> Date : Sep 22, 2015 18:30 (GMT+09:00) Title : Re: [E-devel] [EGIT] [core/efl] master 17/20: eina_tmpstr: add eina_tmpstr_strftime On Mon, Sep 21, 2015 at 11:24 PM, Shilpa Singh wrote: > cedric pushed a commit to branch master. > > http://git.enlightenment.org/core/efl.git/commit/?id=abaf29cb768375957c9ee0b64d36034c21c618ea > > commit abaf29cb768375957c9ee0b64d36034c21c618ea > Author: Shilpa Singh > Date: Mon Sep 21 23:48:16 2015 +0200 > > eina_tmpstr: add eina_tmpstr_strftime This API seems awfully arbitrary and I don't really see the point. Might as well be any other function that prints to strings - are you gonna add these too? Sounds horrible to me. D5 > > Summary: > > @feature > > Test Plan: > eina_tmpstr_strftime API can be used to create a temporary string > which is updated with strftime output > > eina_tmpstr_steal can be used to get actual string set in eina_tmpstr > > Reviewers: cedric > > Subscribers: rajeshps, cedric, govi > > Differential Revision: https://phab.enlightenment.org/D3048 > > Signed-off-by: Cedric BAIL > --- > AUTHORS | 1 + > src/lib/eina/eina_tmpstr.c | 39 +++++++++++++++++++++++++++++++++++++-- > src/lib/eina/eina_tmpstr.h | 25 +++++++++++++++++++++++++ > 3 files changed, 63 insertions(+), 2 deletions(-) > > diff --git a/AUTHORS b/AUTHORS > index eab2011..f714c39 100644 > --- a/AUTHORS > +++ b/AUTHORS > @@ -53,6 +53,7 @@ ChunEon Park (Hermet) > Rajeev Ranjan (Rajeev) > Subodh Kumar > Michelle Legrand > +Shilpa Singh > > Eet > --- > diff --git a/src/lib/eina/eina_tmpstr.c b/src/lib/eina/eina_tmpstr.c > index 43824b7..5b81819 100644 > --- a/src/lib/eina/eina_tmpstr.c > +++ b/src/lib/eina/eina_tmpstr.c > @@ -133,13 +133,48 @@ eina_tmpstr_len(Eina_Tmpstr *tmpstr) > for (s = strs; s; s = s->next) > { > if (s->str == tmpstr) > - { > + { > size_t ret = s->length; > eina_lock_release(&_mutex); > return ret; > - } > + } > } > eina_lock_release(&_mutex); > > return strlen(tmpstr); > } > + > +EAPI Eina_Tmpstr * > +eina_tmpstr_strftime(const char *format, const struct tm *tm) > +{ > + const size_t flen = strlen(format); > + size_t buflen = 16; // An arbitrary starting size > + char *buf = NULL; > + > + do { > + char *tmp; > + size_t len; > + > + tmp = realloc(buf, buflen * sizeof(char)); > + if (!tmp) goto on_error; > + buf = tmp; > + > + len = strftime(buf, buflen, format, tm); > + // Check if we have the expected result and return it. > + if ((len > 0 && len < buflen) || (len == 0 && flen == 0)) > + { > + Eina_Tmpstr *r; > + > + r = eina_tmpstr_add_length(buf, len + 1); > + free(buf); > + return r; > + } > + > + /* Possibly buf overflowed - try again with a bigger buffer */ > + buflen <<= 1; // multiply buffer size by 2 > + } while (buflen < 128 * flen); > + > + on_error: > + free(buf); > + return NULL; > +} > diff --git a/src/lib/eina/eina_tmpstr.h b/src/lib/eina/eina_tmpstr.h > index f784a67..8d9f517 100644 > --- a/src/lib/eina/eina_tmpstr.h > +++ b/src/lib/eina/eina_tmpstr.h > @@ -238,6 +238,31 @@ EAPI size_t eina_tmpstr_len(Eina_Tmpstr *tmpstr); > EAPI void eina_tmpstr_del(Eina_Tmpstr *tmpstr) EINA_ARG_NONNULL(1); > > /** > + * @brief Add a new temporary string based on strftime output. > + * > + * @param tm Pointer to a tm structure needed by strftime. > + * @param format String containing format specifiers needed by strftime. > + * > + * This will add a new temporary string by updating the string value by > output > + * of strftime. > + * > + * Example usage: > + * > + * @code > + * time_t curr_time; > + * struct tm * info; > + * Eina_Tmpstr *buf; > + * > + * curr_time = time(NULL); > + * info = localtime(&curr_time); > + * buf = eina_tmpstr_strftime("%I:%M%p", info); > + * @endcode > + * > + * @since 1.16.0 > + */ > +EAPI Eina_Tmpstr *eina_tmpstr_strftime(const char *format, const struct tm > *tm) EINA_ARG_NONNULL(2); > + > +/** > * @} > */ > > > -- > > ------------------------------------------------------------------------------ _______________________________________________ enlightenment-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/enlightenment-devel ------------------------------------------------------------------------------ Monitor Your Dynamic Infrastructure at Any Scale With Datadog! Get real-time metrics from all of your servers, apps and tools in one place. SourceForge users - Click here to start your Free Trial of Datadog now! http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140 _______________________________________________ enlightenment-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
