r = sd_device_get_property_value(udev_device->device, "SEQNUM", &seqnum);
if (r == -ENOENT)
return 0;
- else if (r < 0) {
- errno = -r;
- return 0;
- }
+ else if (r < 0)
+ return_with_errno(0, r);
r = safe_atollu(seqnum, &ret);
- if (r < 0) {
- errno = -r;
- return 0;
- }
+ if (r < 0)
+ return_with_errno(0, r);
return ret;
}
assert_return_errno(udev_device, makedev(0, 0), EINVAL);
r = sd_device_get_devnum(udev_device->device, &devnum);
- if (r < 0) {
- if (r != -ENOENT)
- errno = -r;
+ if (r == -ENOENT)
return makedev(0, 0);
- }
+ if (r < 0)
+ return_with_errno(makedev(0, 0), r);
return devnum;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_driver(udev_device->device, &driver);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return driver;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_devtype(udev_device->device, &devtype);
- if (r < 0) {
- if (r != -ENOENT)
- errno = -r;
+ if (r == -ENOENT)
return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return devtype;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_subsystem(udev_device->device, &subsystem);
- if (r < 0) {
- errno = -r;
- return NULL;
- } else if (!subsystem)
- errno = ENODATA;
+ if (r < 0)
+ return_with_errno(NULL, r);
+ if (!subsystem)
+ return_with_errno(NULL, ENODATA);
return subsystem;
}
* Returns: the property string, or #NULL if there is no such property.
**/
_public_ const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) {
- const char *value = NULL;
+ const char *value;
int r;
assert_return_errno(udev_device && key, NULL, EINVAL);
r = sd_device_get_property_value(udev_device->device, key, &value);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return value;
}
assert(device);
udev_device = new(struct udev_device, 1);
- if (!udev_device) {
- errno = ENOMEM;
- return NULL;
- }
+ if (!udev_device)
+ return_with_errno(NULL, ENOMEM);
*udev_device = (struct udev_device) {
.n_ref = 1,
int r;
r = sd_device_new_from_syspath(&device, syspath);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(udev, device);
}
int r;
r = sd_device_new_from_devnum(&device, type, devnum);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(udev, device);
}
int r;
r = sd_device_new_from_device_id(&device, id);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(udev, device);
}
int r;
r = sd_device_new_from_subsystem_sysname(&device, subsystem, sysname);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(udev, device);
}
int r;
r = device_new_from_strv(&device, environ);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(udev, device);
}
assert_return_errno(child, NULL, EINVAL);
r = sd_device_get_parent(child->device, &parent);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(child->udev, parent);
}
/* first find the correct sd_device */
r = sd_device_get_parent_with_subsystem_devtype(udev_device->device, subsystem, devtype, &parent);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
/* then walk the chain of udev_device parents until the corresponding
one is found */
- while ((udev_device = udev_device_get_parent(udev_device))) {
+ while ((udev_device = udev_device_get_parent(udev_device)))
if (udev_device->device == parent)
return udev_device;
- }
- errno = ENOENT;
- return NULL;
+ return_with_errno(NULL, ENOENT);
}
/**
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_devpath(udev_device->device, &devpath);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return devpath;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_syspath(udev_device->device, &syspath);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return syspath;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_sysname(udev_device->device, &sysname);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return sysname;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_sysnum(udev_device->device, &sysnum);
- if (r < 0) {
- if (r != -ENOENT)
- errno = -r;
+ if (r == -ENOENT)
return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return sysnum;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_devname(udev_device->device, &devnode);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return devnode;
}
* Returns: the kernel action value, or #NULL if there is no action value available.
**/
_public_ const char *udev_device_get_action(struct udev_device *udev_device) {
- const char *action = NULL;
+ const char *action;
int r;
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_property_value(udev_device->device, "ACTION", &action);
- if (r < 0 && r != -ENOENT) {
- errno = -r;
+ if (r == -ENOENT)
return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return action;
}
assert_return(udev_device, -EINVAL);
r = sd_device_get_usec_since_initialized(udev_device->device, &ts);
- if (r < 0) {
- errno = -r;
- return 0;
- }
+ if (r < 0)
+ return_with_errno(0, r);
return ts;
}
assert_return_errno(udev_device, NULL, EINVAL);
r = sd_device_get_sysattr_value(udev_device->device, sysattr, &value);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return value;
}
assert_return(udev_device, -EINVAL);
r = sd_device_get_is_initialized(udev_device->device);
- if (r < 0) {
- errno = -r;
- return 0;
- }
+ if (r < 0)
+ return_with_errno(0, r);
return r;
}