Skip to content

Instantly share code, notes, and snippets.

@ZanderBrown
Created February 18, 2020 19:24
Show Gist options
  • Save ZanderBrown/7e571dea1f71cf8b9941de536ee441b6 to your computer and use it in GitHub Desktop.
Save ZanderBrown/7e571dea1f71cf8b9941de536ee441b6 to your computer and use it in GitHub Desktop.
// The number needs to be parsed from a string
static int
read_int (GDataInputStream *stream)
{
g_autoptr (GError) error = NULL;
g_autofree char *string = NULL;
gint64 num = -1;
string = g_data_input_stream_read_upto (stream, " \n", 2, NULL, NULL, &error);
if (error) {
g_error ("Can't read input: %s", error->message);
}
// Skip the space
g_data_input_stream_read_byte (stream, NULL, &error);
if (error) {
g_error ("Can't read input: %s", error->message);
}
g_ascii_string_to_signed (string, 10, 0, G_MAXINT, &num, &error);
if (error) {
g_error ("Can't read input: %s", error->message);
}
return num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment