bool hidrd_fmtpva(char **pstr, hidrd_fmt_type type, va_list *pap) { char *str; switch (type) { case HIDRD_FMT_TYPE_NULL: str = NULL; break; case HIDRD_FMT_TYPE_S32: str = HIDRD_DEC_TO_STR(s32, va_arg(*pap, int32_t)); if (str == NULL) return false; break; case HIDRD_FMT_TYPE_U32: str = HIDRD_DEC_TO_STR(u32, va_arg(*pap, uint32_t)); if (str == NULL) return false; break; case HIDRD_FMT_TYPE_STRDUP: { const char *arg = va_arg(*pap, const char *); assert(arg != NULL); str = strdup(arg); if (str == NULL) return false; } break; case HIDRD_FMT_TYPE_STROWN: { char *arg = va_arg(*pap, char *); assert(arg != NULL); str = arg; } break; case HIDRD_FMT_TYPE_HEX: { const void *buf = va_arg(*pap, const void *); size_t size = va_arg(*pap, size_t); assert(buf != NULL || size == 0); str = hidrd_hex_buf_to_str(buf, size); if (str == NULL) return false; } break; case HIDRD_FMT_TYPE_SHEX: { void *buf = va_arg(*pap, void *); size_t size = va_arg(*pap, size_t); assert(buf != NULL || size == 0); str = hidrd_hex_buf_to_sstr(buf, size); if (str == NULL) return false; } break; default: assert(!"Unknown string format"); return false; } if (pstr != NULL) *pstr = str; else free(str); return true; }
char * hidrd_opt_type_format_u32(uint32_t val) { return HIDRD_DEC_TO_STR(u32, val); }