X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibudev%2Flibudev-util.c;h=b55bf75bfcf0aa21da12cf2e1bed8c5c1cc39d5d;hb=77e68fa2f0bd018bab2621a31919bfaa6a6b0a35;hp=8e6d5b621db4cc654b261994290e0d455c472cc8;hpb=c8f8394a9309d4390daac70b736b34d0b6734f95;p=elogind.git diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index 8e6d5b621..b55bf75bf 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2011 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include @@ -288,26 +296,6 @@ size_t util_path_encode(const char *src, char *dest, size_t size) return j; } -size_t util_path_decode(char *s) -{ - size_t i, j; - - for (i = 0, j = 0; s[i] != '\0'; j++) { - if (memcmp(&s[i], "\\x2f", 4) == 0) { - s[j] = '/'; - i += 4; - } else if (memcmp(&s[i], "\\x5c", 4) == 0) { - s[j] = '\\'; - i += 4; - } else { - s[j] = s[i]; - i++; - } - } - s[j] = '\0'; - return j; -} - void util_remove_trailing_chars(char *path, char c) { size_t len; @@ -333,14 +321,32 @@ size_t util_strpcpy(char **dest, size_t size, const char *src) if (size > 1) *dest = mempcpy(*dest, src, size-1); size = 0; - *dest[0] = '\0'; } else { if (len > 0) { *dest = mempcpy(*dest, src, len); size -= len; } - *dest[0] = '\0'; } + *dest[0] = '\0'; + return size; +} + +size_t util_strpcpyf(char **dest, size_t size, const char *src, ...) +{ + va_list va; + int i; + + va_start(va, src); + i = vsnprintf(*dest, size, src, va); + if (i < (int)size) { + *dest += i; + size -= i; + } else { + *dest += size; + size = 0; + } + va_end(va); + *dest[0] = '\0'; return size; } @@ -355,7 +361,6 @@ size_t util_strpcpyl(char **dest, size_t size, const char *src, ...) src = va_arg(va, char *); } while (src != NULL); va_end(va); - return size; } @@ -711,19 +716,27 @@ uint64_t util_string_bloom64(const char *str) return bits; } -#define USEC_PER_SEC 1000000ULL -#define NSEC_PER_USEC 1000ULL -unsigned long long ts_usec(const struct timespec *ts) +ssize_t print_kmsg(const char *fmt, ...) { - return (unsigned long long) ts->tv_sec * USEC_PER_SEC + - (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; -} + int fd; + va_list ap; + char text[1024]; + ssize_t len; + ssize_t ret; -unsigned long long now_usec(void) -{ - struct timespec ts; + fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC); + if (fd < 0) + return -errno; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - return 0; - return ts_usec(&ts); + len = snprintf(text, sizeof(text), "<30>systemd-udevd[%u]: ", getpid()); + + va_start(ap, fmt); + len += vsnprintf(text + len, sizeof(text) - len, fmt, ap); + va_end(ap); + + ret = write(fd, text, len); + if (ret < 0) + ret = -errno; + close(fd); + return ret; }