chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hostnamed: allow UTF8 chars in pretty hostname again
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 15481b6b9d933350cfeccc3e5668e3b10512268e..1c97a8a94ae65386b7731c672e4e1248d7f65826 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-143,6
+143,10
@@
dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
usec_t timespec_load(const struct timespec *ts) {
assert(ts);
usec_t timespec_load(const struct timespec *ts) {
assert(ts);
+ if (ts->tv_sec == (time_t) -1 &&
+ ts->tv_nsec == (long) -1)
+ return (usec_t) -1;
+
return
(usec_t) ts->tv_sec * USEC_PER_SEC +
(usec_t) ts->tv_nsec / NSEC_PER_USEC;
return
(usec_t) ts->tv_sec * USEC_PER_SEC +
(usec_t) ts->tv_nsec / NSEC_PER_USEC;
@@
-151,6
+155,12
@@
usec_t timespec_load(const struct timespec *ts) {
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
assert(ts);
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
assert(ts);
+ if (u == (usec_t) -1) {
+ ts->tv_sec = (time_t) -1;
+ ts->tv_nsec = (long) -1;
+ return ts;
+ }
+
ts->tv_sec = (time_t) (u / USEC_PER_SEC);
ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
ts->tv_sec = (time_t) (u / USEC_PER_SEC);
ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
@@
-160,6
+170,10
@@
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
usec_t timeval_load(const struct timeval *tv) {
assert(tv);
usec_t timeval_load(const struct timeval *tv) {
assert(tv);
+ if (tv->tv_sec == (time_t) -1 &&
+ tv->tv_usec == (suseconds_t) -1)
+ return (usec_t) -1;
+
return
(usec_t) tv->tv_sec * USEC_PER_SEC +
(usec_t) tv->tv_usec;
return
(usec_t) tv->tv_sec * USEC_PER_SEC +
(usec_t) tv->tv_usec;
@@
-168,6
+182,12
@@
usec_t timeval_load(const struct timeval *tv) {
struct timeval *timeval_store(struct timeval *tv, usec_t u) {
assert(tv);
struct timeval *timeval_store(struct timeval *tv, usec_t u) {
assert(tv);
+ if (u == (usec_t) -1) {
+ tv->tv_sec = (time_t) -1;
+ tv->tv_usec = (suseconds_t) -1;
+ return tv;
+ }
+
tv->tv_sec = (time_t) (u / USEC_PER_SEC);
tv->tv_usec = (suseconds_t) (u % USEC_PER_SEC);
tv->tv_sec = (time_t) (u / USEC_PER_SEC);
tv->tv_usec = (suseconds_t) (u % USEC_PER_SEC);
@@
-1939,7
+1959,7
@@
char *format_timestamp(char *buf, size_t l, usec_t t) {
sec = (time_t) (t / USEC_PER_SEC);
sec = (time_t) (t / USEC_PER_SEC);
- if (strftime(buf, l, "%a, %
d %b %Y %H:%M:%S %z
", localtime_r(&sec, &tm)) <= 0)
+ if (strftime(buf, l, "%a, %
Y-%m-%d %H:%M:%S %Z
", localtime_r(&sec, &tm)) <= 0)
return NULL;
return buf;
return NULL;
return buf;
@@
-5909,7
+5929,7
@@
bool string_is_safe(const char *p) {
assert(p);
for (t = p; *t; t++) {
assert(p);
for (t = p; *t; t++) {
- if (*t < ' ')
+ if (*t
> 0 && *t
< ' ')
return false;
if (strchr("\\\"\'", *t))
return false;
if (strchr("\\\"\'", *t))