summaryrefslogtreecommitdiff
path: root/src/libudev/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libudev/util.c')
-rw-r--r--src/libudev/util.c132
1 files changed, 1 insertions, 131 deletions
diff --git a/src/libudev/util.c b/src/libudev/util.c
index a0d7cac697..4796505a5c 100644
--- a/src/libudev/util.c
+++ b/src/libudev/util.c
@@ -102,136 +102,6 @@ bool streq_ptr(const char *a, const char *b) {
return false;
}
-usec_t now(clockid_t clock_id) {
- struct timespec ts;
-
- assert_se(clock_gettime(clock_id, &ts) == 0);
-
- return timespec_load(&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;
-
- if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
- return (usec_t) -1;
-
- return
- (usec_t) ts->tv_sec * USEC_PER_SEC +
- (usec_t) ts->tv_nsec / NSEC_PER_USEC;
-}
-
-char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
- static const struct {
- const char *suffix;
- usec_t usec;
- } table[] = {
- { "y", USEC_PER_YEAR },
- { "month", USEC_PER_MONTH },
- { "w", USEC_PER_WEEK },
- { "d", USEC_PER_DAY },
- { "h", USEC_PER_HOUR },
- { "min", USEC_PER_MINUTE },
- { "s", USEC_PER_SEC },
- { "ms", USEC_PER_MSEC },
- { "us", 1 },
- };
-
- unsigned i;
- char *p = buf;
- bool something = false;
-
- assert(buf);
- assert(l > 0);
-
- if (t == (usec_t) -1)
- return NULL;
-
- if (t <= 0) {
- snprintf(p, l, "0");
- p[l-1] = 0;
- return p;
- }
-
- /* The result of this function can be parsed with parse_sec */
-
- for (i = 0; i < ELEMENTSOF(table); i++) {
- int k;
- size_t n;
- bool done = false;
- usec_t a, b;
-
- if (t <= 0)
- break;
-
- if (t < accuracy && something)
- break;
-
- if (t < table[i].usec)
- continue;
-
- if (l <= 1)
- break;
-
- a = t / table[i].usec;
- b = t % table[i].usec;
-
- /* Let's see if we should shows this in dot notation */
- if (t < USEC_PER_MINUTE && b > 0) {
- usec_t cc;
- int j;
-
- j = 0;
- for (cc = table[i].usec; cc > 1; cc /= 10)
- j++;
-
- for (cc = accuracy; cc > 1; cc /= 10) {
- b /= 10;
- j--;
- }
-
- if (j > 0) {
- k = snprintf(p, l,
- "%s%llu.%0*llu%s",
- p > buf ? " " : "",
- (unsigned long long) a,
- j,
- (unsigned long long) b,
- table[i].suffix);
-
- t = 0;
- done = true;
- }
- }
-
- /* No? Then let's show it normally */
- if (!done) {
- k = snprintf(p, l,
- "%s%llu%s",
- p > buf ? " " : "",
- (unsigned long long) a,
- table[i].suffix);
-
- t = b;
- }
-
- n = MIN((size_t) k, l);
-
- l -= n;
- p += n;
-
- something = true;
- }
-
- *p = 0;
-
- return buf;
-}
-
char* endswith(const char *s, const char *postfix) {
size_t sl, pl;
@@ -826,7 +696,7 @@ int execute_command(const char *command, char *const argv[])
} else
log_debug("%s exited successfully.", command);
- return si.si_status;
+ return si.si_status;
}
}