aboutsummaryrefslogblamecommitdiffstats
path: root/libpatch_create_timestamp_frac_string.c
blob: 18b8090bde36ac494f5ae3e14caf8cdb48798971 (plain) (tree)




















                                                                                                        
/* See LICENSE file for copyright and license details. */
#include "common.h"


size_t
libpatch_create_timestamp_frac_string(char *buf, size_t bufsize, const struct tm *tm,
                                      const char *frac, int zone, enum libpatch_style style)
{
	uintmax_t subseconds = 0, digit;
	unsigned decimals = 0;
	if (frac) {
		for (;; frac++) {
			digit = (uintmax_t)*frac - (uintmax_t)'0';
			if (digit > 9 || subseconds > (UINTMAX_MAX - digit) / 10U)
				break;
			subseconds = subseconds * 10U + digit;
			decimals += 1;
		}
	}
	return libpatch_create_timestamp(buf, bufsize, tm, subseconds, decimals, decimals, zone, style);
}