mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
lib/vsprintf: Print time and date in human readable format via %pt
There are users which print time and date represented by content of struct rtc_time in human readable format. Instead of open coding that each time introduce %ptR[dt][r] specifier. Cc: Arnd Bergmann <arnd@arndb.de> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Guan Xuetao <gxt@mprc.pku.edu.cn> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jason Wessel <jason.wessel@windriver.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Jonathan Hunter <jonathanh@nvidia.com> Cc: Krzysztof Kozlowski <krzk@kernel.org> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: Petr Mladek <pmladek@suse.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
committed by
Alexandre Belloni
parent
8c4cf161a8
commit
4d42c44727
@@ -9,6 +9,7 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/rtc.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
@@ -249,12 +250,11 @@ plain_format(void)
|
||||
#endif /* BITS_PER_LONG == 64 */
|
||||
|
||||
static int __init
|
||||
plain_hash(void)
|
||||
plain_hash_to_buffer(const void *p, char *buf, size_t len)
|
||||
{
|
||||
char buf[PLAIN_BUF_SIZE];
|
||||
int nchars;
|
||||
|
||||
nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR);
|
||||
nchars = snprintf(buf, len, "%p", p);
|
||||
|
||||
if (nchars != PTR_WIDTH)
|
||||
return -1;
|
||||
@@ -265,6 +265,20 @@ plain_hash(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int __init
|
||||
plain_hash(void)
|
||||
{
|
||||
char buf[PLAIN_BUF_SIZE];
|
||||
int ret;
|
||||
|
||||
ret = plain_hash_to_buffer(PTR, buf, PLAIN_BUF_SIZE);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0)
|
||||
return -1;
|
||||
|
||||
@@ -294,6 +308,23 @@ plain(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void __init
|
||||
test_hashed(const char *fmt, const void *p)
|
||||
{
|
||||
char buf[PLAIN_BUF_SIZE];
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* No need to increase failed test counter since this is assumed
|
||||
* to be called after plain().
|
||||
*/
|
||||
ret = plain_hash_to_buffer(p, buf, PLAIN_BUF_SIZE);
|
||||
if (ret)
|
||||
return;
|
||||
|
||||
test(buf, fmt, p);
|
||||
}
|
||||
|
||||
static void __init
|
||||
symbol_ptr(void)
|
||||
{
|
||||
@@ -418,6 +449,29 @@ struct_va_format(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void __init
|
||||
struct_rtc_time(void)
|
||||
{
|
||||
/* 1543210543 */
|
||||
const struct rtc_time tm = {
|
||||
.tm_sec = 43,
|
||||
.tm_min = 35,
|
||||
.tm_hour = 5,
|
||||
.tm_mday = 26,
|
||||
.tm_mon = 10,
|
||||
.tm_year = 118,
|
||||
};
|
||||
|
||||
test_hashed("%pt", &tm);
|
||||
|
||||
test("2018-11-26T05:35:43", "%ptR", &tm);
|
||||
test("0118-10-26T05:35:43", "%ptRr", &tm);
|
||||
test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
|
||||
test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm);
|
||||
test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm);
|
||||
test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm);
|
||||
}
|
||||
|
||||
static void __init
|
||||
struct_clk(void)
|
||||
{
|
||||
@@ -529,6 +583,7 @@ test_pointer(void)
|
||||
uuid();
|
||||
dentry();
|
||||
struct_va_format();
|
||||
struct_rtc_time();
|
||||
struct_clk();
|
||||
bitmap();
|
||||
netdev_features();
|
||||
|
Reference in New Issue
Block a user