From faa1ff8ef8d98fe148ac0efab15fcdf0cabdcaae Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sun, 7 Jul 2013 11:07:06 -0400 Subject: [PATCH] Import strxcpyx from upstream This commit imports strxcpyx from upstream. This is upstream commit d5a89d7dc17a5ba5cf4fc71f82963c5c94a31c3d Note: there were also some very minor code cleanups to accelerometer.c: line 187 collect.c: lines 35, 140 libudev-device.c: line 780 libudev-hwdb.c: line 300 These are part of upstream commits: 507f22bd0172bff5e5d98145b1419bd472a2c57f 3cf7b686e6b29f78de0af5929602cae4482f6d49 67410e9f73a6cdd8453c78b966451b5151def14a Signed-off-by: Anthony G. Basile --- .gitignore | 3 + src/accelerometer/accelerometer.c | 4 +- src/collect/collect.c | 16 +++-- src/gudev/gudevclient.h | 11 ++- src/libudev/Makefile.am | 2 + src/libudev/libudev-device-private.c | 8 +-- src/libudev/libudev-device.c | 62 ++++++++-------- src/libudev/libudev-enumerate.c | 14 ++-- src/libudev/libudev-hwdb.c | 16 +++-- src/libudev/libudev-monitor.c | 8 +-- src/libudev/libudev-private.h | 5 -- src/libudev/libudev-queue.c | 4 +- src/libudev/libudev-util.c | 103 +++----------------------- src/libudev/libudev.c | 2 +- src/libudev/libudev.h | 2 +- src/libudev/strxcpyx.c | 104 +++++++++++++++++++++++++++ src/libudev/strxcpyx.h | 31 ++++++++ src/libudev/util.h | 3 + src/scsi_id/scsi_id.c | 34 ++++----- src/scsi_id/scsi_serial.c | 2 +- src/udev/udev-builtin-blkid.c | 2 +- src/udev/udev-builtin-btrfs.c | 2 +- src/udev/udev-builtin-firmware.c | 8 +-- src/udev/udev-builtin-kmod.c | 2 +- src/udev/udev-builtin-net_id.c | 28 ++++---- src/udev/udev-builtin-path_id.c | 28 ++++---- src/udev/udev-builtin-usb_id.c | 14 ++-- src/udev/udev-builtin.c | 6 +- src/udev/udev-ctrl.c | 4 +- src/udev/udev-event.c | 73 ++++++++++--------- src/udev/udev-node.c | 26 +++---- src/udev/udev-rules.c | 30 ++++---- src/udev/udevadm-info.c | 16 ++--- src/udev/udevadm-monitor.c | 2 +- src/udev/udevadm-test-builtin.c | 4 +- src/udev/udevadm-test.c | 10 +-- src/udev/udevadm-trigger.c | 12 ++-- src/udev/udevadm.c | 2 +- src/udev/udevd.c | 16 ++--- test/test-udev.c | 2 +- 40 files changed, 390 insertions(+), 331 deletions(-) create mode 100644 src/libudev/strxcpyx.c create mode 100644 src/libudev/strxcpyx.h diff --git a/.gitignore b/.gitignore index 0b5695f2c..ab23f3211 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ m4/lt~obsolete.m4 docs/gudev/version.xml docs/libudev/version.xml +docs/gudev/gudev-overrides.txt +docs/libudev/libudev-overrides.txt man/udev.7 man/udevadm.8 @@ -59,3 +61,4 @@ src/keymap/keys.txt test/test-libudev test/test-udev test/test +test-driver diff --git a/src/accelerometer/accelerometer.c b/src/accelerometer/accelerometer.c index 67ed22d44..e611b48a4 100644 --- a/src/accelerometer/accelerometer.c +++ b/src/accelerometer/accelerometer.c @@ -123,7 +123,7 @@ string_to_orientation (const char *orientation) if (orientation == NULL) return ORIENTATION_UNDEFINED; for (i = 0; orientations[i] != NULL; i++) { - if (strcmp (orientation, orientations[i]) == 0) + if (streq (orientation, orientations[i])) return i; } return ORIENTATION_UNDEFINED; @@ -187,7 +187,7 @@ static void test_orientation(struct udev *udev, const char *devpath) { OrientationUp old, new; - int _cleanup_close_ fd = -1; + _cleanup_close_ int fd = -1; struct input_event ev[64]; bool got_syn = false; bool got_x = false, got_y = false, got_z = false; diff --git a/src/collect/collect.c b/src/collect/collect.c index 3dd702dfa..834e27683 100644 --- a/src/collect/collect.c +++ b/src/collect/collect.c @@ -35,8 +35,8 @@ #include "libudev-private.h" #include "macro.h" -#define BUFSIZE 16 -#define UDEV_ALARM_TIMEOUT 180 +#define BUFSIZE 16 +#define UDEV_ALARM_TIMEOUT 180 enum collect_state { STATE_NONE, @@ -140,12 +140,14 @@ static int checkout(int fd) restart: len = bufsize >> 1; - buf = calloc(1,bufsize + 1); + buf = malloc(bufsize + 1); if (!buf) { fprintf(stderr, "Out of memory.\n"); return log_oom(); } memset(buf, ' ', bufsize); + buf[bufsize] = '\0'; + ptr = buf + len; while ((read(fd, buf + len, len)) > 0) { while (ptr && *ptr) { @@ -214,7 +216,7 @@ static void invite(char *us) udev_list_node_foreach(him_node, &bunch) { struct _mate *him = node_to_mate(him_node); - if (!strcmp(him->name, us)) { + if (streq(him->name, us)) { him->state = STATE_CONFIRMED; who = him; } @@ -242,7 +244,7 @@ static void reject(char *us) udev_list_node_foreach(him_node, &bunch) { struct _mate *him = node_to_mate(him_node); - if (!strcmp(him->name, us)) { + if (streq(him->name, us)) { him->state = STATE_NONE; who = him; } @@ -415,7 +417,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; @@ -435,7 +437,7 @@ int main(int argc, char **argv) udev_list_node_foreach(him_node, &bunch) { struct _mate *him = node_to_mate(him_node); - if (!strcmp(him->name, argv[i])) + if (streq(him->name, argv[i])) who = him; } if (!who) { diff --git a/src/gudev/gudevclient.h b/src/gudev/gudevclient.h index b425d03d4..23bfce615 100644 --- a/src/gudev/gudevclient.h +++ b/src/gudev/gudevclient.h @@ -3,19 +3,18 @@ * Copyright (C) 2008 David Zeuthen * * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public + * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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. + * Library General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H) diff --git a/src/libudev/Makefile.am b/src/libudev/Makefile.am index 683944a67..879cc9065 100644 --- a/src/libudev/Makefile.am +++ b/src/libudev/Makefile.am @@ -42,6 +42,7 @@ libudev_la_SOURCES =\ set.c \ strbuf.c \ strv.c \ + strxcpyx.c \ util.c noinst_HEADERS = \ @@ -62,6 +63,7 @@ noinst_HEADERS = \ sparse-endian.h \ strbuf.h \ strv.h \ + strxcpyx.h \ util.h include_HEADERS = \ diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index c12305790..cba08d2f6 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 cd94b7edf..eb43668c5 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 { @@ -780,7 +780,7 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char * * Returns: a new udev device, or #NULL, if it does not exist **/ -_public_ struct udev_device *udev_device_new_from_device_id(struct udev *udev, char *id) +_public_ struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id) { char type; int maj, min; @@ -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; @@ -1456,7 +1456,7 @@ _public_ int udev_device_set_sysattr_value(struct udev_device *udev_device, cons else value_len = strlen(value); - util_strscpyl(path, sizeof(path), udev_device_get_syspath(dev), "/", sysattr, NULL); + strscpyl(path, sizeof(path), udev_device_get_syspath(dev), "/", sysattr, NULL); if (lstat(path, &statbuf) != 0) { udev_list_entry_add(&dev->sysattr_value_list, sysattr, NULL); ret = -ENXIO; @@ -1535,7 +1535,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) @@ -1794,10 +1794,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 6a5f4e025..5ccaabdc6 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -309,7 +309,7 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume } if (move_later && - strncmp(entry->syspath, move_later->syspath, move_later_prefix) != 0) { + !strneq(entry->syspath, move_later->syspath, move_later_prefix)) { udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL); move_later = NULL; @@ -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-hwdb.c b/src/libudev/libudev-hwdb.c index 524895222..5886ed333 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -140,9 +140,13 @@ static const struct trie_node_f *node_lookup_f(struct udev_hwdb *hwdb, const str } static int hwdb_add_property(struct udev_hwdb *hwdb, const char *key, const char *value) { - /* TODO: add sub-matches (+) against DMI data */ + /* + * Silently ignore all properties which do not start with a + * space; future extensions might use additional prefixes. + */ if (key[0] != ' ') return 0; + if (udev_list_entry_add(&hwdb->properties_list, key+1, value) == NULL) return -ENOMEM; return 0; @@ -300,11 +304,11 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) { } log_debug("=== trie on-disk ===\n"); - log_debug("tool version: %llu", (unsigned long long)le64toh(hwdb->head->tool_version)); - log_debug("file size: %8llu bytes\n", (unsigned long long)hwdb->st.st_size); - log_debug("header size %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->header_size)); - log_debug("strings %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->strings_len)); - log_debug("nodes %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->nodes_len)); + log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version)); + log_debug("file size: %8llu bytes\n", (unsigned long long) hwdb->st.st_size); + log_debug("header size %8"PRIu64" bytes\n", le64toh(hwdb->head->header_size)); + log_debug("strings %8"PRIu64" bytes\n", le64toh(hwdb->head->strings_len)); + log_debug("nodes %8"PRIu64" bytes\n", le64toh(hwdb->head->nodes_len)); return hwdb; } diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index b02ea8808..021279255 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -115,9 +115,9 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c if (name == NULL) group = UDEV_MONITOR_NONE; - else if (strcmp(name, "udev") == 0) + else if (streq(name, "udev")) group = UDEV_MONITOR_UDEV; - else if (strcmp(name, "kernel") == 0) + else if (streq(name, "kernel")) group = UDEV_MONITOR_KERNEL; else return NULL; @@ -467,7 +467,7 @@ static int passes_filter(struct udev_monitor *udev_monitor, struct udev_device * const char *devtype; const char *ddevtype; - if (strcmp(dsubsys, subsys) != 0) + if (!streq(dsubsys, subsys)) continue; devtype = udev_list_entry_get_value(list_entry); @@ -476,7 +476,7 @@ static int passes_filter(struct udev_monitor *udev_monitor, struct udev_device * ddevtype = udev_device_get_devtype(udev_device); if (ddevtype == NULL) continue; - if (strcmp(ddevtype, devtype) == 0) + if (streq(ddevtype, devtype)) goto tag; } return 0; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 1b8638470..7caf61aec 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -164,11 +164,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 08d52ab1f..0dd20313d 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; @@ -467,7 +467,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu udev_list_entry_add(&udev_queue->queue_list, syspath, seqnum_str); } else { udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_queue->queue_list)) { - if (strcmp(seqnum_str, udev_list_entry_get_value(list_entry)) == 0) { + if (streq(seqnum_str, udev_list_entry_get_value(list_entry))) { udev_list_entry_delete(list_entry); break; } diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index 7c2cf7c22..522a984c3 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -54,7 +54,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; @@ -86,7 +86,7 @@ uid_t util_lookup_user(struct udev *udev, const char *user) size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); char *buf = alloca(buflen); - if (strcmp(user, "root") == 0) + if (streq(user, "root")) return 0; uid = strtoul(user, &endptr, 10); if (endptr[0] == '\0') @@ -111,7 +111,7 @@ gid_t util_lookup_group(struct udev *udev, const char *group) size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); char *buf = NULL; - if (strcmp(group, "root") == 0) + if (streq(group, "root")) return 0; gid = strtoul(group, &endptr, 10); if (endptr[0] == '\0') @@ -154,7 +154,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]; @@ -186,7 +186,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); @@ -195,9 +195,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); @@ -210,7 +210,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; @@ -219,7 +219,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) @@ -245,7 +245,7 @@ int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size) base[0] = '\0'; } - util_strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL); + strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL); return 0; } @@ -309,89 +309,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) -{ - char *dstend = *dest + (size - 1); - - if (!size) return 0; /*Nothing to do if size is 0*/ - - *dest = memccpy(*dest, src, '\0', size); - - if (*dest) {/*Terminator character found*/ - (*dest)--; /*memccpy points to the element after the one with '\0'*/ - return (dstend - *dest) + 1;/*For some odd reason they are not taking into account the \0 in the capacity...*/ - } else { - *(*dest = dstend) = '\0'; /*Restore dest and add terminator*/ - return 0; /*But here they do*/ - } -} - -size_t util_strpcpyf(char **dest, size_t size, const char *src, ...) -{ - va_list va; - int i; - - if (!size) return 0; /*Nothing to do if size is 0*/ - - va_start(va, src); - i = vsnprintf(*dest, size, src, va); - if (i < (int)size) { - *dest += i; - size -= i; - } else { - *dest += size - 1; - size = 0; - } - va_end(va); - *dest[0] = '\0'; - return size; -} - -/* concatenates list of strings, moves dest forward */ -/* Uses a va_list */ -size_t util_strpcpyv(char **dest, size_t size, const char *src, va_list va) -{ - do { - size = util_strpcpy(dest, size, src); - } while (size && (src = va_arg(va, char *))); - 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); - size=util_strpcpyv(dest, size, src, va); - va_end(va); - - return size; -} - -/* copies string */ -size_t util_strscpy(char *dest, size_t size, const char *src) -{ - return util_strpcpy(&dest, size, src); -} - -/* concatenates list of strings */ -size_t util_strscpyl(char *dest, size_t size, const char *src, ...) -{ - va_list va; - - va_start(va, src); - size=util_strpcpyv(&dest, size, src, va); - 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/libudev/libudev.c b/src/libudev/libudev.c index 09c41e43a..d2bf93db2 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -190,7 +190,7 @@ _public_ struct udev *udev_new(void) val++; } - if (strcmp(key, "udev_log") == 0) { + if (streq(key, "udev_log")) { udev_set_log_priority(udev, util_log_priority(val)); continue; } diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 61567b1d6..b9b8f13e4 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -81,7 +81,7 @@ struct udev *udev_device_get_udev(struct udev_device *udev_device); struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); -struct udev_device *udev_device_new_from_device_id(struct udev *udev, char *id); +struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id); struct udev_device *udev_device_new_from_environment(struct udev *udev); /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */ struct udev_device *udev_device_get_parent(struct udev_device *udev_device); diff --git a/src/libudev/strxcpyx.c b/src/libudev/strxcpyx.c new file mode 100644 index 000000000..fbdf5ac65 --- /dev/null +++ b/src/libudev/strxcpyx.c @@ -0,0 +1,104 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of eudev from 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/libudev/strxcpyx.h b/src/libudev/strxcpyx.h new file mode 100644 index 000000000..962c389e9 --- /dev/null +++ b/src/libudev/strxcpyx.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of eudev from 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/libudev/util.h b/src/libudev/util.h index d44fcc2e4..2ac6f59c4 100644 --- a/src/libudev/util.h +++ b/src/libudev/util.h @@ -90,10 +90,13 @@ size_t page_size(void); #define streq(a,b) (strcmp((a),(b)) == 0) #define strneq(a, b, n) (strncmp((a), (b), (n)) == 0) +#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0) +#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0) bool streq_ptr(const char *a, const char *b) _pure_; #define new(t, n) ((t*) malloc_multiply(sizeof(t), (n))) + #define new0(t, n) ((t*) calloc((n), sizeof(t))) #define malloc0(n) (calloc((n), 1)) diff --git a/src/scsi_id/scsi_id.c b/src/scsi_id/scsi_id.c index 81980778a..230fa2b78 100644 --- a/src/scsi_id/scsi_id.c +++ b/src/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); } /* @@ -227,7 +227,7 @@ static int get_file_options(struct udev *udev, continue; str1 = strsep(&buf, "="); - if (str1 && strcasecmp(str1, "VENDOR") == 0) { + if (str1 && strcaseeq(str1, "VENDOR")) { str1 = get_value(&buf); if (!str1) { retval = log_oom(); @@ -236,7 +236,7 @@ static int get_file_options(struct udev *udev, vendor_in = str1; str1 = strsep(&buf, "="); - if (str1 && strcasecmp(str1, "MODEL") == 0) { + if (str1 && strcaseeq(str1, "MODEL")) { str1 = get_value(&buf); if (!str1) { retval = log_oom(); @@ -247,7 +247,7 @@ static int get_file_options(struct udev *udev, } } - if (str1 && strcasecmp(str1, "OPTIONS") == 0) { + if (str1 && strcaseeq(str1, "OPTIONS")) { str1 = get_value(&buf); if (!str1) { retval = log_oom(); @@ -267,10 +267,10 @@ static int get_file_options(struct udev *udev, if (vendor == NULL) { if (vendor_in == NULL) break; - } else if ((vendor_in && strncmp(vendor, vendor_in, - strlen(vendor_in)) == 0) && - (!model_in || (strncmp(model, model_in, - strlen(model_in)) == 0))) { + } else if ((vendor_in && strneq(vendor, vendor_in, + strlen(vendor_in))) && + (!model_in || (strneq(model, model_in, + strlen(model_in))))) { /* * Matched vendor and optionally model. * @@ -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': @@ -372,11 +372,11 @@ static int set_options(struct udev *udev, exit(0); case 'p': - if (strcmp(optarg, "0x80") == 0) { + if (streq(optarg, "0x80")) { default_page_code = PAGE_80; - } else if (strcmp(optarg, "0x83") == 0) { + } else if (streq(optarg, "0x83")) { default_page_code = PAGE_83; - } else if (strcmp(optarg, "pre-spc3-83") == 0) { + } else if (streq(optarg, "pre-spc3-83")) { default_page_code = PAGE_83_PRE_SPC3; } else { log_error("Unknown page code '%s'\n", optarg); @@ -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; } @@ -449,11 +449,11 @@ static int per_dev_options(struct udev *udev, break; case 'p': - if (strcmp(optarg, "0x80") == 0) { + if (streq(optarg, "0x80")) { *page_code = PAGE_80; - } else if (strcmp(optarg, "0x83") == 0) { + } else if (streq(optarg, "0x83")) { *page_code = PAGE_83; - } else if (strcmp(optarg, "pre-spc3-83") == 0) { + } else if (streq(optarg, "pre-spc3-83")) { *page_code = PAGE_83_PRE_SPC3; } else { log_error("Unknown page code '%s'\n", optarg); diff --git a/src/scsi_id/scsi_serial.c b/src/scsi_id/scsi_serial.c index 950b8adc0..d522a23a0 100644 --- a/src/scsi_id/scsi_serial.c +++ b/src/scsi_id/scsi_serial.c @@ -436,7 +436,7 @@ static int do_scsi_page0_inquiry(struct udev *udev, * If the vendor id appears in the page assume the page is * invalid. */ - if (!strncmp((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) { + if (strneq((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) { log_debug("%s: invalid page0 data\n", dev_scsi->kernel); return 1; } diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index e3a89973c..bae429344 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); } else if (streq(name, "SYSTEM_ID")) { diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index dfb05525a..f7bea69b2 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 a23b8c1a4..b80940b6e 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -98,18 +98,18 @@ 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_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); + strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); if (fwfile == NULL) { log_debug("did not find firmware file '%s'\n", firmware); @@ -134,7 +134,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-kmod.c b/src/udev/udev-builtin-kmod.c index d2148a8ab..e2b97dbc4 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -89,7 +89,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te return 0; #endif - if (argc < 3 || strcmp(argv[1], "load")) { + if (argc < 3 || !streq(argv[1], "load")) { log_error("expect: %s load \n", argv[0]); return EXIT_FAILURE; } diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 37ae710ea..9c1c5feb0 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -193,12 +193,12 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { s = names->pci_path; l = sizeof(names->pci_path); if (domain > 0) - l = util_strpcpyf(&s, l, "P%d", domain); - l = util_strpcpyf(&s, l, "p%ds%d", bus, slot); + l = strpcpyf(&s, l, "P%d", domain); + l = strpcpyf(&s, l, "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'; @@ -230,7 +230,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { snprintf(str, sizeof(str), "%s/%s/address", slots, dent->d_name); if (read_one_line_file(str, &address) >= 0) { /* match slot address with device by stripping the function */ - if (strncmp(address, udev_device_get_sysname(names->pcidev), strlen(address)) == 0) + if (strneq(address, udev_device_get_sysname(names->pcidev), strlen(address))) hotplug_slot = i; free(address); } @@ -244,12 +244,12 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { s = names->pci_slot; l = sizeof(names->pci_slot); if (domain > 0) - l = util_strpcpyf(&s, l, "P%d", domain); - l = util_strpcpyf(&s, l, "s%d", hotplug_slot); + l = strpcpyf(&s, l, "P%d", domain); + l = strpcpyf(&s, l, "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'; } @@ -292,7 +292,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(usbdev)); + strscpy(name, sizeof(name), udev_device_get_sysname(usbdev)); s = strchr(name, '-'); if (!s) return -EINVAL; @@ -315,15 +315,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; @@ -423,7 +423,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool p = udev_device_get_sysattr_value(dev, "iflink"); if (!p) return EXIT_FAILURE; - if (strcmp(s, p) != 0) + if (!streq(s, p)) return 0; devtype = udev_device_get_devtype(dev); diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index d6b3736ae..da0273197 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -83,7 +83,7 @@ static struct udev_device *skip_subsystem(struct udev_device *dev, const char *s const char *subsystem; subsystem = udev_device_get_subsystem(parent); - if (subsystem == NULL || strcmp(subsystem, subsys) != 0) + if (subsystem == NULL || !streq(subsystem, subsys)) break; dev = parent; parent = udev_device_get_parent(parent); @@ -345,7 +345,7 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path) const char *id; devtype = udev_device_get_devtype(parent); - if (devtype == NULL || strcmp(devtype, "scsi_device") != 0) + if (devtype == NULL || !streq(devtype, "scsi_device")) return parent; /* firewire */ @@ -438,7 +438,7 @@ static struct udev_device *handle_usb(struct udev_device *parent, char **path) devtype = udev_device_get_devtype(parent); if (devtype == NULL) return parent; - if (strcmp(devtype, "usb_interface") != 0 && strcmp(devtype, "usb_device") != 0) + if (!streq(devtype, "usb_interface") && !streq(devtype, "usb_device")) return parent; str = udev_device_get_sysname(parent); @@ -498,37 +498,37 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool subsys = udev_device_get_subsystem(parent); if (subsys == NULL) { ; - } else if (strcmp(subsys, "scsi_tape") == 0) { + } else if (streq(subsys, "scsi_tape")) { handle_scsi_tape(parent, &path); - } else if (strcmp(subsys, "scsi") == 0) { + } else if (streq(subsys, "scsi")) { parent = handle_scsi(parent, &path); some_transport = true; - } else if (strcmp(subsys, "cciss") == 0) { + } else if (streq(subsys, "cciss")) { parent = handle_cciss(parent, &path); some_transport = true; - } else if (strcmp(subsys, "usb") == 0) { + } else if (streq(subsys, "usb")) { parent = handle_usb(parent, &path); some_transport = true; - } else if (strcmp(subsys, "serio") == 0) { + } else if (streq(subsys, "serio")) { path_prepend(&path, "serio-%s", udev_device_get_sysnum(parent)); parent = skip_subsystem(parent, "serio"); - } else if (strcmp(subsys, "pci") == 0) { + } else if (streq(subsys, "pci")) { path_prepend(&path, "pci-%s", udev_device_get_sysname(parent)); parent = skip_subsystem(parent, "pci"); - } else if (strcmp(subsys, "platform") == 0) { + } else if (streq(subsys, "platform")) { path_prepend(&path, "platform-%s", udev_device_get_sysname(parent)); parent = skip_subsystem(parent, "platform"); some_transport = true; - } else if (strcmp(subsys, "acpi") == 0) { + } else if (streq(subsys, "acpi")) { path_prepend(&path, "acpi-%s", udev_device_get_sysname(parent)); parent = skip_subsystem(parent, "acpi"); - } else if (strcmp(subsys, "xen") == 0) { + } else if (streq(subsys, "xen")) { path_prepend(&path, "xen-%s", udev_device_get_sysname(parent)); parent = skip_subsystem(parent, "xen"); - } else if (strcmp(subsys, "virtio") == 0) { + } else if (streq(subsys, "virtio")) { path_prepend(&path, "virtio-pci-%s", udev_device_get_sysname(parent)); parent = skip_subsystem(parent, "virtio"); - } else if (strcmp(subsys, "scm") == 0) { + } else if (streq(subsys, "scm")) { path_prepend(&path, "scm-%s", udev_device_get_sysname(parent)); parent = skip_subsystem(parent, "scm"); } diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index b021d03a6..e3bbd05e4 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 @@ -152,7 +152,7 @@ static void set_scsi_type(char *to, const char *from, size_t len) static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len) { _cleanup_free_ char *filename = NULL; - int _cleanup_close_ fd = -1; + _cleanup_close_ int fd = -1; ssize_t size; unsigned char buf[18 + 65535]; int pos = 0; @@ -267,7 +267,7 @@ static int builtin_usb_id(struct udev_device *dev, int argc, char *argv[], bool instance_str[0] = '\0'; /* shortcut, if we are called directly for a "usb_device" type */ - if (udev_device_get_devtype(dev) != NULL && strcmp(udev_device_get_devtype(dev), "usb_device") == 0) { + if (udev_device_get_devtype(dev) != NULL && streq(udev_device_get_devtype(dev), "usb_device")) { dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str)); dev_usb = dev; goto fallback; @@ -443,12 +443,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 226295f68..22deaac1a 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -109,12 +109,12 @@ 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'; for (i = 0; i < ELEMENTSOF(builtins); i++) - if (strcmp(builtins[i]->name, name) == 0) + if (streq(builtins[i]->name, name)) return i; return UDEV_BUILTIN_MAX; } @@ -127,7 +127,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 fe318586f..138b6f44b 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -96,7 +96,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) setsockopt(uctrl->sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); 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; } @@ -274,7 +274,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 c6c5940ff..7cf82fd8a 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 */ @@ -687,14 +687,13 @@ int udev_event_spawn(struct udev_event *event, } /* allow programs in /usr/lib/udev/ to be called without the path */ - /* NOTE - paths need reworking, see note in udev-rules.c */ if (argv[0][0] != '/') { - util_strscpyl(program, sizeof(program), UDEV_LIBEXEC_DIR "/", argv[0], NULL); + strscpyl(program, sizeof(program), UDEV_LIBEXEC_DIR "/", argv[0], NULL); #ifdef HAVE_SPLIT_USR if(access(program, X_OK)) - util_strscpyl(program, sizeof(program), "/usr/lib/udev/", argv[0], NULL); + strscpyl(program, sizeof(program), "/usr/lib/udev/", argv[0], NULL); if(access(program, X_OK)) - util_strscpyl(program, sizeof(program), "/lib/udev/", argv[0], NULL); + strscpyl(program, sizeof(program), "/lib/udev/", argv[0], NULL); #endif argv[0] = program; } @@ -792,8 +791,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); #ifdef ENABLE_RULE_GENERATOR @@ -821,8 +820,8 @@ static int rename_netif(struct udev_event *event) rename_netif_kernel_log(ifr); /* wait a maximum of 90 seconds for our target to become available */ - util_strscpy(ifr.ifr_name, IFNAMSIZ, ifr.ifr_newname); - util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); + strscpy(ifr.ifr_name, IFNAMSIZ, ifr.ifr_newname); + strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); loop = 90 * 20; while (loop--) { const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 }; @@ -863,7 +862,7 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, if (udev_device_get_subsystem(dev) == NULL) return -1; - if (strcmp(udev_device_get_action(dev), "remove") == 0) { + if (streq(udev_device_get_action(dev), "remove")) { udev_device_read_db(dev, NULL); udev_device_delete_db(dev); udev_device_tag_index(dev, NULL, false); @@ -891,8 +890,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, udev_rules_apply_to_event(rules, event, sigmask); /* rename a new network interface, if needed */ - if (udev_device_get_ifindex(dev) > 0 && strcmp(udev_device_get_action(dev), "add") == 0 && - event->name != NULL && strcmp(event->name, udev_device_get_sysname(dev)) != 0) { + if (udev_device_get_ifindex(dev) > 0 && streq(udev_device_get_action(dev), "add") && + event->name != NULL && !streq(event->name, udev_device_get_sysname(dev))) { char syspath[UTIL_PATH_SIZE]; char *pos; @@ -904,11 +903,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 d10c63aaa..4fca46495 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -53,10 +53,10 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s 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; @@ -74,7 +74,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s len = readlink(slink, buf, sizeof(buf)); if (len > 0 && len < (int)sizeof(buf)) { buf[len] = '\0'; - if (strcmp(target, buf) == 0) { + if (streq(target, buf)) { log_debug("preserve already existing symlink '%s' to '%s'\n", slink, target); label_fix(slink, true, false); utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW); @@ -99,7 +99,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s } log_debug("atomically replace '%s'\n", slink); - util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, ".tmp-", udev_device_get_id_filename(dev), NULL); + strscpyl(slink_tmp, sizeof(slink_tmp), slink, ".tmp-", udev_device_get_id_filename(dev), NULL); unlink(slink_tmp); do { err = mkdir_parents_label(slink_tmp, 0755); @@ -134,7 +134,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; } @@ -154,7 +154,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons log_debug("found '%s' claiming '%s'\n", dent->d_name, stackdir); /* did we find ourself? */ - if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0) + if (streq(dent->d_name, udev_device_get_id_filename(dev))) continue; dev_db = udev_device_new_from_device_id(udev, dent->d_name); @@ -167,7 +167,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; } } @@ -189,8 +189,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); @@ -238,7 +238,7 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev udev_list_entry_foreach(list_entry_current, udev_device_get_devlinks_list_entry(dev)) { const char *name_current = udev_list_entry_get_name(list_entry_current); - if (strcmp(name, name_current) == 0) { + if (streq(name, name_current)) { found = 1; break; } @@ -259,7 +259,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, mode_t mo struct stat stats; int err = 0; - if (strcmp(udev_device_get_subsystem(dev), "block") == 0) + if (streq(udev_device_get_subsystem(dev), "block")) mode |= S_IFBLK; else mode |= S_IFCHR; @@ -308,7 +308,7 @@ void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, /* always add /dev/{block,char}/$major:$minor */ snprintf(filename, sizeof(filename), "/dev/%s/%u:%u", - strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", + streq(udev_device_get_subsystem(dev), "block") ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); node_symlink(dev, udev_device_get_devnode(dev), filename); @@ -328,7 +328,7 @@ void udev_node_remove(struct udev_device *dev) /* remove /dev/{block,char}/$major:$minor */ snprintf(filename, sizeof(filename), "/dev/%s/%u:%u", - strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", + streq(udev_device_get_subsystem(dev), "block") ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); unlink(filename); } diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 9844b8a80..e947f317c 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; @@ -1742,7 +1742,7 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * if (next != NULL) { size_t matchlen = (size_t)(next - s); - match = (matchlen == len && strncmp(s, val, matchlen) == 0); + match = (matchlen == len && strneq(s, val, matchlen)); if (match) break; } else { @@ -1757,7 +1757,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, '|'); @@ -1824,7 +1824,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])) @@ -2020,8 +2020,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); } } @@ -2333,7 +2333,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)); @@ -2424,7 +2424,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++; @@ -2434,7 +2434,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; @@ -2446,7 +2446,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)); @@ -2544,7 +2544,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 75510c517..0eaaea19a 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -45,7 +45,7 @@ static bool skip_attribute(const char *name) unsigned int i; for (i = 0; i < ELEMENTSOF(skip); i++) - if (strcmp(name, skip[i]) == 0) + if (streq(name, skip[i])) return true; return false; } @@ -263,7 +263,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; } @@ -387,15 +387,15 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) break; case 'q': action = ACTION_QUERY; - if (strcmp(optarg, "property") == 0 || strcmp(optarg, "env") == 0) { + if (streq(optarg, "property") || streq(optarg, "env")) { query = QUERY_PROPERTY; - } else if (strcmp(optarg, "name") == 0) { + } else if (streq(optarg, "name")) { query = QUERY_NAME; - } else if (strcmp(optarg, "symlink") == 0) { + } else if (streq(optarg, "symlink")) { query = QUERY_SYMLINK; - } else if (strcmp(optarg, "path") == 0) { + } else if (streq(optarg, "path")) { query = QUERY_PATH; - } else if (strcmp(optarg, "all") == 0) { + } else if (streq(optarg, "all")) { query = QUERY_ALL; } else { fprintf(stderr, "unknown query type\n"); @@ -408,7 +408,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 ffa70d830..a390ee6c3 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 9853d83b4..f4aa21ee7 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 2d8aa7913..df1409bff 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -66,11 +66,11 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) action = optarg; break; case 'N': - if (strcmp (optarg, "early") == 0) { + if (streq (optarg, "early")) { resolve_names = 1; - } else if (strcmp (optarg, "late") == 0) { + } else if (streq (optarg, "late")) { resolve_names = 0; - } else if (strcmp (optarg, "never") == 0) { + } else if (streq (optarg, "never")) { resolve_names = -1; } else { fprintf(stderr, "resolve-names must be early, late or never\n"); @@ -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 d8960f997..f47299696 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; @@ -122,9 +122,9 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) dry_run = 1; break; case 't': - if (strcmp(optarg, "devices") == 0) { + if (streq(optarg, "devices")) { device_type = TYPE_DEVICES; - } else if (strcmp(optarg, "subsystems") == 0) { + } else if (streq(optarg, "subsystems")) { device_type = TYPE_SUBSYSTEMS; } else { log_error("unknown type --type=%s\n", optarg); @@ -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/udevadm.c b/src/udev/udevadm.c index 82852fb08..e7e1b4a97 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -130,7 +130,7 @@ int main(int argc, char *argv[]) if (command != NULL) for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) { - if (strcmp(udevadm_cmds[i]->name, command) == 0) { + if (streq(udevadm_cmds[i]->name, command)) { argc -= optind; argv += optind; /* we need '0' here to reset the internal state */ diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 0fb7915b7..44318814c 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -503,7 +503,7 @@ static bool is_devpath_busy(struct event *event) return true; /* check our old name */ - if (event->devpath_old != NULL && strcmp(loop_event->devpath, event->devpath_old) == 0) { + if (event->devpath_old != NULL && streq(loop_event->devpath, event->devpath_old)) { event->delaying_seqnum = loop_event->seqnum; return true; } @@ -732,7 +732,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) @@ -823,7 +823,7 @@ static void static_dev_create_from_modules(struct udev *udev) return; } - 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; @@ -870,7 +870,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); @@ -983,11 +983,11 @@ int main(int argc, char *argv[]) udev_set_log_priority(udev, LOG_DEBUG); break; case 'N': - if (strcmp (optarg, "early") == 0) { + if (streq(optarg, "early")) { resolve_names = 1; - } else if (strcmp (optarg, "late") == 0) { + } else if (streq(optarg, "late")) { resolve_names = 0; - } else if (strcmp (optarg, "never") == 0) { + } else if (streq(optarg, "never")) { resolve_names = -1; } else { fprintf(stderr, "resolve-names must be early, late or never\n"); @@ -1116,7 +1116,7 @@ int main(int argc, char *argv[]) write_one_line_file("/proc/self/oom_score_adj", "-1000"); } - print_kmsg("starting eudev version " VERSION "\n"); + print_kmsg("starting version " VERSION "\n"); if (!debug) { int fd; diff --git a/test/test-udev.c b/test/test-udev.c index 5e227cb55..9935cc1ea 100644 --- a/test/test-udev.c +++ b/test/test-udev.c @@ -129,7 +129,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);