From d5a89d7dc17a5ba5cf4fc71f82963c5c94a31c3d Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 9 Jan 2013 19:06:46 +0100 Subject: udev: move string copy functions to shared/ --- src/libudev/libudev-device-private.c | 8 +-- src/libudev/libudev-device.c | 60 ++++++++++---------- src/libudev/libudev-enumerate.c | 12 ++-- src/libudev/libudev-private.h | 6 +- src/libudev/libudev-queue.c | 2 +- src/libudev/libudev-util.c | 99 +++------------------------------ src/shared/strxcpyx.c | 104 +++++++++++++++++++++++++++++++++++ src/shared/strxcpyx.h | 31 +++++++++++ src/test/test-udev.c | 2 +- src/udev/collect/collect.c | 2 +- src/udev/scsi_id/scsi_id.c | 8 +-- src/udev/udev-builtin-blkid.c | 2 +- src/udev/udev-builtin-btrfs.c | 2 +- src/udev/udev-builtin-firmware.c | 10 ++-- src/udev/udev-builtin-net_id.c | 20 +++---- src/udev/udev-builtin-usb_id.c | 10 ++-- src/udev/udev-builtin.c | 4 +- src/udev/udev-ctrl.c | 4 +- src/udev/udev-event.c | 58 +++++++++---------- src/udev/udev-node.c | 14 ++--- src/udev/udev-rules.c | 28 +++++----- src/udev/udevadm-info.c | 4 +- src/udev/udevadm-monitor.c | 2 +- src/udev/udevadm-test-builtin.c | 4 +- src/udev/udevadm-test.c | 4 +- src/udev/udevadm-trigger.c | 8 +-- src/udev/udevd.c | 14 ++--- 27 files changed, 285 insertions(+), 237 deletions(-) create mode 100644 src/shared/strxcpyx.c create mode 100644 src/shared/strxcpyx.h (limited to 'src') diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index c123057907..cba08d2f65 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -38,7 +38,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) id = udev_device_get_id_filename(dev); if (id == NULL) return; - util_strscpyl(filename, sizeof(filename), "/run/udev/tags/", tag, "/", id, NULL); + strscpyl(filename, sizeof(filename), "/run/udev/tags/", tag, "/", id, NULL); if (add) { int fd; @@ -116,7 +116,7 @@ int udev_device_update_db(struct udev_device *udev_device) return -1; has_info = device_has_info(udev_device); - util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); + strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); /* do not store anything for otherwise empty devices */ if (!has_info && @@ -127,7 +127,7 @@ int udev_device_update_db(struct udev_device *udev_device) } /* write a database file */ - util_strscpyl(filename_tmp, sizeof(filename_tmp), filename, ".tmp", NULL); + strscpyl(filename_tmp, sizeof(filename_tmp), filename, ".tmp", NULL); mkdir_parents(filename_tmp, 0755); f = fopen(filename_tmp, "we"); if (f == NULL) { @@ -186,7 +186,7 @@ int udev_device_delete_db(struct udev_device *udev_device) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); + strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); unlink(filename); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index f218b0278a..9fe3d633d4 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -379,7 +379,7 @@ static struct udev_list_entry *udev_device_add_property_from_string(struct udev_ char name[UTIL_LINE_SIZE]; char *val; - util_strscpy(name, sizeof(name), property); + strscpy(name, sizeof(name), property); val = strchr(name, '='); if (val == NULL) return NULL; @@ -404,7 +404,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, if (startswith(property, "DEVPATH=")) { char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), "/sys", &property[8], NULL); + strscpyl(path, sizeof(path), "/sys", &property[8], NULL); udev_device_set_syspath(udev_device, path); } else if (startswith(property, "SUBSYSTEM=")) { udev_device_set_subsystem(udev_device, &property[10]); @@ -417,7 +417,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, char *slink; char *next; - util_strscpy(devlinks, sizeof(devlinks), &property[9]); + strscpy(devlinks, sizeof(devlinks), &property[9]); slink = devlinks; next = strchr(slink, ' '); while (next != NULL) { @@ -432,7 +432,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, char tags[UTIL_PATH_SIZE]; char *next; - util_strscpy(tags, sizeof(tags), &property[5]); + strscpy(tags, sizeof(tags), &property[5]); next = strchr(tags, ':'); if (next != NULL) { next++; @@ -527,7 +527,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); + strscpyl(filename, sizeof(filename), "/run/udev/data/", id, NULL); dbfile = filename; } @@ -550,7 +550,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) val = &line[2]; switch(line[0]) { case 'S': - util_strscpyl(filename, sizeof(filename), "/dev/", val, NULL); + strscpyl(filename, sizeof(filename), "/dev/", val, NULL); udev_device_add_devlink(udev_device, filename); break; case 'L': @@ -588,7 +588,7 @@ int udev_device_read_uevent_file(struct udev_device *udev_device) if (udev_device->uevent_loaded) return 0; - util_strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL); + strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL); f = fopen(filename, "re"); if (f == NULL) return -1; @@ -702,14 +702,14 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; /* resolve possible symlink to real path */ - util_strscpy(path, sizeof(path), syspath); + strscpy(path, sizeof(path), syspath); util_resolve_sys_link(udev, path, sizeof(path)); if (startswith(path + strlen("/sys"), "/devices/")) { char file[UTIL_PATH_SIZE]; /* all "devices" require a "uevent" file */ - util_strscpyl(file, sizeof(file), path, "/uevent", NULL); + strscpyl(file, sizeof(file), path, "/uevent", NULL); if (stat(file, &statbuf) != 0) return NULL; } else { @@ -823,7 +823,7 @@ _public_ struct udev_device *udev_device_new_from_device_id(struct udev *udev, c return NULL; } case '+': - util_strscpy(subsys, sizeof(subsys), &id[1]); + strscpy(subsys, sizeof(subsys), &id[1]); sysname = strchr(subsys, ':'); if (sysname == NULL) return NULL; @@ -856,22 +856,22 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev struct stat statbuf; if (streq(subsystem, "subsystem")) { - util_strscpyl(path, sizeof(path), "/sys/subsystem/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/subsystem/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), "/sys/bus/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/bus/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), "/sys/class/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/class/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; goto out; } if (streq(subsystem, "module")) { - util_strscpyl(path, sizeof(path), "/sys/module/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/module/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; goto out; @@ -881,32 +881,32 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev char subsys[UTIL_NAME_SIZE]; char *driver; - util_strscpy(subsys, sizeof(subsys), sysname); + strscpy(subsys, sizeof(subsys), sysname); driver = strchr(subsys, ':'); if (driver != NULL) { driver[0] = '\0'; driver = &driver[1]; - util_strscpyl(path, sizeof(path), "/sys/subsystem/", subsys, "/drivers/", driver, NULL); + strscpyl(path, sizeof(path), "/sys/subsystem/", subsys, "/drivers/", driver, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), "/sys/bus/", subsys, "/drivers/", driver, NULL); + strscpyl(path, sizeof(path), "/sys/bus/", subsys, "/drivers/", driver, NULL); if (stat(path, &statbuf) == 0) goto found; } goto out; } - util_strscpyl(path, sizeof(path), "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), "/sys/bus/", subsystem, "/devices/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/bus/", subsystem, "/devices/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, sizeof(path), "/sys/class/", subsystem, "/", sysname, NULL); + strscpyl(path, sizeof(path), "/sys/class/", subsystem, "/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; out: @@ -957,7 +957,7 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic char path[UTIL_PATH_SIZE]; const char *subdir; - util_strscpy(path, sizeof(path), udev_device->syspath); + strscpy(path, sizeof(path), udev_device->syspath); subdir = path + strlen("/sys/"); for (;;) { char *pos; @@ -1260,9 +1260,9 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud size_t l; s = symlinks; - l = util_strpcpyl(&s, sizeof(symlinks), udev_list_entry_get_name(list_entry), NULL); + l = strpcpyl(&s, sizeof(symlinks), udev_list_entry_get_name(list_entry), NULL); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry), NULL); + l = strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry), NULL); udev_device_add_property(udev_device, "DEVLINKS", symlinks); } } @@ -1275,9 +1275,9 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud size_t l; s = tags; - l = util_strpcpyl(&s, sizeof(tags), ":", NULL); + l = strpcpyl(&s, sizeof(tags), ":", NULL); udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(udev_device)) - l = util_strpcpyl(&s, l, udev_list_entry_get_name(list_entry), ":", NULL); + l = strpcpyl(&s, l, udev_list_entry_get_name(list_entry), ":", NULL); udev_device_add_property(udev_device, "TAGS", tags); } } @@ -1374,7 +1374,7 @@ _public_ const char *udev_device_get_sysattr_value(struct udev_device *udev_devi if (list_entry != NULL) return udev_list_entry_get_value(list_entry); - util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL); + strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL); if (lstat(path, &statbuf) != 0) { udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, NULL); goto out; @@ -1400,7 +1400,7 @@ _public_ const char *udev_device_get_sysattr_value(struct udev_device *udev_devi /* resolve custom link to a device and return its syspath */ if (!streq(sysattr, "device")) { - util_strscpyl(path, sizeof(path), udev_device->syspath, "/", sysattr, NULL); + strscpyl(path, sizeof(path), udev_device->syspath, "/", sysattr, NULL); dev = udev_device_new_from_syspath(udev_device->udev, path); if (dev != NULL) { list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, @@ -1463,7 +1463,7 @@ static int udev_device_sysattr_list_read(struct udev_device *udev_device) if (dent->d_type != DT_LNK && dent->d_type != DT_REG) continue; - util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", dent->d_name, NULL); + strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", dent->d_name, NULL); if (lstat(path, &statbuf) != 0) continue; if ((statbuf.st_mode & S_IRUSR) == 0) @@ -1722,10 +1722,10 @@ static int update_envp_monitor_buf(struct udev_device *udev_device) return -EINVAL; /* add property string to monitor buffer */ - l = util_strpcpyl(&s, l, key, "=", udev_list_entry_get_value(list_entry), NULL); + l = strpcpyl(&s, l, key, "=", udev_list_entry_get_value(list_entry), NULL); if (l == 0) return -EINVAL; - /* advance past the trailing '\0' that util_strpcpyl() guarantees */ + /* advance past the trailing '\0' that strpcpyl() guarantees */ s++; l--; } diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 6a5f4e025e..2c1f7ab4ac 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -659,11 +659,11 @@ static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, struct dirent *dent; s = path; - l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL); + l = strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL); if (subdir1 != NULL) - l = util_strpcpyl(&s, l, "/", subdir1, NULL); + l = strpcpyl(&s, l, "/", subdir1, NULL); if (subdir2 != NULL) - util_strpcpyl(&s, l, "/", subdir2, NULL); + strpcpyl(&s, l, "/", subdir2, NULL); dir = opendir(path); if (dir == NULL) return -ENOENT; @@ -677,7 +677,7 @@ static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, if (!match_sysname(udev_enumerate, dent->d_name)) continue; - util_strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL); + strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL); dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath); if (dev == NULL) continue; @@ -738,7 +738,7 @@ static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, DIR *dir; struct dirent *dent; - util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL); + strscpyl(path, sizeof(path), "/sys/", basedir, NULL); dir = opendir(path); if (dir == NULL) return -1; @@ -789,7 +789,7 @@ static int scan_devices_tags(struct udev_enumerate *udev_enumerate) struct dirent *dent; char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL); + strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL); dir = opendir(path); if (dir == NULL) continue; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 1b86384703..54c51acc23 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -29,6 +29,7 @@ #include "macro.h" #include "util.h" #include "mkdir.h" +#include "strxcpyx.h" #define READ_END 0 #define WRITE_END 1 @@ -164,11 +165,6 @@ int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size); int util_log_priority(const char *priority); size_t util_path_encode(const char *src, char *dest, size_t size); void util_remove_trailing_chars(char *path, char c); -size_t util_strpcpy(char **dest, size_t size, const char *src); -size_t util_strpcpyf(char **dest, size_t size, const char *src, ...) __attribute__((format(printf, 3, 4))); -size_t util_strpcpyl(char **dest, size_t size, const char *src, ...) __attribute__((sentinel)); -size_t util_strscpy(char *dest, size_t size, const char *src); -size_t util_strscpyl(char *dest, size_t size, const char *src, ...) __attribute__((sentinel)); int util_replace_whitespace(const char *str, char *to, size_t len); int util_replace_chars(char *str, const char *white); unsigned int util_string_hash32(const char *key); diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 08d52ab1f1..bfb4807383 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -458,7 +458,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu snprintf(seqnum_str, sizeof(seqnum_str), "%llu", seqnum); s = syspath; - l = util_strpcpy(&s, sizeof(syspath), "/sys"); + l = strpcpy(&s, sizeof(syspath), "/sys"); len = udev_queue_read_devpath(queue_file, s, l); if (len < 0) break; diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index b55bf75bfc..2eb7907063 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -51,7 +51,7 @@ int util_delete_path(struct udev *udev, const char *path) if (path[0] == '/') while(path[1] == '/') path++; - util_strscpy(p, sizeof(p), path); + strscpy(p, sizeof(p), path); pos = strrchr(p, '/'); if (pos == p || pos == NULL) return 0; @@ -151,7 +151,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, if (string[0] != '[') return -1; - util_strscpy(temp, sizeof(temp), string); + strscpy(temp, sizeof(temp), string); subsys = &temp[1]; @@ -183,7 +183,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, val = udev_device_get_sysattr_value(dev, attr); if (val != NULL) - util_strscpy(result, maxsize, val); + strscpy(result, maxsize, val); else result[0] = '\0'; udev_dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); @@ -192,9 +192,9 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *s; s = result; - l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL); + l = strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL); if (attr != NULL) - util_strpcpyl(&s, l, "/", attr, NULL); + strpcpyl(&s, l, "/", attr, NULL); udev_dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); } udev_device_unref(dev); @@ -207,7 +207,7 @@ ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const ssize_t len; const char *pos; - util_strscpyl(path, sizeof(path), syspath, "/", slink, NULL); + strscpyl(path, sizeof(path), syspath, "/", slink, NULL); len = readlink(path, target, sizeof(target)); if (len <= 0 || len == (ssize_t)sizeof(target)) return -1; @@ -216,7 +216,7 @@ ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const if (pos == NULL) return -1; pos = &pos[1]; - return util_strscpy(value, size, pos); + return strscpy(value, size, pos); } int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size) @@ -243,7 +243,7 @@ int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size) } if (base == NULL) return -EINVAL; - util_strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL); + strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL); return 0; } @@ -307,89 +307,6 @@ void util_remove_trailing_chars(char *path, char c) path[--len] = '\0'; } -/* - * Concatenates strings. In any case, terminates in _all_ cases with '\0' - * and moves the @dest pointer forward to the added '\0'. Returns the - * remaining size, and 0 if the string was truncated. - */ -size_t util_strpcpy(char **dest, size_t size, const char *src) -{ - size_t len; - - len = strlen(src); - if (len >= size) { - if (size > 1) - *dest = mempcpy(*dest, src, size-1); - size = 0; - } else { - if (len > 0) { - *dest = mempcpy(*dest, src, len); - size -= len; - } - } - *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; -} - -/* concatenates list of strings, moves dest forward */ -size_t util_strpcpyl(char **dest, size_t size, const char *src, ...) -{ - va_list va; - - va_start(va, src); - do { - size = util_strpcpy(dest, size, src); - src = va_arg(va, char *); - } while (src != NULL); - va_end(va); - return size; -} - -/* copies string */ -size_t util_strscpy(char *dest, size_t size, const char *src) -{ - char *s; - - s = dest; - return util_strpcpy(&s, size, src); -} - -/* concatenates list of strings */ -size_t util_strscpyl(char *dest, size_t size, const char *src, ...) -{ - va_list va; - char *s; - - va_start(va, src); - s = dest; - do { - size = util_strpcpy(&s, size, src); - src = va_arg(va, char *); - } while (src != NULL); - va_end(va); - - return size; -} - /* count of characters used to encode one unicode char */ static int utf8_encoded_expected_len(const char *str) { diff --git a/src/shared/strxcpyx.c b/src/shared/strxcpyx.c new file mode 100644 index 0000000000..3cb04b25cd --- /dev/null +++ b/src/shared/strxcpyx.c @@ -0,0 +1,104 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2013 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 . +***/ + +/* + * Concatenates/copies strings. In any case, terminates in all cases + * with '\0' * and moves the @dest pointer forward to the added '\0'. + * Returns the * remaining size, and 0 if the string was truncated. + */ + +#include +#include +#include "strxcpyx.h" + +size_t strpcpy(char **dest, size_t size, const char *src) +{ + size_t len; + + len = strlen(src); + if (len >= size) { + if (size > 1) + *dest = mempcpy(*dest, src, size-1); + size = 0; + } else { + if (len > 0) { + *dest = mempcpy(*dest, src, len); + size -= len; + } + } + *dest[0] = '\0'; + return size; +} + +size_t 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; +} + +size_t strpcpyl(char **dest, size_t size, const char *src, ...) +{ + va_list va; + + va_start(va, src); + do { + size = strpcpy(dest, size, src); + src = va_arg(va, char *); + } while (src != NULL); + va_end(va); + return size; +} + +size_t strscpy(char *dest, size_t size, const char *src) +{ + char *s; + + s = dest; + return strpcpy(&s, size, src); +} + +size_t strscpyl(char *dest, size_t size, const char *src, ...) { + va_list va; + char *s; + + va_start(va, src); + s = dest; + do { + size = strpcpy(&s, size, src); + src = va_arg(va, char *); + } while (src != NULL); + va_end(va); + + return size; +} diff --git a/src/shared/strxcpyx.h b/src/shared/strxcpyx.h new file mode 100644 index 0000000000..1229a4821d --- /dev/null +++ b/src/shared/strxcpyx.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2013 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 + +size_t strpcpy(char **dest, size_t size, const char *src); +size_t strpcpyf(char **dest, size_t size, const char *src, ...) __attribute__((format(printf, 3, 4))); +size_t strpcpyl(char **dest, size_t size, const char *src, ...) __attribute__((sentinel)); +size_t strscpy(char *dest, size_t size, const char *src); +size_t strscpyl(char *dest, size_t size, const char *src, ...) __attribute__((sentinel)); diff --git a/src/test/test-udev.c b/src/test/test-udev.c index db9d36124e..7cb93edc1d 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) rules = udev_rules_new(udev, 1); - util_strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL); + strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL); dev = udev_device_new_from_syspath(udev, syspath); if (dev == NULL) { log_debug("unknown device '%s'\n", devpath); diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 3c46e40de1..f594814dbe 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -414,7 +414,7 @@ int main(int argc, char **argv) if (debug) fprintf(stderr, "Using checkpoint '%s'\n", checkpoint); - util_strscpyl(tmpdir, sizeof(tmpdir), "/run/udev/collect", NULL); + strscpyl(tmpdir, sizeof(tmpdir), "/run/udev/collect", NULL); fd = prepare(tmpdir, checkpoint); if (fd < 0) { ret = 3; diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index c90b6aa581..fa0413c462 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -108,7 +108,7 @@ static void set_type(const char *from, char *to, size_t len) break; } } - util_strscpy(to, len, type); + strscpy(to, len, type); } /* @@ -341,7 +341,7 @@ static int set_options(struct udev *udev, case 'd': dev_specified = 1; - util_strscpy(maj_min_dev, MAX_PATH_LEN, optarg); + strscpy(maj_min_dev, MAX_PATH_LEN, optarg); break; case 'e': @@ -349,7 +349,7 @@ static int set_options(struct udev *udev, break; case 'f': - util_strscpy(config_file, MAX_PATH_LEN, optarg); + strscpy(config_file, MAX_PATH_LEN, optarg); break; case 'g': @@ -415,7 +415,7 @@ static int set_options(struct udev *udev, } if (optind < argc && !dev_specified) { dev_specified = 1; - util_strscpy(maj_min_dev, MAX_PATH_LEN, argv[optind]); + strscpy(maj_min_dev, MAX_PATH_LEN, argv[optind]); } return 0; } diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index 4293103046..56a05f5e50 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -76,7 +76,7 @@ static void print_property(struct udev_device *dev, bool test, const char *name, udev_builtin_add_property(dev, test, "ID_PART_ENTRY_TYPE", s); } else if (startswith(name, "PART_ENTRY_")) { - util_strscpyl(s, sizeof(s), "ID_", name, NULL); + strscpyl(s, sizeof(s), "ID_", name, NULL); udev_builtin_add_property(dev, test, s, value); } } diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index dfb05525ad..f7bea69b26 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -48,7 +48,7 @@ static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool t if (fd < 0) return EXIT_FAILURE; - util_strscpy(args.name, sizeof(args.name), argv[2]); + strscpy(args.name, sizeof(args.name), argv[2]); err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args); close(fd); if (err < 0) diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c index 4a91d33575..9cb4294633 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -100,20 +100,20 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo /* lookup firmware file */ uname(&kernel); for (i = 0; i < ELEMENTSOF(searchpath); i++) { - util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL); + strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL); fwfile = fopen(fwpath, "re"); if (fwfile != NULL) break; - util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL); + strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL); fwfile = fopen(fwpath, "re"); if (fwfile != NULL) break; } util_path_encode(firmware, fwencpath, sizeof(fwencpath)); - util_strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL); - util_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); + strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL); + strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); if (fwfile == NULL) { int err; @@ -152,7 +152,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo if (!set_loading(udev, loadpath, "1")) goto exit; - util_strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL); + strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL); if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) { log_error("error sending firmware '%s' to device\n", firmware); set_loading(udev, loadpath, "-1"); diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 7c9564f4cd..a5da291497 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -183,11 +183,11 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { /* compose a name based on the raw kernel's PCI bus, slot numbers */ s = names->pci_path; - l = util_strpcpyf(&s, sizeof(names->pci_path), "p%ds%d", bus, slot); + l = strpcpyf(&s, sizeof(names->pci_path), "p%ds%d", bus, slot); if (func > 0 || is_pci_multifunction(names->pcidev)) - l = util_strpcpyf(&s, l, "f%d", func); + l = strpcpyf(&s, l, "f%d", func); if (dev_id > 0) - l = util_strpcpyf(&s, l, "d%d", dev_id); + l = strpcpyf(&s, l, "d%d", dev_id); if (l == 0) names->pci_path[0] = '\0'; @@ -231,11 +231,11 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { if (hotplug_slot > 0) { s = names->pci_slot; - l = util_strpcpyf(&s, sizeof(names->pci_slot), "s%d", hotplug_slot); + l = strpcpyf(&s, sizeof(names->pci_slot), "s%d", hotplug_slot); if (func > 0 || is_pci_multifunction(names->pcidev)) - l = util_strpcpyf(&s, l, "f%d", func); + l = strpcpyf(&s, l, "f%d", func); if (dev_id > 0) - l = util_strpcpyf(&s, l, "d%d", dev_id); + l = strpcpyf(&s, l, "d%d", dev_id); if (l == 0) names->pci_path[0] = '\0'; } @@ -277,7 +277,7 @@ static int names_usb(struct udev_device *dev, struct netnames *names) { return -ENOENT; /* get USB port number chain, configuration, interface */ - util_strscpy(name, sizeof(name), udev_device_get_sysname(names->usbdev)); + strscpy(name, sizeof(name), udev_device_get_sysname(names->usbdev)); s = strchr(name, '-'); if (!s) return -EINVAL; @@ -300,15 +300,15 @@ static int names_usb(struct udev_device *dev, struct netnames *names) { while ((s = strchr(s, '.'))) s[0] = 'u'; s = names->usb_ports; - l = util_strpcpyl(&s, sizeof(names->usb_ports), "u", ports, NULL); + l = strpcpyl(&s, sizeof(names->usb_ports), "u", ports, NULL); /* append USB config number, suppress the common config == 1 */ if (!streq(config, "1")) - l = util_strpcpyl(&s, sizeof(names->usb_ports), "c", config, NULL); + l = strpcpyl(&s, sizeof(names->usb_ports), "c", config, NULL); /* append USB interface number, suppress the interface == 0 */ if (!streq(interf, "0")) - l = util_strpcpyl(&s, sizeof(names->usb_ports), "i", interf, NULL); + l = strpcpyl(&s, sizeof(names->usb_ports), "i", interf, NULL); if (l == 0) return -ENAMETOOLONG; diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index 13d1226393..7ce401d152 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -111,7 +111,7 @@ static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len break; } } - util_strscpy(to, len, type); + strscpy(to, len, type); return type_num; } @@ -143,7 +143,7 @@ static void set_scsi_type(char *to, const char *from, size_t len) break; } } - util_strscpy(to, len, type); + strscpy(to, len, type); } #define USB_DT_DEVICE 0x01 @@ -438,12 +438,12 @@ fallback: } s = serial; - l = util_strpcpyl(&s, sizeof(serial), vendor_str, "_", model_str, NULL); + l = strpcpyl(&s, sizeof(serial), vendor_str, "_", model_str, NULL); if (serial_str[0] != '\0') - l = util_strpcpyl(&s, l, "_", serial_str, NULL); + l = strpcpyl(&s, l, "_", serial_str, NULL); if (instance_str[0] != '\0') - util_strpcpyl(&s, l, "-", instance_str, NULL); + strpcpyl(&s, l, "-", instance_str, NULL); udev_builtin_add_property(dev, test, "ID_VENDOR", vendor_str); udev_builtin_add_property(dev, test, "ID_VENDOR_ENC", vendor_str_enc); diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index 32e6e1e90c..0651ae2ff0 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -110,7 +110,7 @@ enum udev_builtin_cmd udev_builtin_lookup(const char *command) enum udev_builtin_cmd i; char *pos; - util_strscpy(name, sizeof(name), command); + strscpy(name, sizeof(name), command); pos = strchr(name, ' '); if (pos) pos[0] = '\0'; @@ -128,7 +128,7 @@ int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const c /* we need '0' here to reset the internal state */ optind = 0; - util_strscpy(arg, sizeof(arg), command); + strscpy(arg, sizeof(arg), command); udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv); return builtins[cmd]->cmd(dev, argc, argv, test); } diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index a235912ffb..6ee6b04b1b 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -93,7 +93,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) } uctrl->saddr.sun_family = AF_LOCAL; - util_strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control"); + strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control"); uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path); return uctrl; } @@ -250,7 +250,7 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int ctrl_msg_wire.type = type; if (buf != NULL) - util_strscpy(ctrl_msg_wire.buf, sizeof(ctrl_msg_wire.buf), buf); + strscpy(ctrl_msg_wire.buf, sizeof(ctrl_msg_wire.buf), buf); else ctrl_msg_wire.intval = intval; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 5eedf4f0df..8c8b058df7 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -191,20 +191,20 @@ subst: switch (type) { case SUBST_DEVPATH: - l = util_strpcpy(&s, l, udev_device_get_devpath(dev)); + l = strpcpy(&s, l, udev_device_get_devpath(dev)); break; case SUBST_KERNEL: - l = util_strpcpy(&s, l, udev_device_get_sysname(dev)); + l = strpcpy(&s, l, udev_device_get_sysname(dev)); break; case SUBST_KERNEL_NUMBER: if (udev_device_get_sysnum(dev) == NULL) break; - l = util_strpcpy(&s, l, udev_device_get_sysnum(dev)); + l = strpcpy(&s, l, udev_device_get_sysnum(dev)); break; case SUBST_ID: if (event->dev_parent == NULL) break; - l = util_strpcpy(&s, l, udev_device_get_sysname(event->dev_parent)); + l = strpcpy(&s, l, udev_device_get_sysname(event->dev_parent)); break; case SUBST_DRIVER: { const char *driver; @@ -215,21 +215,21 @@ subst: driver = udev_device_get_driver(event->dev_parent); if (driver == NULL) break; - l = util_strpcpy(&s, l, driver); + l = strpcpy(&s, l, driver); break; } case SUBST_MAJOR: { char num[UTIL_PATH_SIZE]; sprintf(num, "%d", major(udev_device_get_devnum(dev))); - l = util_strpcpy(&s, l, num); + l = strpcpy(&s, l, num); break; } case SUBST_MINOR: { char num[UTIL_PATH_SIZE]; sprintf(num, "%d", minor(udev_device_get_devnum(dev))); - l = util_strpcpy(&s, l, num); + l = strpcpy(&s, l, num); break; } case SUBST_RESULT: { @@ -247,7 +247,7 @@ subst: char tmp[UTIL_PATH_SIZE]; char *cpos; - util_strscpy(result, sizeof(result), event->program_result); + strscpy(result, sizeof(result), event->program_result); cpos = result; while (--i) { while (cpos[0] != '\0' && !isspace(cpos[0])) @@ -259,16 +259,16 @@ subst: log_error("requested part of result string not found\n"); break; } - util_strscpy(tmp, sizeof(tmp), cpos); + strscpy(tmp, sizeof(tmp), cpos); /* %{2+}c copies the whole string from the second part on */ if (rest[0] != '+') { cpos = strchr(tmp, ' '); if (cpos) cpos[0] = '\0'; } - l = util_strpcpy(&s, l, tmp); + l = strpcpy(&s, l, tmp); } else { - l = util_strpcpy(&s, l, event->program_result); + l = strpcpy(&s, l, event->program_result); } break; } @@ -300,14 +300,14 @@ subst: /* strip trailing whitespace, and replace unwanted characters */ if (value != vbuf) - util_strscpy(vbuf, sizeof(vbuf), value); + strscpy(vbuf, sizeof(vbuf), value); len = strlen(vbuf); while (len > 0 && isspace(vbuf[--len])) vbuf[len] = '\0'; count = util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT); if (count > 0) log_debug("%i character(s) replaced\n" , count); - l = util_strpcpy(&s, l, vbuf); + l = strpcpy(&s, l, vbuf); break; } case SUBST_PARENT: { @@ -319,20 +319,20 @@ subst: break; devnode = udev_device_get_devnode(dev_parent); if (devnode != NULL) - l = util_strpcpy(&s, l, devnode + strlen("/dev/")); + l = strpcpy(&s, l, devnode + strlen("/dev/")); break; } case SUBST_DEVNODE: if (udev_device_get_devnode(dev) != NULL) - l = util_strpcpy(&s, l, udev_device_get_devnode(dev)); + l = strpcpy(&s, l, udev_device_get_devnode(dev)); break; case SUBST_NAME: if (event->name != NULL) - l = util_strpcpy(&s, l, event->name); + l = strpcpy(&s, l, event->name); else if (udev_device_get_devnode(dev) != NULL) - l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen("/dev/")); + l = strpcpy(&s, l, udev_device_get_devnode(dev) + strlen("/dev/")); else - l = util_strpcpy(&s, l, udev_device_get_sysname(dev)); + l = strpcpy(&s, l, udev_device_get_sysname(dev)); break; case SUBST_LINKS: { struct udev_list_entry *list_entry; @@ -340,16 +340,16 @@ subst: list_entry = udev_device_get_devlinks_list_entry(dev); if (list_entry == NULL) break; - l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen("/dev/")); + l = strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen("/dev/")); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen("/dev/"), NULL); + l = strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen("/dev/"), NULL); break; } case SUBST_ROOT: - l = util_strpcpy(&s, l, "/dev"); + l = strpcpy(&s, l, "/dev"); break; case SUBST_SYS: - l = util_strpcpy(&s, l, "/sys"); + l = strpcpy(&s, l, "/sys"); break; case SUBST_ENV: if (attr == NULL) { @@ -360,7 +360,7 @@ subst: value = udev_device_get_property_value(event->dev, attr); if (value == NULL) break; - l = util_strpcpy(&s, l, value); + l = strpcpy(&s, l, value); break; } default: @@ -667,7 +667,7 @@ int udev_event_spawn(struct udev_event *event, char program[UTIL_PATH_SIZE]; int err = 0; - util_strscpy(arg, sizeof(arg), cmd); + strscpy(arg, sizeof(arg), cmd); udev_build_argv(event->udev, arg, NULL, argv); /* pipes from child to parent */ @@ -688,7 +688,7 @@ int udev_event_spawn(struct udev_event *event, /* allow programs in /usr/lib/udev/ to be called without the path */ if (argv[0][0] != '/') { - util_strscpyl(program, sizeof(program), UDEVLIBEXECDIR "/", argv[0], NULL); + strscpyl(program, sizeof(program), UDEVLIBEXECDIR "/", argv[0], NULL); argv[0] = program; } @@ -763,8 +763,8 @@ static int rename_netif(struct udev_event *event) } memset(&ifr, 0x00, sizeof(struct ifreq)); - util_strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev)); - util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); + strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev)); + strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); err = ioctl(sk, SIOCSIFNAME, &ifr); if (err >= 0) { print_kmsg("renamed network interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname); @@ -825,11 +825,11 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, udev_device_add_property(dev, "INTERFACE_OLD", udev_device_get_sysname(dev)); /* now change the devpath, because the kernel device name has changed */ - util_strscpy(syspath, sizeof(syspath), udev_device_get_syspath(dev)); + strscpy(syspath, sizeof(syspath), udev_device_get_syspath(dev)); pos = strrchr(syspath, '/'); if (pos != NULL) { pos++; - util_strscpy(pos, sizeof(syspath) - (pos - syspath), event->name); + strscpy(pos, sizeof(syspath) - (pos - syspath), event->name); udev_device_set_syspath(event->dev, syspath); udev_device_add_property(dev, "INTERFACE", udev_device_get_sysname(dev)); log_debug("changed devpath to '%s'\n", udev_device_get_devpath(dev)); diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 1e378adf29..3eec14021b 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -55,10 +55,10 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) l = sizeof(target); while (slink[i] != '\0') { if (slink[i] == '/') - l = util_strpcpy(&s, l, "../"); + l = strpcpy(&s, l, "../"); i++; } - l = util_strscpy(s, l, &node[tail]); + l = strscpy(s, l, &node[tail]); if (l == 0) { err = -EINVAL; goto exit; @@ -101,7 +101,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) } log_debug("atomically replace '%s'\n", slink); - util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL); + strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL); unlink(slink_tmp); do { err = mkdir_parents_label(slink_tmp, 0755); @@ -136,7 +136,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons if (add) { priority = udev_device_get_devlink_priority(dev); - util_strscpy(buf, bufsize, udev_device_get_devnode(dev)); + strscpy(buf, bufsize, udev_device_get_devnode(dev)); target = buf; } @@ -169,7 +169,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons log_debug("'%s' claims priority %i for '%s'\n", udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir); priority = udev_device_get_devlink_priority(dev_db); - util_strscpy(buf, bufsize, devnode); + strscpy(buf, bufsize, devnode); target = buf; } } @@ -191,8 +191,8 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) char buf[UTIL_PATH_SIZE]; util_path_encode(slink + strlen("/dev"), name_enc, sizeof(name_enc)); - util_strscpyl(dirname, sizeof(dirname), "/run/udev/links/", name_enc, NULL); - util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); + strscpyl(dirname, sizeof(dirname), "/run/udev/links/", name_enc, NULL); + strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); if (!add && unlink(filename) == 0) rmdir(dirname); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 9743243a37..bb57d2af48 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -600,7 +600,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) log_debug("updating devpath from '%s' to '%s'\n", udev_device_get_devpath(dev), val); - util_strscpyl(syspath, sizeof(syspath), "/sys", val, NULL); + strscpyl(syspath, sizeof(syspath), "/sys", val, NULL); udev_device_set_syspath(dev, syspath); } else { struct udev_list_entry *entry; @@ -691,8 +691,8 @@ static int wait_for_file(struct udev_device *dev, const char *file, int timeout) /* a relative path is a device attribute */ devicepath[0] = '\0'; if (file[0] != '/') { - util_strscpyl(devicepath, sizeof(devicepath), udev_device_get_syspath(dev), NULL); - util_strscpyl(filepath, sizeof(filepath), devicepath, "/", file, NULL); + strscpyl(devicepath, sizeof(devicepath), udev_device_get_syspath(dev), NULL); + strscpyl(filepath, sizeof(filepath), devicepath, "/", file, NULL); file = filepath; } @@ -726,7 +726,7 @@ static int attr_subst_subdir(char *attr, size_t len) const char *tail; DIR *dir; - util_strscpy(dirname, sizeof(dirname), attr); + strscpy(dirname, sizeof(dirname), attr); pos = strstr(dirname, "/*/"); if (pos == NULL) return -1; @@ -741,7 +741,7 @@ static int attr_subst_subdir(char *attr, size_t len) if (dent->d_name[0] == '.') continue; - util_strscpyl(attr, len, dirname, "/", dent->d_name, tail, NULL); + strscpyl(attr, len, dirname, "/", dent->d_name, tail, NULL); if (stat(attr, &stats) == 0) { found = true; break; @@ -1752,7 +1752,7 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * { char value[UTIL_PATH_SIZE]; - util_strscpy(value, sizeof(value), rules_str(rules, token->key.value_off)); + strscpy(value, sizeof(value), rules_str(rules, token->key.value_off)); key_value = value; while (key_value != NULL) { pos = strchr(key_value, '|'); @@ -1819,7 +1819,7 @@ static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct klen = strlen(key_value); if (klen > 0 && !isspace(key_value[klen-1])) { if (value != vbuf) { - util_strscpy(vbuf, sizeof(vbuf), value); + strscpy(vbuf, sizeof(vbuf), value); value = vbuf; } while (len > 0 && isspace(vbuf[--len])) @@ -2015,8 +2015,8 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (filename[0] != '/') { char tmp[UTIL_PATH_SIZE]; - util_strscpy(tmp, sizeof(tmp), filename); - util_strscpyl(filename, sizeof(filename), + strscpy(tmp, sizeof(tmp), filename); + strscpyl(filename, sizeof(filename), udev_device_get_syspath(event->dev), "/", tmp, NULL); } } @@ -2328,7 +2328,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event /* append value separated by space */ udev_event_apply_format(event, value, temp, sizeof(temp)); - util_strscpyl(value_new, sizeof(value_new), value_old, " ", temp, NULL); + strscpyl(value_new, sizeof(value_new), value_old, " ", temp, NULL); } else udev_event_apply_format(event, value, value_new, sizeof(value_new)); @@ -2419,7 +2419,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event next[0] = '\0'; log_debug("LINK '%s' %s:%u\n", pos, rules_str(rules, rule->rule.filename_off), rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); + strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename); while (isspace(next[1])) next++; @@ -2429,7 +2429,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (pos[0] != '\0') { log_debug("LINK '%s' %s:%u\n", pos, rules_str(rules, rule->rule.filename_off), rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); + strscpyl(filename, sizeof(filename), "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename); } break; @@ -2441,7 +2441,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event FILE *f; if (util_resolve_subsys_kernel(event->udev, key_name, attr, sizeof(attr), 0) != 0) - util_strscpyl(attr, sizeof(attr), udev_device_get_syspath(event->dev), "/", key_name, NULL); + strscpyl(attr, sizeof(attr), udev_device_get_syspath(event->dev), "/", key_name, NULL); attr_subst_subdir(attr, sizeof(attr)); udev_event_apply_format(event, rules_str(rules, cur->key.value_off), value, sizeof(value)); @@ -2539,7 +2539,7 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules) /* we assure, that the permissions tokens are sorted before the static token */ if (mode == 0 && uid == 0 && gid == 0) goto next; - util_strscpyl(filename, sizeof(filename), "/dev/", rules_str(rules, cur->key.value_off), NULL); + strscpyl(filename, sizeof(filename), "/dev/", rules_str(rules, cur->key.value_off), NULL); if (stat(filename, &stats) != 0) goto next; if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode)) diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 95f077ca95..d6f82869b1 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -269,7 +269,7 @@ static struct udev_device *find_device(struct udev *udev, const char *id, const char name[UTIL_PATH_SIZE]; if (prefix && !startswith(id, prefix)) { - util_strscpyl(name, sizeof(name), prefix, id, NULL); + strscpyl(name, sizeof(name), prefix, id, NULL); id = name; } @@ -414,7 +414,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) break; case 'd': action = ACTION_DEVICE_ID_FILE; - util_strscpy(name, sizeof(name), optarg); + strscpy(name, sizeof(name), optarg); break; case 'a': action = ACTION_ATTRIBUTE_WALK; diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index ffa70d8300..a390ee6c34 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -116,7 +116,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) char subsys[UTIL_NAME_SIZE]; char *devtype; - util_strscpy(subsys, sizeof(subsys), optarg); + strscpy(subsys, sizeof(subsys), optarg); devtype = strchr(subsys, '/'); if (devtype != NULL) { devtype[0] = '\0'; diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 9853d83b49..f4aa21ee72 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -96,9 +96,9 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) /* add /sys if needed */ if (!startswith(syspath, "/sys")) - util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); + strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else - util_strscpy(filename, sizeof(filename), syspath); + strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); dev = udev_device_new_from_syspath(udev, filename); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 2d8aa7913e..f22a2c32cc 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -113,9 +113,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) /* add /sys if needed */ if (!startswith(syspath, "/sys")) - util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); + strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else - util_strscpy(filename, sizeof(filename), syspath); + strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); dev = udev_device_new_from_syspath(udev, filename); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index d52ae461fe..4d96a786c3 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -48,7 +48,7 @@ static void exec_list(struct udev_enumerate *udev_enumerate, const char *action) printf("%s\n", udev_list_entry_get_name(entry)); if (dry_run) continue; - util_strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL); + strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL); fd = open(filename, O_WRONLY); if (fd < 0) continue; @@ -62,7 +62,7 @@ static const char *keyval(const char *str, const char **val, char *buf, size_t s { char *pos; - util_strscpy(buf, size,str); + strscpy(buf, size,str); pos = strchr(buf, '='); if (pos != NULL) { pos[0] = 0; @@ -165,9 +165,9 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) /* add sys dir if needed */ if (!startswith(optarg, "/sys")) - util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); + strscpyl(path, sizeof(path), "/sys", optarg, NULL); else - util_strscpy(path, sizeof(path), optarg); + strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); dev = udev_device_new_from_syspath(udev, path); if (dev == NULL) { diff --git a/src/udev/udevd.c b/src/udev/udevd.c index ffc48a03bd..9f184621ae 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -726,7 +726,7 @@ static int handle_inotify(struct udev *udev) int fd; log_debug("device %s closed, synthesising 'change'\n", udev_device_get_devnode(dev)); - util_strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL); + strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL); fd = open(filename, O_WRONLY); if (fd >= 0) { if (write(fd, "change", 6) < 0) @@ -813,7 +813,7 @@ static void static_dev_create_from_modules(struct udev *udev) FILE *f; uname(&kernel); - util_strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL); + strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL); f = fopen(modules, "re"); if (f == NULL) return; @@ -860,7 +860,7 @@ static void static_dev_create_from_modules(struct udev *udev) else continue; - util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL); + strscpyl(filename, sizeof(filename), "/dev/", devname, NULL); mkdir_parents_label(filename, 0755); label_context_set(filename, mode); log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min); @@ -909,7 +909,7 @@ static int convert_db(struct udev *udev) mkdir_p("/run/udev/data", 0755); /* old database */ - util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL); + strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL); if (access(filename, F_OK) < 0) return 0; @@ -938,7 +938,7 @@ static int convert_db(struct udev *udev) /* find database in old location */ id = udev_device_get_id_filename(device); - util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL); + strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -948,7 +948,7 @@ static int convert_db(struct udev *udev) } /* find old database with $subsys:$sysname name */ - util_strscpyl(from, sizeof(from), "/dev/.udev/db/", + strscpyl(from, sizeof(from), "/dev/.udev/db/", udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL); if (lstat(from, &stats) == 0) { if (!have_db) { @@ -960,7 +960,7 @@ static int convert_db(struct udev *udev) /* find old database with the encoded devpath name */ util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath)); - util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL); + strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); -- cgit v1.2.3-54-g00ecf