summaryrefslogtreecommitdiff
path: root/src/libudev
diff options
context:
space:
mode:
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/Makefile.am2
-rw-r--r--src/libudev/libudev-device-private.c8
-rw-r--r--src/libudev/libudev-device.c62
-rw-r--r--src/libudev/libudev-enumerate.c14
-rw-r--r--src/libudev/libudev-hwdb.c16
-rw-r--r--src/libudev/libudev-monitor.c8
-rw-r--r--src/libudev/libudev-private.h5
-rw-r--r--src/libudev/libudev-queue.c4
-rw-r--r--src/libudev/libudev-util.c103
-rw-r--r--src/libudev/libudev.c2
-rw-r--r--src/libudev/libudev.h2
-rw-r--r--src/libudev/strxcpyx.c104
-rw-r--r--src/libudev/strxcpyx.h31
-rw-r--r--src/libudev/util.h3
14 files changed, 210 insertions, 154 deletions
diff --git a/src/libudev/Makefile.am b/src/libudev/Makefile.am
index 683944a671..879cc90653 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 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 cd94b7edff..eb43668c56 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 6a5f4e025e..5ccaabdc6c 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 5248952223..5886ed333c 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 b02ea8808c..0212792552 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 1b86384703..7caf61aecd 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 08d52ab1f1..0dd20313d9 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 7c2cf7c22a..522a984c3b 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 09c41e43a9..d2bf93db2a 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 61567b1d67..b9b8f13e44 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 0000000000..fbdf5ac658
--- /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 <http://www.gnu.org/licenses/>.
+***/
+
+/*
+ * 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 <stdio.h>
+#include <string.h>
+#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 0000000000..962c389e93
--- /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 <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdarg.h>
+#include <stdbool.h>
+
+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 d44fcc2e4f..2ac6f59c49 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))