size_t parse_size_t(const char* str, size_t def) { if ( !str || !*str ) return def; char* endptr; size_t ret = (size_t) strtoumax(str, &endptr, 10); if ( *endptr ) return def; return ret; }
static inline int ini_process_word(const char* curr_name, const char* value, const char* option_name, word* target, ini_value_list_type* value_names) { if(strcasecmp(curr_name, option_name) == 0) { if (strcasecmp(value, "default") != 0) { int named_value = ini_get_named_value(value, value_names); *target = (named_value == INI_NO_VALID_NAME) ? ((word) strtoumax(value, NULL, 0)) : ((word) named_value); } return 1; // finished; don't look for more possible options that curr_name can be } return 0; // not the right option; should check another option_name }
status_t IntegerValueFormatter::_ValidateUnsigned(const BString& input, type_code type, ::Value*& _output, integer_format format, bool wantsValue) const { const char* text = input.String(); int32 base = format == INTEGER_FORMAT_UNSIGNED ? 10 : 16; char *parseEnd = NULL; uintmax_t parsedValue = strtoumax(text, &parseEnd, base); if (parseEnd - text < input.Length() && !isspace(*parseEnd)) return B_BAD_VALUE; BVariant newValue; switch (type) { case B_UINT8_TYPE: { if (parsedValue > UINT8_MAX) return B_BAD_VALUE; newValue.SetTo((uint8)parsedValue); break; } case B_UINT16_TYPE: { if (parsedValue > UINT16_MAX) return B_BAD_VALUE; newValue.SetTo((uint16)parsedValue); break; } case B_UINT32_TYPE: { if (parsedValue > UINT32_MAX) return B_BAD_VALUE; newValue.SetTo((uint32)parsedValue); break; } case B_UINT64_TYPE: { newValue.SetTo((uint64)parsedValue); break; } default: return B_BAD_VALUE; } if (wantsValue) { _output = new(std::nothrow) IntegerValue(newValue); if (_output == NULL) return B_NO_MEMORY; } return B_OK; }
int main() { { int8_t i1 = 0; int16_t i2 = 0; int32_t i3 = 0; int64_t i4 = 0; } { uint8_t i1 = 0; uint16_t i2 = 0; uint32_t i3 = 0; uint64_t i4 = 0; } { int_least8_t i1 = 0; int_least16_t i2 = 0; int_least32_t i3 = 0; int_least64_t i4 = 0; } { uint_least8_t i1 = 0; uint_least16_t i2 = 0; uint_least32_t i3 = 0; uint_least64_t i4 = 0; } { int_fast8_t i1 = 0; int_fast16_t i2 = 0; int_fast32_t i3 = 0; int_fast64_t i4 = 0; } { uint_fast8_t i1 = 0; uint_fast16_t i2 = 0; uint_fast32_t i3 = 0; uint_fast64_t i4 = 0; } { intptr_t i1 = 0; uintptr_t i2 = 0; intmax_t i3 = 0; uintmax_t i4 = 0; } { imaxdiv_t i1 = {0}; } intmax_t i = 0; static_assert((std::is_same<decltype(imaxabs(i)), intmax_t>::value), ""); static_assert((std::is_same<decltype(imaxdiv(i, i)), imaxdiv_t>::value), ""); static_assert((std::is_same<decltype(strtoimax("", (char**)0, 0)), intmax_t>::value), ""); static_assert((std::is_same<decltype(strtoumax("", (char**)0, 0)), uintmax_t>::value), ""); static_assert((std::is_same<decltype(wcstoimax(L"", (wchar_t**)0, 0)), intmax_t>::value), ""); static_assert((std::is_same<decltype(wcstoumax(L"", (wchar_t**)0, 0)), uintmax_t>::value), ""); }
static uintmax_t hf_probe_volume_getenv_uintmax (const char *name) { char *str; g_return_val_if_fail(name != NULL, 0); str = getenv(name); return str ? strtoumax(str, NULL, 10) : 0; }
/** * Convert a `char*` to `a size_t` * * @param str The `char*` * @return The `size_t` */ static size_t parse_size(const char* str) { char buf[3 * sizeof(size_t) + 2]; size_t rc; rc = (size_t)strtoumax(str, NULL, 10); if (sprintf(buf, "%zu", rc), strcmp(buf, str)) return 0; return rc; }
ValgrindResult* valgrindXML_evaluate(char *xml_path,int testing_framework) { char *docname; xmlDocPtr doc; xmlChar *xpath = (xmlChar*) "//errorcounts/pair/count"; xmlNodeSetPtr nodeset; xmlXPathObjectPtr result; int i; docname = xml_path; doc = getdoc(docname); result = getnodeset (doc, xpath); ValgrindResult *valgrindResult=NULL; //Get all the errors first if (result) { nodeset = result->nodesetval; if(nodeset->nodeNr==0){ //NO valgrind errors for this mutant return NULL; } valgrindResult= malloc(sizeof(ValgrindResult)); //Initialization of valgrindResult valgrindResult->valgrind_error_count=0; valgrindResult->unique_valgrind_error_count=0; //Capturing results in valgrindResult valgrindResult->unique_valgrind_error_count=nodeset->nodeNr; valgrindResult->valgrindErrors = malloc(nodeset->nodeNr*sizeof(ValgrindError)); for (i=0; i < nodeset->nodeNr; i++) { //Get <count></count> xmlNodePtr countNode = nodeset->nodeTab[i]; //Get <unique></unique> xmlNodePtr uniqueNode = xmlNextElementSibling(countNode); //Values for both of the nodes xmlChar *count_value = xmlNodeListGetString(doc, countNode->xmlChildrenNode, 1); xmlChar *unique_value = xmlNodeListGetString(doc, uniqueNode->xmlChildrenNode, 1); int error_count = (int)strtoumax((char*)count_value, NULL, 10); valgrindResult->valgrind_error_count+=error_count; //For each unique value, get all its error nodes evaluate_error_nodes(&valgrindResult->valgrindErrors[i],doc,error_count,unique_value,testing_framework); xmlFree(count_value); xmlFree(unique_value); } xmlXPathFreeObject (result); } xmlFreeDoc(doc); xmlCleanupParser(); return valgrindResult; }
void cmd_parse_add(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "hp:l:n:k:")) != -1) { switch (opt) { case 'h': cmd_usage_add(); exit(EXIT_FAILURE); case 'p': cmd_profile_name = strdup(optarg); break; case 'l': cmd_character_count = strtoumax(optarg, NULL, 10); break; case 'n': cmd_password_count = strtoumax(optarg, NULL, 10); break; case 'k': cmd_gpg_key_id = strdup(optarg); break; default: exit(EXIT_FAILURE); break; } } argc -= optind; argv += optind; if (argc > 0) { char *s = join_list(' ', argc, argv); cmd_add_prefix = mbs_duplicate_as_wcs(s); if (cmd_add_prefix == NULL) { err(EXIT_FAILURE, "unable to read the prefix (wrong " "locale?)"); } xfree(s); } }
static bool next_field_uintmax(char** current, uintmax_t* result) { char* id_str = next_field(current); if ( !id_str ) return false; char* id_endptr; uintmax_t id_umax = strtoumax(id_str, &id_endptr, 10); if ( *id_endptr ) return false; *result = id_umax; return true; }
static bool _strtoumax(const char *str, int base, uintmax_t *out) { char *endptr = NULL; errno = 0; uintmax_t ret = strtoumax(str, &endptr, base); if (errno != 0) return false; if (*endptr != '\0') { errno = EINVAL; return false; } *out = ret; return true; }
int main() { test<int8_t >(); test<int16_t>(); test<int32_t>(); test<int64_t>(); test<uint8_t >(); test<uint16_t>(); test<uint32_t>(); test<uint64_t>(); test<int_least8_t >(); test<int_least16_t>(); test<int_least32_t>(); test<int_least64_t>(); test<uint_least8_t >(); test<uint_least16_t>(); test<uint_least32_t>(); test<uint_least64_t>(); test<int_fast8_t >(); test<int_fast16_t>(); test<int_fast32_t>(); test<int_fast64_t>(); test<uint_fast8_t >(); test<uint_fast16_t>(); test<uint_fast32_t>(); test<uint_fast64_t>(); test<intptr_t >(); test<uintptr_t>(); test<intmax_t >(); test<uintmax_t>(); { imaxdiv_t i1 = {}; ((void)i1); // Prevent unused warning } intmax_t i = 0; ((void)i); // Prevent unused warning static_assert((std::is_same<decltype(imaxabs(i)), intmax_t>::value), ""); static_assert((std::is_same<decltype(imaxdiv(i, i)), imaxdiv_t>::value), ""); static_assert((std::is_same<decltype(strtoimax("", (char**)0, 0)), intmax_t>::value), ""); static_assert((std::is_same<decltype(strtoumax("", (char**)0, 0)), uintmax_t>::value), ""); static_assert((std::is_same<decltype(wcstoimax(L"", (wchar_t**)0, 0)), intmax_t>::value), ""); static_assert((std::is_same<decltype(wcstoumax(L"", (wchar_t**)0, 0)), uintmax_t>::value), ""); }
static uintmax_t read_number(void) { uintmax_t number; errno = 0; number = strtoumax(optarg, NULL, 10); if ((number == 0 || number == UINTMAX_MAX) && errno != 0) { perror("strtoumax"); exit(EXIT_FAILURE); } return number; }
static void assign_time_option (char **sval, time_t *tval, const char *input) { uintmax_t u; char *p; time_t t = u = strtoumax (input, &p, 10); if (t != u || *p || errno == ERANGE) ERROR ((0, 0, _("Time stamp is out of allowed range"))); else { *tval = t; assign_string (sval, input); } }
int main(int argc, char **argv) { estats_error* err = NULL; struct estats_nl_client* cl = NULL; estats_val_data* data = NULL; int cid, i, j; int opt, option; char varname[24]; char *endptr, *str; uintmax_t val; if (argc < 4) { usage(); exit(EXIT_FAILURE); } while ((opt = getopt(argc, argv, "h")) != -1) { switch (opt) { case 'h': usage(); exit(EXIT_SUCCESS); break; default: exit(EXIT_FAILURE); break; } } cid = atoi(argv[1]); strncpy(varname, argv[2], 24); str = argv[3]; val = strtoumax(str, &endptr, 10); Chk(estats_nl_client_init(&cl)); Chk(estats_write_var(varname, (uint32_t)val, cid, cl)); Cleanup: estats_nl_client_destroy(&cl); if (err != NULL) { PRINT_AND_FREE(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
static int parse_port_option(const char *arg) { assert(arg != NULL); errno = 0; uintmax_t num = strtoumax(arg, NULL, 10); if (errno != 0) { mushroom_log_fatal(strerror(errno)); } if (num <= 0) { mushroom_log_fatal("invalid port number: %s", arg); } return (int)num; }
static void md_prthumanval(char *length) { char buf[6]; uintmax_t bytes; char *endptr; errno = 0; bytes = strtoumax(length, &endptr, 10); if (errno != 0 || *endptr != '\0' || bytes > INT64_MAX) return; humanize_number(buf, sizeof(buf), (int64_t)bytes, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); (void)printf("%6s", buf); }
/* * parse_config_integer -- (internal) parse integer value */ static inline uintmax_t parse_config_integer(const char *value, uintmax_t max_value) { char *endptr; uintmax_t v = strtoumax(value, &endptr, 10); if (endptr != value + strlen(value)) errno = EINVAL; else if (v > max_value) errno = ERANGE; if (errno != 0) return max_value; return v; }
static int l_filter_accept(lua_State *L) { uint64_t id; const char *s_id; if (lua_gettop(L) != 1) return (0); s_id = luaL_checklstring(L, 1, NULL); id = strtoumax(s_id, (char **)NULL, 10); filter_api_accept(id); return (0); }
static int ask_number(struct fdisk_context *cxt, struct fdisk_ask *ask, char *buf, size_t bufsz) { char prompt[128] = { '\0' }; const char *q = fdisk_ask_get_query(ask); const char *range = fdisk_ask_number_get_range(ask); uint64_t dflt = fdisk_ask_number_get_default(ask), low = fdisk_ask_number_get_low(ask), high = fdisk_ask_number_get_high(ask); assert(q); DBG(ASK, dbgprint("asking for number ['%s', <%jd,%jd>, default=%jd, range: %s]", q, low, high, dflt, range)); if (range && dflt >= low && dflt <= high) snprintf(prompt, sizeof(prompt), _("%s (%s, default %jd): "), q, range, dflt); else if (dflt >= low && dflt <= high) snprintf(prompt, sizeof(prompt), _("%s (%jd-%jd, default %jd): "), q, low, high, dflt); else snprintf(prompt, sizeof(prompt), _("%s (%jd-%jd): "), q, low, high); do { int rc = get_user_reply(cxt, prompt, buf, bufsz); if (rc) return rc; if (!*buf && dflt >= low && dflt <= high) return fdisk_ask_number_set_result(ask, dflt); else if (isdigit_string(buf)) { char *end; uint64_t num; errno = 0; num = strtoumax(buf, &end, 10); if (errno || buf == end || (end && *end)) continue; if (num >= low && num <= high) return fdisk_ask_number_set_result(ask, num); printf(_("Value out of range.\n")); } } while (1); return -1; }
static ssize_t vbf_fetch_number(const char *nbr, int radix) { uintmax_t cll; ssize_t cl; char *q; if (*nbr == '\0') return (-1); cll = strtoumax(nbr, &q, radix); if (q == NULL || *q != '\0') return (-1); cl = (ssize_t)cll; if((uintmax_t)cl != cll) /* Protect against bogusly large values */ return (-1); return (cl); }
/* * Convert an expression of the following forms to a uintmax_t. * 1) A positive decimal number. * 2) A positive decimal number followed by a 'b' or 'B' (mult by 512). * 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10). * 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20). * 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30). * 6) A positive decimal number followed by a 't' or 'T' (mult by 1 << 40). * 7) A positive decimal number followed by a 'p' or 'P' (mult by 1 << 50). * 8) A positive decimal number followed by a 'w' or 'W' (mult by sizeof int). * 9) Two or more positive decimal numbers (with/without [BbKkMmGgWw]) * separated by 'x' or 'X' (also '*' for backwards compatibility), * specifying the product of the indicated values. */ static uintmax_t get_num(const char *val) { uintmax_t num, mult, prevnum; char *expr; errno = 0; num = strtoumax(val, &expr, 0); if (expr == val) /* No valid digits. */ errx(1, "%s: invalid numeric value", oper); if (errno != 0) err(1, "%s", oper); mult = postfix_to_mult(*expr); if (mult != 0) { prevnum = num; num *= mult; /* Check for overflow. */ if (num / mult != prevnum) goto erange; expr++; } switch (*expr) { case '\0': break; case '*': /* Backward compatible. */ case 'X': case 'x': mult = get_num(expr + 1); prevnum = num; num *= mult; if (num / mult == prevnum) break; erange: errx(1, "%s: %s", oper, strerror(ERANGE)); default: errx(1, "%s: illegal numeric value", oper); } return (num); }
static int parse_size(struct sun_disklabel *sl, int part, char *size) { uintmax_t nsectors; uintmax_t total; uintmax_t n; char *p; int i; nsectors = 0; n = strtoumax(size, &p, 10); if (*p != '\0') { if (strcmp(size, "*") == 0) { total = sl->sl_ncylinders * sl->sl_ntracks * sl->sl_nsectors; for (i = 0; i < part; i++) { if (i == 2) continue; nsectors += sl->sl_part[i].sdkp_nsectors; } n = total - nsectors; } else if (p[1] == '\0' && (p[0] == 'C' || p[0] == 'c')) { n = n * sl->sl_ntracks * sl->sl_nsectors; } else if (p[1] == '\0' && (p[0] == 'K' || p[0] == 'k')) { n = roundup((n * 1024) / 512, sl->sl_ntracks * sl->sl_nsectors); } else if (p[1] == '\0' && (p[0] == 'M' || p[0] == 'm')) { n = roundup((n * 1024 * 1024) / 512, sl->sl_ntracks * sl->sl_nsectors); } else if (p[1] == '\0' && (p[0] == 'S' || p[0] == 's')) { /* size in sectors, no action neded */ } else if (p[1] == '\0' && (p[0] == 'G' || p[0] == 'g')) { n = roundup((n * 1024 * 1024 * 1024) / 512, sl->sl_ntracks * sl->sl_nsectors); } else return (-1); } else if (cflag) { n = n * sl->sl_ntracks * sl->sl_nsectors; } sl->sl_part[part].sdkp_nsectors = n; return (0); }
/** * \brief Parse string containing time size (1m, 1h, etc). * * \param str String to parse. * * \retval size on success. * \retval 0 on failure. */ uint64_t SCParseTimeSizeString (const char *str) { uint64_t size = 0; uint64_t modifier = 1; char last = str[strlen(str)-1]; switch (last) { case '0' ... '9': break; /* seconds */ case 's': break; /* minutes */ case 'm': modifier = 60; break; /* hours */ case 'h': modifier = 60 * 60; break; /* days */ case 'd': modifier = 60 * 60 * 24; break; /* weeks */ case 'w': modifier = 60 * 60 * 24 * 7; break; /* invalid */ default: return 0; } errno = 0; size = strtoumax(str, NULL, 10); if (errno) { return 0; } return (size * modifier); }
/* Parse a uintmax_t, put it into *result; return 0 on failure, else 1. */ int opt_umax(const char *value, uintmax_t *result) { int oerrno = errno; uintmax_t m; char *endp; m = strtoumax(value, &endp, 0); if (*endp || endp == value || (m == UINTMAX_MAX && errno == ERANGE) || (m == 0 && errno != 0)) { BIO_printf(bio_err, "%s: Can't parse \"%s\" as a number\n", prog, value); errno = oerrno; return 0; } *result = m; errno = oerrno; return 1; }
intmax_t strtoimax(const char *s1, char **p, int base) { const unsigned char *s = (const void *)s1; int sign = 0; uintmax_t x; /* Initial whitespace */ for (; isspace(*s); s++); /* Optional sign */ if (*s == '-') sign = *s++; else if (*s == '+') s++; x = strtoumax((const void *)s, p, base); if (x > INTMAX_MAX) { if (!sign || -x != INTMAX_MIN) errno = ERANGE; return sign ? INTMAX_MIN : INTMAX_MAX; } return sign ? -x : x; }
static uintmax_t getuintmax(void) { uintmax_t val = 0; char *cp, *ep; cp = *gargv; if (cp == NULL) goto out; gargv++; val = (unsigned char) cp[1]; if (*cp == '\"' || *cp == '\'') goto out; errno = 0; val = strtoumax(cp, &ep, 0); check_conversion(cp, ep); out: return val; }
/*! \brief SVSHOST command handler * * \param source_p Pointer to allocated Client struct from which the message * originally comes from. This can be a local or remote client. * \param parc Integer holding the number of supplied arguments. * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL * pointers. * \note Valid arguments for this command are: * - parv[0] = command * - parv[1] = nickname * - parv[2] = TS * - parv[3] = host name */ static int ms_svshost(struct Client *source_p, int parc, char *parv[]) { if (!HasFlag(source_p, FLAGS_SERVICE)) return 0; struct Client *target_p; if ((target_p = find_person(source_p, parv[1])) == NULL) return 0; uintmax_t ts = strtoumax(parv[2], NULL, 10); if (ts && (ts != target_p->tsinfo)) return 0; if (valid_hostname(parv[3]) == true) user_set_hostmask(target_p, parv[3]); sendto_server(source_p, 0, 0, ":%s SVSHOST %s %ju %s", source_p->id, target_p->id, target_p->tsinfo, parv[3]); return 0; }
static int apply_delta(int argc, const char **argv) { struct line_buffer preimage = LINE_BUFFER_INIT; struct line_buffer delta = LINE_BUFFER_INIT; struct sliding_view preimage_view = SLIDING_VIEW_INIT(&preimage, -1); if (argc != 5) usage(test_svnfe_usage); if (buffer_init(&preimage, argv[2])) die_errno("cannot open preimage"); if (buffer_init(&delta, argv[3])) die_errno("cannot open delta"); if (svndiff0_apply(&delta, (off_t) strtoumax(argv[4], NULL, 0), &preimage_view, stdout)) return 1; if (buffer_deinit(&preimage)) die_errno("cannot close preimage"); if (buffer_deinit(&delta)) die_errno("cannot close delta"); strbuf_release(&preimage_view.buf); return 0; }
static int l_filter_reject(lua_State *L) { uint64_t id; const char *s_id; uint32_t action; if (lua_gettop(L) != 2) return (0); s_id = luaL_checklstring(L, 1, NULL); id = strtoumax(s_id, (char **)NULL, 10); action = luaL_checkinteger(L, 2); switch (action) { case FILTER_FAIL: case FILTER_CLOSE: filter_api_reject(id, action); break; } return (0); }
static int parse_cat_response_line(const char *header, off_t *len) { uintmax_t n; const char *type; const char *end; if (ends_with(header, " missing")) return error("cat-blob reports missing blob: %s", header); type = strstr(header, " blob "); if (!type) return error("cat-blob header has wrong object type: %s", header); n = strtoumax(type + strlen(" blob "), (char **) &end, 10); if (end == type + strlen(" blob ")) return error("cat-blob header does not contain length: %s", header); if (memchr(type + strlen(" blob "), '-', end - type - strlen(" blob "))) return error("cat-blob header contains negative length: %s", header); if (n == UINTMAX_MAX || n > maximum_signed_value_of_type(off_t)) return error("blob too large for current definition of off_t"); *len = n; if (*end) return error("cat-blob header contains garbage after length: %s", header); return 0; }