@@ -152,6 +152,46 @@ static gboolean get_key_int(GKeyFile *key_file, const gchar *group, const gchar
152152 return TRUE;
153153}
154154
155+ /**
156+ * @brief Get 64-bit integer value from key_file for key in group, default_value must be specified,
157+ * returned in case key not found in group.
158+ *
159+ * @param[in] key_file GKeyFile to look value up
160+ * @param[in] group A group name
161+ * @param[in] key A key
162+ * @param[out] value Output 64-bit integer value
163+ * @param[in] default_value Return this value in case no value found
164+ * @param[out] error Error
165+ * @return FALSE on error (error is set), TRUE otherwise. Note that TRUE is returned if key in
166+ * group is not found, value is set to default_value in this case.
167+ */
168+ static gboolean get_key_int64 (GKeyFile * key_file , const gchar * group , const gchar * key , gint64 * value ,
169+ const gint64 default_value , GError * * error )
170+ {
171+ GError * ierror = NULL ;
172+ gint64 val ;
173+
174+ g_return_val_if_fail (key_file , FALSE);
175+ g_return_val_if_fail (group , FALSE);
176+ g_return_val_if_fail (key , FALSE);
177+ g_return_val_if_fail (value , FALSE);
178+ g_return_val_if_fail (error == NULL || * error == NULL , FALSE);
179+
180+ val = g_key_file_get_int64 (key_file , group , key , & ierror );
181+
182+ if (g_error_matches (ierror , G_KEY_FILE_ERROR , G_KEY_FILE_ERROR_KEY_NOT_FOUND )) {
183+ g_clear_error (& ierror );
184+ * value = default_value ;
185+ return TRUE;
186+ } else if (ierror ) {
187+ g_propagate_error (error , ierror );
188+ return FALSE;
189+ }
190+
191+ * value = val ;
192+ return TRUE;
193+ }
194+
155195/**
156196 * @brief Get GHashTable containing keys/values from group in key_file.
157197 *
@@ -328,7 +368,7 @@ Config* load_config_file(const gchar *config_file, GError **error)
328368 return NULL ;
329369 if (!get_key_int (ini_file , "client" , "low_speed_time" , & config -> low_speed_time , 60 , error ))
330370 return NULL ;
331- if (!get_key_int (ini_file , "client" , "download_speed_limit" , & config -> download_speed_limit , 0 , error ))
371+ if (!get_key_int64 (ini_file , "client" , "download_speed_limit" , & config -> download_speed_limit , 0 , error ))
332372 return NULL ;
333373 if (!get_key_bool (ini_file , "client" , "resume_downloads" , & config -> resume_downloads , FALSE,
334374 error ))
0 commit comments