/** * Convert a given fancy human-readable size to bytes. * * @param fancy_size human readable string (i.e. 1 MB) * @param size set to the size in bytes * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, unsigned long long *size) { static const struct ConversionTable table[] = { { "B", 1}, { "KiB", 1024}, { "kB", 1000}, { "MiB", 1024 * 1024}, { "MB", 1000 * 1000}, { "GiB", 1024 * 1024 * 1024}, { "GB", 1000 * 1000 * 1000}, { "TiB", 1024LL * 1024LL * 1024LL * 1024LL}, { "TB", 1000LL * 1000LL * 1000LL * 1024LL}, { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL}, { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL}, { NULL, 0} }; return convert_with_table (fancy_size, table, size); }
/** * Convert a given fancy human-readable time to our internal * representation. * * @param fancy_time human readable string (i.e. 1 minute) * @param rtime set to the relative time * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, struct GNUNET_TIME_Relative *rtime) { static const struct ConversionTable table[] = { { "ms", 1}, { "s", 1000}, { "\"", 1000}, { "m", 60 * 1000}, { "min", 60 * 1000}, { "minutes", 60 * 1000}, { "'", 60 * 1000}, { "h", 60 * 60 * 1000}, { "d", 24 * 60 * 60 * 1000}, { "day", 24 * 60 * 60 * 1000}, { "days", 24 * 60 * 60 * 1000}, { "a", 31536000000LL /* year */ }, { NULL, 0} }; int ret; unsigned long long val; if (0 == strcasecmp ("forever", fancy_time)) { *rtime = GNUNET_TIME_UNIT_FOREVER_REL; return GNUNET_OK; } ret = convert_with_table (fancy_time, table, &val); rtime->rel_value = (uint64_t) val; return ret; }