Re: libgnomeui-2.0 vs pipes



Dixit Pierre Sarrazin <sarrazip sympatico ca> (2002-11-26 10:19):
	[...]
> I have attached two .c files that illustrate the output given above

OK, now I've attached the two files...

-- 
Pierre Sarrazin <sarrazip @ sympatico . ca>
/*
    libgnomeui-2.0 vs pipes -- 2002-11-26 -- http://sarrazip.com/en/

    To compile, put this file and test_pipe.c in the same dir and then:
    gcc -g -Wall gnome-and-pipe.c -o gnome-and-pipe `pkg-config --cflags --libs libgnomeui-2.0`
*/

#include <gnome.h>
#include "test_pipe.c"

int main(int argc, char *argv[])
{
    test_pipe();
    gnome_program_init("x", "0.0", LIBGNOMEUI_MODULE, argc, argv, NULL);
    test_pipe();
    return 0;
}
#include <stdio.h>
#include <string.h>
#include <errno.h>

void test_pipe()
{
    FILE *pipe;
    char buffer[1024];
    size_t n;
    int i;

    fprintf(stderr, "Testing pipe\n");
    pipe = popen("echo foo", "r");
    if (pipe == NULL)
    {
	fprintf(stderr, "popen failed: %s\n", strerror(errno));
	return;
    }

    for (i = 1; i <= 10; i++)
    {
	fprintf(stderr, "Attempt # %d\n", i);
	n = fread(buffer, 1, sizeof(buffer), pipe);
	if (n == 0)
	{
	    int e = errno;
	    fprintf(stderr, "errno: %s\n", strerror(e));
	    if (e == EINTR)
		continue;
	    break;
	}

	fprintf(stderr, "buffer=[");
	fwrite(buffer, 1, n, stderr);
	fprintf(stderr, "]\n");
	break;
    }

    fprintf(stderr, "End of test\n\n");
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]