+
+ result = stat(dir, &st);
+ if(result == -1 && errno != ENOENT) {
+ return -1;
+ }
+ else if(result == -1) {
+ /* ENOENT */
+ int result;
+
+ /* mkdir mode to 0777 */
+ result = mkdir_p(dir, S_IRWXU | S_IRWXG | S_IRWXO);
+ if(result != 0) {
+ ERR("executing in recursive creation of directory %s", dir);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+char * ustcomm_print_data(char *data_field, int field_size,
+ int *offset, const char *format, ...)
+{
+ va_list args;
+ int count, limit;
+ char *ptr = USTCOMM_POISON_PTR;
+
+ limit = field_size - *offset;
+ va_start(args, format);
+ count = vsnprintf(&data_field[*offset], limit, format, args);
+ va_end(args);
+
+ if (count < limit && count > -1) {
+ ptr = NULL + *offset;
+ *offset = *offset + count + 1;
+ }
+
+ return ptr;
+}
+
+char * ustcomm_restore_ptr(char *ptr, char *data_field, int data_field_size)
+{
+ if ((unsigned long)ptr > data_field_size ||
+ ptr == USTCOMM_POISON_PTR) {
+ return NULL;