src/shared/strv.h \
src/shared/strbuf.c \
src/shared/strbuf.h \
+ src/shared/strxcpyx.c \
+ src/shared/strxcpyx.h \
src/shared/conf-parser.c \
src/shared/conf-parser.h \
src/shared/log.c \
* udev: move to LGPL
* udev systemd unify:
- - strpcpy(), strpcpyl(), strscpy(), strscpyl()
- utf8 validator code
* udev: scsi_id -> sg3_utils -> kill scsi_id
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;
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 &&
}
/* 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) {
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;
}
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;
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]);
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) {
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++;
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;
}
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':
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;
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 {
return NULL;
}
case '+':
- util_strscpy(subsys, sizeof(subsys), &id[1]);
+ strscpy(subsys, sizeof(subsys), &id[1]);
sysname = strchr(subsys, ':');
if (sysname == NULL)
return NULL;
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;
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:
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;
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);
}
}
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);
}
}
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;
/* resolve custom link to a device and return its syspath */
if (!streq(sysattr, "device")) {
- util_strscpyl(path, sizeof(path), udev_device->syspath, "/", sysattr, NULL);
+ strscpyl(path, sizeof(path), udev_device->syspath, "/", sysattr, NULL);
dev = udev_device_new_from_syspath(udev_device->udev, path);
if (dev != NULL) {
list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr,
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)
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--;
}
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;
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;
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;
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;
#include "macro.h"
#include "util.h"
#include "mkdir.h"
+#include "strxcpyx.h"
#define READ_END 0
#define WRITE_END 1
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);
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;
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;
if (string[0] != '[')
return -1;
- util_strscpy(temp, sizeof(temp), string);
+ strscpy(temp, sizeof(temp), string);
subsys = &temp[1];
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);
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);
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;
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)
}
if (base == NULL)
return -EINVAL;
- util_strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL);
+ strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL);
return 0;
}
path[--len] = '\0';
}
-/*
- * Concatenates strings. In any case, terminates in _all_ cases with '\0'
- * and moves the @dest pointer forward to the added '\0'. Returns the
- * remaining size, and 0 if the string was truncated.
- */
-size_t util_strpcpy(char **dest, size_t size, const char *src)
-{
- size_t len;
-
- len = strlen(src);
- if (len >= size) {
- if (size > 1)
- *dest = mempcpy(*dest, src, size-1);
- size = 0;
- } else {
- if (len > 0) {
- *dest = mempcpy(*dest, src, len);
- size -= len;
- }
- }
- *dest[0] = '\0';
- return size;
-}
-
-size_t util_strpcpyf(char **dest, size_t size, const char *src, ...)
-{
- va_list va;
- int i;
-
- va_start(va, src);
- i = vsnprintf(*dest, size, src, va);
- if (i < (int)size) {
- *dest += i;
- size -= i;
- } else {
- *dest += size;
- size = 0;
- }
- va_end(va);
- *dest[0] = '\0';
- return size;
-}
-
-/* concatenates list of strings, moves dest forward */
-size_t util_strpcpyl(char **dest, size_t size, const char *src, ...)
-{
- va_list va;
-
- va_start(va, src);
- do {
- size = util_strpcpy(dest, size, src);
- src = va_arg(va, char *);
- } while (src != NULL);
- va_end(va);
- return size;
-}
-
-/* copies string */
-size_t util_strscpy(char *dest, size_t size, const char *src)
-{
- char *s;
-
- s = dest;
- return util_strpcpy(&s, size, src);
-}
-
-/* concatenates list of strings */
-size_t util_strscpyl(char *dest, size_t size, const char *src, ...)
-{
- va_list va;
- char *s;
-
- va_start(va, src);
- s = dest;
- do {
- size = util_strpcpy(&s, size, src);
- src = va_arg(va, char *);
- } while (src != NULL);
- va_end(va);
-
- return size;
-}
-
/* count of characters used to encode one unicode char */
static int utf8_encoded_expected_len(const char *str)
{
--- /dev/null
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Kay Sievers
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <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;
+}
--- /dev/null
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Kay Sievers
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <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));
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);
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;
break;
}
}
- util_strscpy(to, len, type);
+ strscpy(to, len, type);
}
/*
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':
break;
case 'f':
- util_strscpy(config_file, MAX_PATH_LEN, optarg);
+ strscpy(config_file, MAX_PATH_LEN, optarg);
break;
case 'g':
}
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;
}
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);
}
}
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)
/* lookup firmware file */
uname(&kernel);
for (i = 0; i < ELEMENTSOF(searchpath); i++) {
- util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
fwfile = fopen(fwpath, "re");
if (fwfile != NULL)
break;
- util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
fwfile = fopen(fwpath, "re");
if (fwfile != NULL)
break;
}
util_path_encode(firmware, fwencpath, sizeof(fwencpath));
- util_strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL);
- util_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
+ strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL);
+ strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
if (fwfile == NULL) {
int err;
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");
/* compose a name based on the raw kernel's PCI bus, slot numbers */
s = names->pci_path;
- l = util_strpcpyf(&s, sizeof(names->pci_path), "p%ds%d", bus, slot);
+ l = strpcpyf(&s, sizeof(names->pci_path), "p%ds%d", bus, slot);
if (func > 0 || is_pci_multifunction(names->pcidev))
- l = util_strpcpyf(&s, l, "f%d", func);
+ l = strpcpyf(&s, l, "f%d", func);
if (dev_id > 0)
- l = util_strpcpyf(&s, l, "d%d", dev_id);
+ l = strpcpyf(&s, l, "d%d", dev_id);
if (l == 0)
names->pci_path[0] = '\0';
if (hotplug_slot > 0) {
s = names->pci_slot;
- l = util_strpcpyf(&s, sizeof(names->pci_slot), "s%d", hotplug_slot);
+ l = strpcpyf(&s, sizeof(names->pci_slot), "s%d", hotplug_slot);
if (func > 0 || is_pci_multifunction(names->pcidev))
- l = util_strpcpyf(&s, l, "f%d", func);
+ l = strpcpyf(&s, l, "f%d", func);
if (dev_id > 0)
- l = util_strpcpyf(&s, l, "d%d", dev_id);
+ l = strpcpyf(&s, l, "d%d", dev_id);
if (l == 0)
names->pci_path[0] = '\0';
}
return -ENOENT;
/* get USB port number chain, configuration, interface */
- util_strscpy(name, sizeof(name), udev_device_get_sysname(names->usbdev));
+ strscpy(name, sizeof(name), udev_device_get_sysname(names->usbdev));
s = strchr(name, '-');
if (!s)
return -EINVAL;
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;
break;
}
}
- util_strscpy(to, len, type);
+ strscpy(to, len, type);
return type_num;
}
break;
}
}
- util_strscpy(to, len, type);
+ strscpy(to, len, type);
}
#define USB_DT_DEVICE 0x01
}
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);
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';
/* 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);
}
}
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;
}
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;
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;
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: {
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]))
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;
}
/* 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: {
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;
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) {
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:
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 */
/* allow programs in /usr/lib/udev/ to be called without the path */
if (argv[0][0] != '/') {
- util_strscpyl(program, sizeof(program), UDEVLIBEXECDIR "/", argv[0], NULL);
+ strscpyl(program, sizeof(program), UDEVLIBEXECDIR "/", argv[0], NULL);
argv[0] = program;
}
}
memset(&ifr, 0x00, sizeof(struct ifreq));
- util_strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev));
- util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
+ strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev));
+ strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
err = ioctl(sk, SIOCSIFNAME, &ifr);
if (err >= 0) {
print_kmsg("renamed network interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname);
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));
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;
}
log_debug("atomically replace '%s'\n", slink);
- util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
+ strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
unlink(slink_tmp);
do {
err = mkdir_parents_label(slink_tmp, 0755);
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;
}
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;
}
}
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);
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;
/* 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;
}
const char *tail;
DIR *dir;
- util_strscpy(dirname, sizeof(dirname), attr);
+ strscpy(dirname, sizeof(dirname), attr);
pos = strstr(dirname, "/*/");
if (pos == NULL)
return -1;
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;
{
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, '|');
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]))
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);
}
}
/* 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));
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++;
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;
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));
/* 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))
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;
}
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;
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';
/* 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);
/* 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);
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;
{
char *pos;
- util_strscpy(buf, size,str);
+ strscpy(buf, size,str);
pos = strchr(buf, '=');
if (pos != NULL) {
pos[0] = 0;
/* 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) {
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)
FILE *f;
uname(&kernel);
- util_strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL);
+ strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL);
f = fopen(modules, "re");
if (f == NULL)
return;
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);
mkdir_p("/run/udev/data", 0755);
/* old database */
- util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL);
+ strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL);
if (access(filename, F_OK) < 0)
return 0;
/* find database in old location */
id = udev_device_get_id_filename(device);
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL);
+ strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);
}
/* find old database with $subsys:$sysname name */
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/",
+ strscpyl(from, sizeof(from), "/dev/.udev/db/",
udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
/* find old database with the encoded devpath name */
util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath));
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL);
+ strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);