mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-02-26 05:43:09 +07:00
util: introduce format_timestamp()
This commit is contained in:
parent
bbd6713566
commit
8b6c71206d
18
util.c
18
util.c
@ -1258,6 +1258,24 @@ bool chars_intersect(const char *a, const char *b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char *format_timestamp(char *buf, size_t l, usec_t t) {
|
||||
struct tm tm;
|
||||
time_t sec;
|
||||
|
||||
assert(buf);
|
||||
assert(l > 0);
|
||||
|
||||
if (t <= 0)
|
||||
return NULL;
|
||||
|
||||
sec = (time_t) t / USEC_PER_SEC;
|
||||
|
||||
if (strftime(buf, l, "%a, %d %b %Y %H:%M:%S %z", localtime_r(&sec, &tm)) <= 0)
|
||||
return NULL;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static const char *const ioprio_class_table[] = {
|
||||
[IOPRIO_CLASS_NONE] = "none",
|
||||
[IOPRIO_CLASS_RT] = "realtime",
|
||||
|
4
util.h
4
util.h
@ -41,6 +41,8 @@ typedef uint64_t usec_t;
|
||||
#define WHITESPACE " \t\n\r"
|
||||
#define NEWLINE "\n\r"
|
||||
|
||||
#define FORMAT_TIMESTAMP_MAX 64
|
||||
|
||||
usec_t now(clockid_t clock);
|
||||
|
||||
usec_t timespec_load(const struct timespec *ts);
|
||||
@ -166,6 +168,8 @@ bool ignore_file(const char *filename);
|
||||
|
||||
bool chars_intersect(const char *a, const char *b);
|
||||
|
||||
char *format_timestamp(char *buf, size_t l, usec_t t);
|
||||
|
||||
#define DEFINE_STRING_TABLE_LOOKUP(name,type) \
|
||||
const char *name##_to_string(type i) { \
|
||||
if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
|
||||
|
Loading…
Reference in New Issue
Block a user