/** * filter_line_fsck: (skip) * Filter one line - decide what to do with it. * * Returns: Zero or positive number as a percentage, -1 if not a percentage, -2 on an error */ static gint8 filter_line_fsck (const gchar * line, guint8 total_stages, GError **error) { static GRegex *output_regex = NULL; GMatchInfo *match_info; gint8 perc = -1; if (output_regex == NULL) { /* Compile regular expression that matches to e2fsck progress output */ output_regex = g_regex_new ("^([0-9][0-9]*) ([0-9][0-9]*) ([0-9][0-9]*) (/.*)", 0, 0, error); if (output_regex == NULL) { return -2; } } /* Execute regular expression */ if (g_regex_match (output_regex, line, 0, &match_info)) { guint8 stage; gint64 val_cur; gint64 val_total; /* The output_regex ensures we have a number in these matches, so we can skip * tests for conversion errors. */ stage = (guint8) g_ascii_strtoull (g_match_info_fetch (match_info, 1), (char **)NULL, 10); val_cur = g_ascii_strtoll (g_match_info_fetch (match_info, 2), (char **)NULL, 10); val_total = g_ascii_strtoll (g_match_info_fetch (match_info, 3), (char **)NULL, 10); perc = compute_percents (stage, total_stages, val_cur, val_total); } else { g_match_info_free (match_info); return -1; } g_match_info_free (match_info); return perc; }
void scan_operators_cb(struct ofono_error *error, GList *operators, void *data) { struct cb_data *cbd = data; struct ofono_data *od = cbd->user; struct telephony_error terr; telephony_network_list_query_cb cb = cbd->cb; GList *networks = NULL; int n, mcc, mnc; if (error) { terr.code = TELEPHONY_ERROR_INTERNAL; cb(&terr, NULL, cbd->data); } else { for(n = 0; n < g_list_length(operators); n++) { struct ofono_network_operator *netop = g_list_nth_data(operators, n); struct telephony_network *network = g_new0(struct telephony_network, 1); mcc = g_ascii_strtoll(ofono_network_operator_get_mcc(netop), NULL, 0); mnc = g_ascii_strtoll(ofono_network_operator_get_mnc(netop), NULL, 0); network->id = (mcc * 100) + mnc; network->name = ofono_network_operator_get_name(netop); network->radio_access_mode = select_best_radio_access_mode(netop); networks = g_list_append(networks, network); } cb(NULL, networks, cbd->data); g_list_free_full(networks, g_free); } od->network_scan_cancellable = 0; }
void ofono_platform_query(struct telephony_service *service, telephony_platform_query_cb cb, void *data) { struct ofono_data *od = telephony_service_get_data(service); struct telephony_platform_info pinfo; const char *mnc = NULL; const char *mcc = NULL; struct telephony_error error; if (!od->modem) { error.code = TELEPHONY_ERROR_INTERNAL; cb(&error, NULL, data); return; } memset(&pinfo, 0, sizeof(struct telephony_platform_info)); pinfo.platform_type = TELEPHONY_PLATFORM_TYPE_GSM; pinfo.imei = ofono_modem_get_serial(od->modem); pinfo.version = ofono_modem_get_revision(od->modem); if (ofono_modem_is_interface_supported(od->modem, OFONO_MODEM_INTERFACE_SIM_MANAGER)) { mcc = ofono_sim_manager_get_mcc(od->sim); mnc = ofono_sim_manager_get_mnc(od->sim); if (mcc && mnc) { pinfo.mcc = g_ascii_strtoll(mcc, NULL, 0); pinfo.mnc = g_ascii_strtoll(mnc, NULL, 0); } } cb(NULL, &pinfo, data); }
static void update_from_key_value (void *vpeer, const char *key, const char *value) { CcnetPeer *peer = vpeer; if (strcmp(key, "timestamp") == 0) { gint64 timestamp = g_ascii_strtoll(value, NULL, 10); if (timestamp > peer->timestamp) get_peer_pubinfo (peer); CcnetUser *user = ccnet_peer_get_user(peer); if (!user || timestamp > user->timestamp) get_user_pubinfo (peer); } if (strcmp(key, "role-timestamp") == 0) { CcnetUser *user = ccnet_peer_get_user(peer); if (!user) return; gint64 timestamp = g_ascii_strtoll (value, NULL, 10); if (timestamp < user->role_timestamp) { ccnet_peer_manager_notify_peer_role (peer->manager, peer); } } }
static GParameter * extractable_get_parameters_from_id (const gchar * id, guint * n_params) { gchar **func_udata; GParameter *params = g_new0 (GParameter, 3); *n_params = 3; /* We already know that we have a valid ID here */ func_udata = g_strsplit (id, "!", -1); params[0].name = "fill-func"; g_value_init (¶ms[0].value, G_TYPE_POINTER); g_value_set_pointer (¶ms[0].value, GUINT_TO_POINTER (g_ascii_strtoll (func_udata[0], NULL, 10))); params[1].name = "user-data"; g_value_init (¶ms[1].value, G_TYPE_POINTER); g_value_set_pointer (¶ms[1].value, GUINT_TO_POINTER (g_ascii_strtoll (func_udata[1], NULL, 10))); params[2].name = "supported-formats"; g_value_init (¶ms[2].value, GES_TYPE_TRACK_TYPE); g_value_set_flags (¶ms[2].value, GES_TRACK_TYPE_CUSTOM); g_strfreev (func_udata); return params; }
gboolean _gum_duk_parse_int64 (duk_context * ctx, duk_idx_t index, GumDukCore * core, gint64 * i) { if (duk_is_string (ctx, index)) { const gchar * value_as_string, * end; gboolean valid; value_as_string = duk_require_string (ctx, index); if (g_str_has_prefix (value_as_string, "0x")) { *i = g_ascii_strtoll (value_as_string + 2, (gchar **) &end, 16); valid = end != value_as_string + 2; } else { *i = g_ascii_strtoll (value_as_string, (gchar **) &end, 10); valid = end != value_as_string; } return valid; } return _gum_duk_get_int64 (ctx, index, core, i); }
static void mixer_pad_added (KmsBaseHub * mixer, GstPad * pad, gpointer data) { if (gst_pad_get_direction (pad) != GST_PAD_SRC) { return; } KMS_BASE_HUB_LOCK (mixer); if (g_str_has_prefix (GST_OBJECT_NAME (pad), VIDEO_SRC_PAD_PREFIX)) { KmsBaseHubPortData *port; gint64 id; const gchar *pad_name; pad_name = GST_OBJECT_NAME (pad); id = g_ascii_strtoll (pad_name + LENGTH_VIDEO_SRC_PAD_PREFIX, NULL, 10); port = g_hash_table_lookup (mixer->priv->ports, &id); gst_element_link_pads (GST_ELEMENT (mixer), GST_OBJECT_NAME (pad), port->port, "mixer_video_sink"); } else if (g_str_has_prefix (GST_OBJECT_NAME (pad), AUDIO_SRC_PAD_PREFIX)) { KmsBaseHubPortData *port; gint64 id; const gchar *pad_name; pad_name = GST_OBJECT_NAME (pad); id = g_ascii_strtoll (pad_name + LENGTH_AUDIO_SRC_PAD_PREFIX, NULL, 10); port = g_hash_table_lookup (mixer->priv->ports, &id); gst_element_link_pads (GST_ELEMENT (mixer), GST_OBJECT_NAME (pad), port->port, "mixer_audio_sink"); } KMS_BASE_HUB_UNLOCK (mixer); }
bool synctex_parse_input(const char* synctex, char** input_file, int* line, int* column) { if (synctex == NULL || input_file == NULL || line == NULL || column == NULL) { return false; } char** split_fwd = g_strsplit(synctex, ":", 0); if (split_fwd == NULL || split_fwd[0] == NULL || split_fwd[1] == NULL || split_fwd[2] == NULL || split_fwd[3] != NULL) { g_strfreev(split_fwd); return false; } *line = MIN(INT_MAX, g_ascii_strtoll(split_fwd[0], NULL, 10)); *column = MIN(INT_MAX, g_ascii_strtoll(split_fwd[1], NULL, 10)); /* SyncTeX starts indexing at 1, but we use 0 */ if (*line > 0) { --*line; } if (*column > 0) { --*column; } *input_file = g_strdup(split_fwd[2]); g_strfreev(split_fwd); return true; }
static void parse_requires (ParserData *data, const gchar *element_name, const gchar **names, const gchar **values, GError **error) { RequiresInfo *req_info; const gchar *library = NULL; const gchar *version = NULL; gchar **split; gint i, version_major = 0, version_minor = 0; gint line_number, char_number; g_markup_parse_context_get_position (data->ctx, &line_number, &char_number); for (i = 0; names[i] != NULL; i++) { if (strcmp (names[i], "lib") == 0) library = values[i]; else if (strcmp (names[i], "version") == 0) version = values[i]; else error_invalid_attribute (data, element_name, names[i], error); } if (!library || !version) { error_missing_attribute (data, element_name, version ? "lib" : "version", error); return; } if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1]) { g_set_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_VALUE, "%s:%d:%d <%s> attribute has malformed value \"%s\"", data->filename, line_number, char_number, "version", version); return; } version_major = g_ascii_strtoll (split[0], NULL, 10); version_minor = g_ascii_strtoll (split[1], NULL, 10); g_strfreev (split); req_info = g_slice_new0 (RequiresInfo); req_info->library = g_strdup (library); req_info->major = version_major; req_info->minor = version_minor; state_push (data, req_info); req_info->tag.name = element_name; }
gboolean sqlx_name_extract (struct sqlx_name_s *n, struct oio_url_s *url, const char *srvtype, gint64 *pseq) { SQLXNAME_CHECK(n); EXTRA_ASSERT (url != NULL); EXTRA_ASSERT (srvtype != NULL); EXTRA_ASSERT (pseq != NULL); int rc = 0; gchar **tokens; if (NULL != (tokens = g_strsplit (n->type, ".", 2))) { if (tokens[0]) rc = !strcmp(tokens[0], srvtype); oio_url_set (url, OIOURL_TYPE, tokens[1] ? tokens[1] : OIOURL_DEFAULT_TYPE); g_strfreev (tokens); } if (NULL != (tokens = g_strsplit (n->base, ".", 2))) { if (tokens[0]) oio_url_set (url, OIOURL_HEXID, tokens[0]); *pseq = tokens[1] ? g_ascii_strtoll (tokens[1], NULL, 10) : 1; g_strfreev (tokens); } return BOOL(rc); }
/** * CacheUtilTimeSpanFromString: * @value: String containing a positive integer with an suffix, like "5d" for 5 * days or "1w" for one week. * @result: (out): Pointer to the resulting GTimeSpan. * * Valid suffixes are "w" (weeks), "d" (days), and "h" (hours). * * Returns: #TRUE if @value is valid and @result was updated. */ gboolean CacheUtilTimespanFromString(const gchar *value, GTimeSpan *result) { gchar *suffix = NULL; gint64 multiple = 0; gint64 number = g_ascii_strtoll(value, &suffix, 10); if (!suffix || strlen(suffix) != 1 || suffix == value) return FALSE; switch (suffix[0]) { case 'm': multiple = G_TIME_SPAN_MINUTE; break; case 'h': multiple = G_TIME_SPAN_HOUR; break; case 'd': multiple = G_TIME_SPAN_DAY; break; case 'w': multiple = G_TIME_SPAN_DAY * 7; break; default: return FALSE; } *result = number * multiple; return TRUE; }
static gboolean parse_geom_token(const gchar **iter, GValue *value) { gchar *end = NULL; gint64 token_value = g_ascii_strtoll(*iter, &end, 10); if(end) { if(*end == '%') { g_value_init(value, G_TYPE_DOUBLE); g_value_set_double(value, (gdouble)token_value/100.0); end++; } else { g_value_init(value, G_TYPE_INT64); g_value_set_int64(value, token_value); } *iter = end; } return !!end; }
static void parse_attachment_size(struct map_msg *msg, const char *value, DBusMessageIter *iter) { msg->attachment_size = g_ascii_strtoll(value, NULL, 10); obex_dbus_dict_append(iter, "AttachmentSize", DBUS_TYPE_UINT64, &msg->attachment_size); }
gboolean _ostree_sysroot_parse_deploy_path_name (const char *name, char **out_csum, int *out_serial, GError **error) { gboolean ret = FALSE; __attribute__((cleanup(match_info_cleanup))) GMatchInfo *match = NULL; g_autofree char *serial_str = NULL; static gsize regex_initialized; static GRegex *regex; if (g_once_init_enter (®ex_initialized)) { regex = g_regex_new ("^([0-9a-f]+)\\.([0-9]+)$", 0, 0, NULL); g_assert (regex); g_once_init_leave (®ex_initialized, 1); } if (!g_regex_match (regex, name, 0, &match)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid deploy name '%s', expected CHECKSUM.TREESERIAL", name); goto out; } *out_csum = g_match_info_fetch (match, 1); serial_str = g_match_info_fetch (match, 2); *out_serial = (int)g_ascii_strtoll (serial_str, NULL, 10); ret = TRUE; out: return ret; }
/** * egg_strtoint: * @text: The text the convert * @value: The return numeric return value * * Converts a string into a signed integer value in a safe way. * * Return value: %TRUE if the string was converted correctly **/ gboolean egg_strtoint (const gchar *text, gint *value) { gchar *endptr = NULL; gint64 value_raw; /* invalid */ if (text == NULL) return FALSE; /* parse */ value_raw = g_ascii_strtoll (text, &endptr, 10); /* parsing error */ if (endptr == text) return FALSE; /* out of range */ if (value_raw > G_MAXINT || value_raw < G_MININT) return FALSE; /* cast back down to value */ *value = (gint) value_raw; return TRUE; }
static void _filter_info_xml(gs_content_t *content, struct list_content_s *lc) { struct ls_utils_s *lu = NULL; lu = g_malloc0(sizeof(struct ls_utils_s)); GString *tmp = g_string_new(""); lu->path = g_strdup(content->info.path); lu->deleted = content->deleted; lu->version = g_ascii_strtoll(content->version, NULL, 10); // content->gba_sysmd->data doesn't end with '\0' gchar *sysmd = g_strndup((const gchar*)content->gba_sysmd->data, content->gba_sysmd->len); g_string_append_printf(tmp, " <Content>\n" " <Path>%s</Path>\n" " <Size>%"G_GINT64_FORMAT"</Size>\n" " <Version>%s</Version>\n" " <MdSys>%s</MdSys>\n" " <Deleted>%d</Deleted>\n" " </Content>\n", content->info.path, content->info.size, content->version, sysmd, content->deleted); g_free(sysmd); lu->str = g_string_free(tmp, FALSE); lc->listed = g_slist_prepend(lc->listed, lu); }
static gboolean get_evolution_pid (GFile *file) { gint64 v_int64; gchar *contents = NULL; gboolean success = FALSE; /* Try to read Evolution's PID from its .running file. */ if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, NULL)) goto exit; /* Try to extract an integer value from the string. */ v_int64 = g_ascii_strtoll (contents, NULL, 10); if (!(v_int64 > 0 && v_int64 < G_MAXINT64)) goto exit; /* XXX Probably not portable. */ evolution_pid = (GPid) v_int64; success = TRUE; exit: g_free (contents); return success; }
gboolean _gtk_css_parser_try_int (GtkCssParser *parser, int *value) { gint64 result; char *end; g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE); g_return_val_if_fail (value != NULL, FALSE); /* strtoll parses a plus, but we are not allowed to */ if (*parser->data == '+') return FALSE; errno = 0; result = g_ascii_strtoll (parser->data, &end, 10); if (errno) return FALSE; if (result > G_MAXINT || result < G_MININT) return FALSE; if (parser->data == end) return FALSE; parser->data = end; *value = result; _gtk_css_parser_skip_whitespace (parser); return TRUE; }
gboolean stg_pol_rainx_get_param(namespace_info_t *ni, const gchar *stgpol, const gchar *param, gint64 *p_val) { const char *val_str = NULL; struct storage_policy_s *sp = storage_policy_init(ni, stgpol); const struct data_security_s *datasec = storage_policy_get_data_security(sp); gboolean ret; if (!datasec) { GRID_INFO("Cannot find datasecurity values for policy [%s]", stgpol); ret = FALSE; } else { if (NULL == (val_str = data_security_get_param(datasec, param))) { GRID_INFO("Cannot get parameter '%s' from data security [%s]", param, data_security_get_name(datasec)); ret = FALSE; } else { *p_val = g_ascii_strtoll(val_str, NULL, 10); ret = TRUE; } } storage_policy_clean(sp); return ret; }
gint64 lr_xml_parser_strtoll(LrParserData *pd, const char *nptr, unsigned int base) { gint64 val; char *endptr = NULL; assert(pd); assert(base <= 36 && base != 1); if (!nptr) return 0; val = g_ascii_strtoll(nptr, &endptr, base); if ((val == G_MAXINT64 || val == G_MININT64) && errno == ERANGE) lr_xml_parser_warning(pd, LR_XML_WARNING_BADATTRVAL, "Correct integer value \"%s\" caused overflow", nptr); else if (val == 0 && *endptr != '\0') lr_xml_parser_warning(pd, LR_XML_WARNING_BADATTRVAL, "Conversion of \"%s\" to integer failed", nptr); return val; }
gint64 arv_gc_property_node_get_int64 (ArvGcPropertyNode *node, GError **error) { ArvDomNode *pvalue_node; g_return_val_if_fail (ARV_IS_GC_PROPERTY_NODE (node), 0); g_return_val_if_fail (error == NULL || *error == NULL, 0); pvalue_node = _get_pvalue_node (node); if (pvalue_node == NULL) return g_ascii_strtoll (_get_value_data (node), NULL, 0); if (ARV_IS_GC_INTEGER (pvalue_node)) { GError *local_error = NULL; gint64 value; value = arv_gc_integer_get_value (ARV_GC_INTEGER (pvalue_node), &local_error); if (local_error != NULL) g_propagate_error (error, local_error); return value; } arv_warning_genicam ("[GcPropertyNode::get_int64] Invalid node '%s'", arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (pvalue_node))); return 0; }
struct meta1_service_url_s* meta1_unpack_url(const gchar *url) { gchar *type = NULL, *host = NULL, *args = NULL; EXTRA_ASSERT(url != NULL); int len = strlen(url); gchar *tmp = g_alloca(len+1); g_strlcpy(tmp, url, len+1); if (!(type = strchr(tmp, '|'))) return NULL; *(type++) = '\0'; if (!(host = strchr(type, '|'))) return NULL; *(host++) = '\0'; if (!(args = strchr(host, '|'))) return NULL; *(args++) = '\0'; if (strlen(args) >= LIMIT_LENGTH_SRVARGS) return NULL; struct meta1_service_url_s *result; result = g_malloc0(sizeof(*result) + strlen(args) + 1); result->seq = g_ascii_strtoll(url, NULL, 10); g_strlcpy(result->srvtype, type, sizeof(result->srvtype)); g_strlcpy(result->host, host, sizeof(result->host)); strcpy(result->args, args); return result; }
/** * cd_parse_beagle_process_entry_huey: **/ static void cd_parse_beagle_process_entry_huey (CdParseEntry *entry) { gchar **tok; guint j; guint8 cmd; guint8 instruction = 0; const gchar *command_as_text; GString *output = NULL; entry->ep_description = "default"; /* only know how to parse 8 bytes */ tok = g_strsplit (entry->summary, " ", -1); if (g_strv_length (tok) != 8) { g_print ("not 8 tokens: %s\n", entry->summary); goto out; } output = g_string_new (""); for (j = 0; j < 8; j++) { command_as_text = NULL; cmd = g_ascii_strtoll (tok[j], NULL, 16); if (j == 0 && entry->direction == CD_PARSE_ENTRY_DIRECTION_REPLY) { command_as_text = huey_rc_to_string (cmd); if (command_as_text == NULL) g_warning ("return code 0x%02x not known in %s", cmd, entry->summary); } if ((j == 0 && entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST) || (j == 1 && entry->direction == CD_PARSE_ENTRY_DIRECTION_REPLY)) { instruction = cmd; command_as_text = huey_cmd_code_to_string (instruction); if (command_as_text == NULL) g_warning ("command code 0x%02x not known", cmd); } /* some requests are filled with junk data */ if (entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST && instruction == HUEY_CMD_REGISTER_READ && j > 1) g_string_append_printf (output, "xx "); else if (entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST && instruction == HUEY_CMD_SET_LEDS && j > 4) g_string_append_printf (output, "xx "); else if (entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST && instruction == HUEY_CMD_GET_AMBIENT && j > 3) g_string_append_printf (output, "xx "); else if (command_as_text != NULL) g_string_append_printf (output, "%02x(%s) ", cmd, command_as_text); else g_string_append_printf (output, "%02x ", cmd); } /* remove trailing space */ if (output->len > 1) g_string_set_size (output, output->len - 1); out: if (output != NULL) entry->summary_pretty = g_string_free (output, FALSE); g_strfreev (tok); }
static gboolean _manage_and_renew_header(struct http_parser_s *parser, GString *buf) { if (!buf->len) return TRUE; gstr_chomp(buf); gchar *header = buf->str; gchar *sep = strchr(header, ':'); if (!sep) return FALSE; *(sep++) = '\0'; if (*(sep++) != ' ') return FALSE; oio_str_lower (header); if (*header == 'c' && !strcmp(header, "content-length")) parser->content_length = g_ascii_strtoll(sep, NULL, 10); if (parser->header_provider) parser->header_provider(header, sep); g_string_set_size(buf, 0); return TRUE; }
bool WebKitTestBus::run() { // FIXME: Use GTestDBus when we bump glib to 2.34. GUniquePtr<char> dbusLaunch(g_find_program_in_path("dbus-launch")); if (!dbusLaunch) { g_warning("Error starting DBUS daemon: dbus-launch not found in path"); return false; } GUniqueOutPtr<char> output; GUniqueOutPtr<GError> error; if (!g_spawn_command_line_sync(dbusLaunch.get(), &output.outPtr(), 0, 0, &error.outPtr())) { g_warning("Error starting DBUS daemon: %s", error->message); return false; } String outputString = String::fromUTF8(output.get()); Vector<String> lines; outputString.split(UChar('\n'), /* allowEmptyEntries */ false, lines); for (size_t i = 0; i < lines.size(); ++i) { char** keyValue = g_strsplit(lines[i].utf8().data(), "=", 2); g_assert_cmpuint(g_strv_length(keyValue), ==, 2); if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_ADDRESS")) { m_address = keyValue[1]; g_setenv("DBUS_SESSION_BUS_ADDRESS", keyValue[1], TRUE); } else if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_PID")) m_pid = g_ascii_strtoll(keyValue[1], 0, 10); g_strfreev(keyValue); } return m_pid > 0; }
static void ide_editor_view_goto_line_activate (IdeEditorView *self, const gchar *text, EggSimplePopover *popover) { gint64 value; g_assert (IDE_IS_EDITOR_VIEW (self)); g_assert (EGG_IS_SIMPLE_POPOVER (popover)); if (!ide_str_empty0 (text)) { value = g_ascii_strtoll (text, NULL, 10); if ((value > 0) && (value < G_MAXINT)) { GtkTextIter iter; GtkTextBuffer *buffer = GTK_TEXT_BUFFER (self->document); gtk_widget_grab_focus (GTK_WIDGET (self->frame1->source_view)); gtk_text_buffer_get_iter_at_line (buffer, &iter, value - 1); gtk_text_buffer_select_range (buffer, &iter, &iter); ide_source_view_scroll_to_iter (self->frame1->source_view, &iter, 0.25, TRUE, 1.0, 0.5, TRUE); } } }
GError * metautils_message_extract_strint64(MESSAGE msg, const gchar *n, gint64 *i64) { gchar *end, dst[24]; EXTRA_ASSERT (i64 != NULL); *i64 = 0; memset(dst, 0, sizeof(dst)); GError *err = metautils_message_extract_string(msg, n, dst, sizeof(dst)); if (err != NULL) { g_prefix_error(&err, "field: "); return err; } end = NULL; *i64 = g_ascii_strtoll(dst, &end, 10); switch (*i64) { case G_MININT64: case G_MAXINT64: return (errno == ERANGE) ? NEWERROR(CODE_BAD_REQUEST, "Invalid number") : NULL; case 0: return (end == dst) ? NEWERROR(CODE_BAD_REQUEST, "Invalid number") : NULL; default: return NULL; } }
/** * tp_g_key_file_get_int64: * @key_file: a non-%NULL #GKeyFile * @group_name: a non-%NULL group name * @key: a non-%NULL key * @error: return location for a #GError * * Returns the value associated with @key under @group_name as a signed * 64-bit integer. This is similar to g_key_file_get_integer() but can return * 64-bit results without truncation. * * Returns: the value associated with the key as a signed 64-bit integer, or * 0 if the key was not found or could not be parsed. * * Since: 0.7.31 */ gint64 tp_g_key_file_get_int64 (GKeyFile *key_file, const gchar *group_name, const gchar *key, GError **error) { gchar *s, *end; gint64 v; g_return_val_if_fail (key_file != NULL, -1); g_return_val_if_fail (group_name != NULL, -1); g_return_val_if_fail (key != NULL, -1); s = g_key_file_get_value (key_file, group_name, key, error); if (s == NULL) return 0; v = g_ascii_strtoll (s, &end, 10); if (*s == '\0' || *end != '\0') { g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE, "Key '%s' in group '%s' has value '%s' where int64 was expected", key, group_name, s); return 0; } g_free (s); return v; }
/* _nm_utils_ascii_str_to_int64: * * A wrapper for g_ascii_strtoll, that checks whether the whole string * can be successfully converted to a number and is within a given * range. On any error, @fallback will be returned and %errno will be set * to a non-zero value. On success, %errno will be set to zero, check %errno * for errors. Any trailing or leading (ascii) white space is ignored and the * functions is locale independent. * * The function is guaranteed to return a value between @min and @max * (inclusive) or @fallback. Also, the parsing is rather strict, it does * not allow for any unrecognized characters, except leading and trailing * white space. **/ gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback) { gint64 v; const char *s = NULL; if (str) { while (g_ascii_isspace (str[0])) str++; } if (!str || !str[0]) { errno = EINVAL; return fallback; } errno = 0; v = g_ascii_strtoll (str, (char **) &s, base); if (errno != 0) return fallback; if (s[0] != '\0') { while (g_ascii_isspace (s[0])) s++; if (s[0] != '\0') { errno = EINVAL; return fallback; } } if (v > max || v < min) { errno = ERANGE; return fallback; } return v; }
static void gst_multiudpsink_set_clients_string (GstMultiUDPSink * sink, const gchar * string) { gchar **clients; gint i; clients = g_strsplit (string, ",", 0); g_mutex_lock (&sink->client_lock); /* clear all existing clients */ gst_multiudpsink_clear_internal (sink, FALSE); for (i = 0; clients[i]; i++) { gchar *host, *p; gint64 port = 0; host = clients[i]; p = strstr (clients[i], ":"); if (p != NULL) { *p = '\0'; port = g_ascii_strtoll (p + 1, NULL, 10); } if (port != 0) gst_multiudpsink_add_internal (sink, host, port, FALSE); } g_mutex_unlock (&sink->client_lock); g_strfreev (clients); }