+#define strfieldcat(to, from) \
+do { \
+ to[sizeof(to)-1] = '\0'; \
+ strncat(to, from, sizeof(to) - strlen(to)-1); \
+} while (0)
+
+#define strnfieldcpy(to, from, maxsize) \
+do { \
+ to[maxsize-1] = '\0'; \
+ strncpy(to, from, maxsize-1); \
+} while (0)
+
+#define strnfieldcat(to, from, maxsize) \
+do { \
+ to[maxsize-1] = '\0'; \
+ strncat(to, from, maxsize - strlen(to)-1); \
+} while (0)
+
+#define strintcat(to, i) \
+do { \
+ to[sizeof(to)-1] = '\0'; \
+ snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \
+} while (0)
+
+#define strnintcat(to, i, maxsize) \
+do { \
+ to[maxsize-1] = '\0'; \
+ snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \
+} while (0)
+
+#define foreach_strpart(str, separator, pos, len) \
+ for(pos = 0, len = strcspn(str, separator); \
+ (pos) < strlen(str); \
+ pos = pos + (len) + 1, len = strcspn((str) + pos, separator)) \
+ if (len > 0)
+
+static inline char *get_action(void)
+{
+ char *action;
+
+ action = getenv("ACTION");
+ if (action != NULL && strlen(action) > ACTION_SIZE)
+ action[ACTION_SIZE-1] = '\0';
+
+ return action;
+}
+
+static inline char *get_devpath(void)
+{
+ char *devpath;
+
+ devpath = getenv("DEVPATH");
+ if (devpath != NULL && strlen(devpath) > DEVPATH_SIZE)
+ devpath[DEVPATH_SIZE-1] = '\0';
+
+ return devpath;
+}
+
+static inline char *get_seqnum(void)
+{
+ char *seqnum;
+
+ seqnum = getenv("SEQNUM");
+
+ return seqnum;
+}
+
+static inline char *get_subsystem(char *subsystem)
+{
+ if (subsystem != NULL && strlen(subsystem) > SUBSYSTEM_SIZE)
+ subsystem[SUBSYSTEM_SIZE-1] = '\0';
+
+ return subsystem;
+}
+