/** * Put an integer into table as string type. * * @param tbl qhasharr_t container pointer. * @param key key string * @param value value integer * * @return true if successful, otherwise returns false * @retval errno will be set in error condition. * - ENOBUFS : Table doesn't have enough space to store the object. * - EINVAL : Invalid argument. * - EFAULT : Unexpected error. Data structure is not constant. * * @note * The integer will be converted to a string object and stored as string object. */ bool qhasharr_putint(qhasharr_t *tbl, const char *key, int64_t num) { if (NULL == tbl || NULL == key) { errno = EINVAL; return false; } char str[20+1]; snprintf(str, sizeof(str), "%"PRId64, num); return qhasharr_putstr(tbl, key, str); }
/** * qhasharr->putstrf(): Put a formatted string into this table. * * @param tbl qhasharr_t container pointer. * @param name key string * @param format formatted string data. * * @return true if successful, otherwise returns false. * @retval errno will be set in error condition. * - ENOBUFS : Table doesn't have enough space to store the object. * - ENOMEM : System memory allocation failure. * - EINVAL : Invalid argument. * - EFAULT : Unexpected error. Data structure is not constant. */ bool qhasharr_putstrf(qhasharr_t *tbl, const char *name, const char *format, ...) { char *str; DYNAMIC_VSPRINTF(str, format); if (str == NULL) { errno = ENOMEM; return false; } bool ret = qhasharr_putstr(tbl, name, str); free(str); return ret; }