#include "config.h"
+#include <stdio.h>
+
#include "timetoa.h"
#include "lib_strbuf.h"
-#include <stdio.h>
/*
* Formatting to string needs at max 40 bytes (even with 64 bit time_t),
- * so we check LIB_BUFLENGTH is big enough for our pupose.
+ * so we check LIB_BUFLENGTH is big enough for our purpose.
*/
#if LIB_BUFLENGTH < 40
# include "GRONK: LIB_BUFLENGTH is not sufficient"
*/
const char *
format_time_fraction(
- time_t secs,
- long frac,
- int prec
+ time_t secs,
+ long frac,
+ int prec
)
{
- static const long limit[10] = {
+ static const long limit[10] = {
1,
10, 100, 1000,
10000, 100000, 1000000,
10000000, 100000000, 1000000000
};
- char * cp;
- u_time ttmp; /* unsigned storage for seconds */
- int notneg; /* flag for non-negative value */
- const char * fmt;
+ char * cp;
+ u_time ttmp; /* unsigned storage for seconds */
+ int notneg; /* flag for non-negative value */
+ const char * fmt;
+ ldiv_t qr;
LIB_GETBUF(cp);
ttmp = (u_time)secs;
/* check if we need signed or unsigned mode */
notneg = (prec < 0);
- prec = abs(prec);
- if (prec <= 0 || prec > 9) {
+ prec = abs(prec);
+ if (prec <= 0 || prec > COUNTOF(limit)) {
if (notneg)
fmt = "%" UTIME_FORMAT;
else
fmt = "%" TIME_FORMAT;
snprintf(cp, LIB_BUFLENGTH, fmt, secs);
- return (cp);
+
+ return cp;
}
/*
* consistency.
*/
if (frac < 0 || frac >= limit[prec]) {
- ldiv_t qr;
qr = ldiv(frac, limit[prec]);
if (qr.rem < 0) {
qr.quot--;
* Get the absolute value of the time stamp.
*/
notneg = notneg || ((time_t)ttmp >= 0);
- if (notneg == 0) {
+ if (!notneg) {
ttmp = ~ttmp;
if (frac != 0)
frac = limit[prec] - frac;
else
- ttmp += 1;
- } else
+ ttmp += 1;
+ } else {
fmt++; /* skip sign char in format string */
+ }
/* finally format the data and return the result */
snprintf(cp, LIB_BUFLENGTH, fmt, ttmp, prec, frac);
- return (cp);
+ return cp;
}
RelativePath="..\..\..\lib\isc\win32\time.c">
</File>
<File
- RelativePath="..\libntp\timespecops.c">
+ RelativePath="..\..\..\libntp\timespecops.c">
</File>
<File
- RelativePath="..\libntp\timevalops.c">
+ RelativePath="..\..\..\libntp\timetoa.c">
+ </File>
+ <File
+ RelativePath="..\..\..\libntp\timevalops.c">
</File>
<File
RelativePath="..\..\..\libntp\tsftomsu.c">
RelativePath="..\..\..\..\libntp\timespecops.c"
>
</File>
+ <File
+ RelativePath="..\..\..\..\libntp\timetoa.c"
+ >
+ </File>
<File
RelativePath="..\..\..\..\libntp\timevalops.c"
>
>
</File>
<File
- RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
+ RelativePath="..\..\include\sys\time.h"
>
</File>
<File
- RelativePath="..\..\include\sys\time.h"
+ RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
>
</File>
<File
RelativePath="..\..\..\..\include\timespecops.h"
>
</File>
+ <File
+ RelativePath="..\..\..\..\include\timetoa.h"
+ >
+ </File>
<File
RelativePath="..\..\..\..\include\timevalops.h"
>