Created
February 18, 2020 19:24
-
-
Save ZanderBrown/7e571dea1f71cf8b9941de536ee441b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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