/* Copyright (C) 2017-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4grpdt.ctr */ /** @file dk4grpdt.c The dk4grpdt module. */ #line 9 "dk4grpdt.ctr" #include "dk4conf.h" #if DK4_TIME_WITH_SYS_TIME #ifndef SYS_TIME_H_INCLUDED #include #define SYS_TIME_H_INCLUDED 1 #endif #ifndef TIME_H_INCLUDED #include #define TIME_H_INCLUDED 1 #endif #else #if DK4_HAVE_TIME_H #ifndef TIME_H_INCLUDED #include #define TIME_H_INCLUDED 1 #endif #else #if DK4_HAVE_SYS_TIME_H #ifndef SYS_TIME_H_INCLUDED #include #define SYS_TIME_H_INCLUDED 1 #endif #endif #endif #endif #include #ifndef GRA_H_INCLUDED #include "gra.h" #endif #if DK4_HAVE_ASSERT_H #ifndef ASSERT_H_INCLUDED #include #define ASSERT_H_INCLUDED 1 #endif #endif /** Conversion format string. */ static const char dk4gra_pdf_ts_format[] = { "%04d%02d%02d%02d%02d%02d" }; /** Convert timestamp to text. @param buf Destination buffer. @param szbuf Size of destination buffer. @param plct Local time splitted into components. */ static void dk4gra_pdf_convert_timestamp(char *buf, size_t szbuf, const struct tm *plct) { #if DK4_HAVE__SNPRINTF_S _snprintf_s( buf, szbuf, _TRUNCATE, dk4gra_pdf_ts_format, (1900 + plct->tm_year), (1 + plct->tm_mon), plct->tm_mday, plct->tm_hour, plct->tm_min, plct->tm_sec ); #else #if DK4_HAVE__SNPRINTF _snprintf( buf, szbuf, dk4gra_pdf_ts_format, (1900 + plct->tm_year), (1 + plct->tm_mon), plct->tm_mday, plct->tm_hour, plct->tm_min, plct->tm_sec ); #else #if DK4_HAVE_SNPRINTF snprintf( buf, szbuf, dk4gra_pdf_ts_format, (1900 + plct->tm_year), (1 + plct->tm_mon), plct->tm_mday, plct->tm_hour, plct->tm_min, plct->tm_sec ); #else sprintf( buf, dk4gra_pdf_ts_format, (1900 + plct->tm_year), (1 + plct->tm_mon), plct->tm_mday, plct->tm_hour, plct->tm_min, plct->tm_sec ); #endif #endif #endif } int dk4gra_pdf_timestamp(char *buf, size_t szbuf, dk4_er_t *erp) { #if DK4_ON_WINDOWS /* +++ Windows +++ */ struct tm lct; __time64_t timer; /* --- Windows --- */ #else /* +++ POSIX +++ */ struct tm lct; #if !DK4_HAVE_LOCALTIME_R struct tm *plct; #endif time_t timer; /* --- POSIX --- */ #endif int back = 0; #if DK4_USE_ASSERT assert(NULL != buf); assert(14 < szbuf); #endif if ((NULL == buf) || (15 > szbuf)) { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); goto finished; } buf[0] = '\0'; #if DK4_ON_WINDOWS /* +++ Windows +++ */ (void)_time64(&timer); if (0 == _localtime64_s(&lct, &timer)) { back = 1; dk4gra_pdf_convert_timestamp(buf, szbuf, &lct); } /* --- Windows --- */ #else /* +++ POSIX +++ */ (void)time(&timer); #if DK4_HAVE_LOCALTIME_R if (NULL != localtime_r(&timer, &lct)) { back = 1; dk4gra_pdf_convert_timestamp(buf, szbuf, &lct); } #else dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED); #endif /* --- POSIX --- */ #endif finished: return back; } /* vim: set ai sw=4 ts=4 : */