[Spice-devel] [PATCH v3 26/51] test: Add code to read input from a file (or stdin)

Christophe Fergeau cfergeau at redhat.com
Thu Jul 23 06:15:19 PDT 2015


On Tue, Jul 21, 2015 at 05:45:56PM +0100, Frediano Ziglio wrote:
> This allow to emulate reading from network

'allows'

> @@ -540,10 +551,25 @@ int main(int argc, char **argv)
>  	hfs = g_ptr_array_new_with_free_func(free);
>  	spice_register_fields(1, NULL);
>  
> +	/* read message from standard input */
> +	buf = malloc(max_message_size);
> +	assert(buf);
> +	p = buf;
> +	pend = buf + max_message_size;
> +	while (p < pend && (size = fread(p, 1, pend - p, f)) > 0)
> +		p += size;
> +	assert(p < pend);
> +	assert(!ferror(f));
> +	size = p - buf;

This could probably use glib stream functions as well, which might make
the code a bit simpler (or more complicated given that this is very
short ;) I'd tend to move this bit to a small separate helper though for
readability.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20150723/dbedf8ba/attachment.sig>


More information about the Spice-devel mailing list