diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-07-16 15:20:57 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-07-16 18:38:03 +0200 |
commit | fe20121a4c36bdd26465b22805016e4596457881 (patch) | |
tree | cc0929294fc3004d758aa702db9e5f98116b84a8 /src/libsystemd/sd-device/sd-device.c | |
parent | udev: tweak debug logs for udev rules (diff) | |
download | systemd-fe20121a4c36bdd26465b22805016e4596457881.tar.xz systemd-fe20121a4c36bdd26465b22805016e4596457881.zip |
sd-device: use strjoin instead of asprintf
strjoin should be faster for string concatenation.
Also drop "_"-prefix from function prototypes.
Diffstat (limited to '')
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index bd3b67c55c..3bba17aff8 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -320,24 +320,22 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s return -ENODEV; } -int device_set_devtype(sd_device *device, const char *_devtype) { - _cleanup_free_ char *devtype = NULL; +int device_set_devtype(sd_device *device, const char *devtype) { + _cleanup_free_ char *t = NULL; int r; assert(device); - assert(_devtype); + assert(devtype); - devtype = strdup(_devtype); - if (!devtype) + t = strdup(devtype); + if (!t) return -ENOMEM; - r = device_add_property_internal(device, "DEVTYPE", devtype); + r = device_add_property_internal(device, "DEVTYPE", t); if (r < 0) return r; - free_and_replace(device->devtype, devtype); - - return 0; + return free_and_replace(device->devtype, t); } int device_set_ifindex(sd_device *device, const char *name) { @@ -359,30 +357,25 @@ int device_set_ifindex(sd_device *device, const char *name) { return 0; } -int device_set_devname(sd_device *device, const char *_devname) { - _cleanup_free_ char *devname = NULL; +int device_set_devname(sd_device *device, const char *devname) { + _cleanup_free_ char *t = NULL; int r; assert(device); - assert(_devname); + assert(devname); - if (_devname[0] != '/') { - r = asprintf(&devname, "/dev/%s", _devname); - if (r < 0) - return -ENOMEM; - } else { - devname = strdup(_devname); - if (!devname) - return -ENOMEM; - } + if (devname[0] != '/') + t = strjoin("/dev/", devname); + else + t = strdup(devname); + if (!t) + return -ENOMEM; - r = device_add_property_internal(device, "DEVNAME", devname); + r = device_add_property_internal(device, "DEVNAME", t); if (r < 0) return r; - free_and_replace(device->devname, devname); - - return 0; + return free_and_replace(device->devname, t); } int device_set_devmode(sd_device *device, const char *_devmode) { @@ -1250,17 +1243,15 @@ int device_get_id_filename(sd_device *device, const char **ret) { if (!subsystem) return -EINVAL; - if (streq(subsystem, "drivers")) { + + if (streq(subsystem, "drivers")) /* the 'drivers' pseudo-subsystem is special, and needs the real subsystem * encoded as well */ - r = asprintf(&id, "+drivers:%s:%s", device->driver_subsystem, sysname); - if (r < 0) - return -ENOMEM; - } else { - r = asprintf(&id, "+%s:%s", subsystem, sysname); - if (r < 0) - return -ENOMEM; - } + id = strjoin("+drivers:", device->driver_subsystem, ":", sysname); + else + id = strjoin("+", subsystem, ":", sysname); + if (!id) + return -ENOMEM; } device->id_filename = TAKE_PTR(id); |