From: Michael Tremer Date: Thu, 18 Aug 2022 19:24:51 +0000 (+0000) Subject: string: Drop pakfire_format_date() X-Git-Tag: 0.9.28~443 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06e2161b5f9f6b90ff1925291eea8314ef0b2654;p=pakfire.git string: Drop pakfire_format_date() Instead, pakfire_strftime can be used more universally. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/string.h b/src/libpakfire/include/pakfire/string.h index 6c34fd023..43ab71095 100644 --- a/src/libpakfire/include/pakfire/string.h +++ b/src/libpakfire/include/pakfire/string.h @@ -59,8 +59,6 @@ int pakfire_format_speed(char* dst, size_t length, double value); int __pakfire_strftime(char* buffer, const size_t length, const char* format, const time_t t) __attribute__((format(strftime, 3, 0))); -char* pakfire_format_date(time_t t); - #define pakfire_strftime_now(buffer, format) \ __pakfire_strftime_now(buffer, sizeof(dest), format) int __pakfire_strftime_now(char* buffer, const size_t length, const char* format) diff --git a/src/libpakfire/key.c b/src/libpakfire/key.c index 50b83dd47..fbfdeba48 100644 --- a/src/libpakfire/key.c +++ b/src/libpakfire/key.c @@ -638,18 +638,23 @@ ERROR: } PAKFIRE_EXPORT char* pakfire_key_dump(struct pakfire_key* key) { - char* s = ""; + char date[1024]; + char* s = NULL; + int r; time_t created = pakfire_key_get_created(key); - char* date_created = pakfire_format_date(created); + + // Format creation time + r = pakfire_strftime(date, "%Y-%m-%d", created); + if (r) + goto ERROR; asprintf(&s, "pub %s%zu/%s %s", pakfire_key_get_pubkey_algo(key), pakfire_key_get_pubkey_length(key), pakfire_key_get_fingerprint(key), - date_created + date ); - free(date_created); const char* uid = pakfire_key_get_uid(key); if (uid) { @@ -658,12 +663,20 @@ PAKFIRE_EXPORT char* pakfire_key_dump(struct pakfire_key* key) { time_t expires = pakfire_key_get_expires(key); if (expires) { - char* date_expires = pakfire_format_date(expires); - asprintf(&s, "%s\n %s: %s", s, _("Expires"), date_expires); - free(date_expires); + r = pakfire_strftime(date, "%Y-%m-%d", expires); + if (r) + goto ERROR; + + asprintf(&s, "%s\n %s: %s", s, _("Expires"), date); } return s; + +ERROR: + if (s) + free(s); + + return NULL; } int pakfire_key_sign(struct pakfire_key* key, const char* buffer, const size_t buffer_length, diff --git a/src/libpakfire/string.c b/src/libpakfire/string.c index a89a01e24..527a079ae 100644 --- a/src/libpakfire/string.c +++ b/src/libpakfire/string.c @@ -362,18 +362,6 @@ int __pakfire_strftime(char* buffer, const size_t length, return 0; } -char* pakfire_format_date(time_t t) { - char buffer[1024]; - int r; - - // Format time - r = pakfire_strftime(buffer, "%Y-%m-%d", t); - if (r) - return NULL; - - return strdup(buffer); -} - int __pakfire_strftime_now(char* buffer, size_t length, const char* format) { // Fetch the current time const time_t t = time(NULL);