+#define MONITOR_BUF_SIZE 4096
+ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf)
+{
+ if (udev_device->monitor_buf_len == 0) {
+ const char *action;
+ struct udev_list_entry *list_entry;
+ size_t bufpos;
+ size_t len;
+
+ free(udev_device->monitor_buf);
+ udev_device->monitor_buf = malloc(MONITOR_BUF_SIZE);
+ if (udev_device->monitor_buf == NULL)
+ return -ENOMEM;
+
+ /* header <action>@<devpath> */
+ action = udev_device_get_action(udev_device);
+ if (action == NULL)
+ return -EINVAL;
+ bufpos = util_strlcpy(udev_device->monitor_buf, action, MONITOR_BUF_SIZE);
+ len = util_strlcpy(&udev_device->monitor_buf[bufpos], "@", MONITOR_BUF_SIZE-bufpos);
+ if (len >= MONITOR_BUF_SIZE-bufpos)
+ return -EINVAL;
+ bufpos += len;
+ len = util_strlcpy(&udev_device->monitor_buf[bufpos],
+ udev_device_get_devpath(udev_device),
+ MONITOR_BUF_SIZE-bufpos);
+ if (len+1 >= MONITOR_BUF_SIZE-bufpos)
+ return -EINVAL;
+ bufpos += len+1;
+
+ /* property strings */
+ udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
+ len = util_strlcpy(&udev_device->monitor_buf[bufpos],
+ udev_list_entry_get_name(list_entry), MONITOR_BUF_SIZE-bufpos);
+ if (len >= MONITOR_BUF_SIZE-bufpos)
+ return -EINVAL;
+ bufpos += len;
+ len = util_strlcpy(&udev_device->monitor_buf[bufpos], "=", MONITOR_BUF_SIZE-bufpos);
+ if (len >= MONITOR_BUF_SIZE-bufpos)
+ return -EINVAL;
+ bufpos += len;
+ len = util_strlcpy(&udev_device->monitor_buf[bufpos], udev_list_entry_get_value(list_entry),
+ MONITOR_BUF_SIZE-bufpos);
+ if (len+1 >= MONITOR_BUF_SIZE-bufpos)
+ return -EINVAL;
+ bufpos += len+1;
+ }
+ udev_device->monitor_buf_len = bufpos;
+ }
+ *buf = udev_device->monitor_buf;
+ return udev_device->monitor_buf_len;
+}
+