|
Message-ID: <alpine.LNX.2.20.13.1706152038570.13954@monopod.intra.ispras.ru> Date: Thu, 15 Jun 2017 20:46:18 +0300 (MSK) From: Alexander Monakov <amonakov@...ras.ru> To: musl@...ts.openwall.com Subject: Re: [PATCH] Handle localtime errors in ctime On Thu, 15 Jun 2017, Rich Felker wrote: > Look ok? > > diff --git a/src/time/ctime_r.c b/src/time/ctime_r.c > index d2260a1..05699ca 100644 > --- a/src/time/ctime_r.c > +++ b/src/time/ctime_r.c > @@ -3,6 +3,5 @@ > char *ctime_r(const time_t *t, char *buf) > { > struct tm tm; > - localtime_r(t, &tm); > - return asctime_r(&tm, buf); > + return localtime_r(t, &tm) ? asctime_r(&tm, buf) : 0; > } Sure, although personally I'm highly tempted to pick up the size optimization from reusing return value of localtime_r: Alexander diff --git a/src/time/ctime_r.c b/src/time/ctime_r.c index d2260a16..9047b38f 100644 --- a/src/time/ctime_r.c +++ b/src/time/ctime_r.c @@ -2,7 +2,6 @@ char *ctime_r(const time_t *t, char *buf) { - struct tm tm; - localtime_r(t, &tm); - return asctime_r(&tm, buf); + struct tm tm, *tm_p; + return (tm_p = localtime_r(t, &tm)) ? asctime_r(tm_p, buf) : 0; }
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.