File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,34 @@ pk_strtouint (const gchar *text, guint *value)
264264 return TRUE;
265265}
266266
267+ /**
268+ * pk_strtoulong:
269+ * @text: The string to convert
270+ * @value: The numeric return value
271+ *
272+ * Converts a string into a unsigned long value in a safe way.
273+ *
274+ * Return value: %TRUE if the string was converted correctly
275+ **/
276+ gboolean
277+ pk_strtoulong (const gchar * text , gulong * value )
278+ {
279+ gboolean ret ;
280+ guint64 value_raw ;
281+
282+ ret = pk_strtouint64 (text , & value_raw );
283+ if (!ret )
284+ return FALSE;
285+
286+ /* out of range */
287+ if (value_raw > G_MAXULONG )
288+ return FALSE;
289+
290+ /* cast back down to value */
291+ * value = (gulong ) value_raw ;
292+ return TRUE;
293+ }
294+
267295/**
268296 * pk_strzero:
269297 * @text: The text to check
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ gboolean pk_strtoint (const gchar *text,
3939 gint * value );
4040gboolean pk_strtouint (const gchar * text ,
4141 guint * value );
42+ gboolean pk_strtoulong (const gchar * text ,
43+ gulong * value );
4244gboolean pk_strtouint64 (const gchar * text ,
4345 guint64 * value );
4446GDBusNodeInfo * pk_load_introspection (const gchar * filename ,
You can’t perform that action at this time.
0 commit comments