int device_get_sysattr_int(sd_device *device, const char *sysattr, int *ret);
int device_get_sysattr_unsigned_full(sd_device *device, const char *sysattr, unsigned base, unsigned *ret);
static inline int device_get_sysattr_unsigned(sd_device *device, const char *sysattr, unsigned *ret) {
- return device_get_sysattr_unsigned_full(device, sysattr, 0, ret);
+ return device_get_sysattr_unsigned_full(device, sysattr, /* base= */ 0, ret);
+}
+int device_get_sysattr_u8_full(sd_device *device, const char *sysattr, unsigned base, uint8_t *ret);
+static inline int device_get_sysattr_u8(sd_device *device, const char *sysattr, uint8_t *ret) {
+ return device_get_sysattr_u8_full(device, sysattr, /* base= */ 0, ret);
+}
+int device_get_sysattr_u16_full(sd_device *device, const char *sysattr, unsigned base, uint16_t *ret);
+static inline int device_get_sysattr_u16(sd_device *device, const char *sysattr, uint16_t *ret) {
+ return device_get_sysattr_u16_full(device, sysattr, /* base= */ 0, ret);
}
int device_get_sysattr_u32_full(sd_device *device, const char *sysattr, unsigned base, uint32_t *ret);
static inline int device_get_sysattr_u32(sd_device *device, const char *sysattr, uint32_t *ret) {
- return device_get_sysattr_u32_full(device, sysattr, 0, ret);
+ return device_get_sysattr_u32_full(device, sysattr, /* base= */ 0, ret);
}
int device_get_sysattr_u64(sd_device *device, const char *sysattr, uint64_t *ret);
int device_get_sysattr_bool(sd_device *device, const char *sysattr);
DEFINE_DEVICE_GET_SYSATTR_PARSE(int, int, safe_atoi);
DEFINE_DEVICE_GET_SYSATTR_PARSE_BASE(unsigned, unsigned, safe_atou_full);
+DEFINE_DEVICE_GET_SYSATTR_PARSE_BASE(u8, uint8_t, safe_atou8_full);
+DEFINE_DEVICE_GET_SYSATTR_PARSE_BASE(u16, uint16_t, safe_atou16_full);
DEFINE_DEVICE_GET_SYSATTR_PARSE_BASE(u32, uint32_t, safe_atou32_full);
DEFINE_DEVICE_GET_SYSATTR_PARSE(u64, uint64_t, safe_atou64);
uint32_t u32;
ASSERT_OK_POSITIVE(device_get_sysattr_u32(d, "ifindex", &u32));
ASSERT_EQ(u32, (uint32_t) ifindex);
+
+ if (ifindex <= UINT16_MAX) {
+ uint16_t u16;
+ ASSERT_OK_POSITIVE(device_get_sysattr_u16(d, "ifindex", &u16));
+ ASSERT_EQ(u16, (uint16_t) ifindex);
+ }
+
+ if (ifindex <= UINT8_MAX) {
+ uint8_t u8;
+ ASSERT_OK_POSITIVE(device_get_sysattr_u8(d, "ifindex", &u8));
+ ASSERT_EQ(u8, (uint8_t) ifindex);
+ }
}
}