3 typedef struct _Buffer
{
8 #define INIT_BUFFER_SIZE 10000
13 b
->room
= INIT_BUFFER_SIZE
;
15 b
->buff
= (char *)malloc(INIT_BUFFER_SIZE
*sizeof(char));
18 void AppendToBuffer(b
, str
, len
)
23 while (b
->used
+ len
> b
->room
) {
24 b
->buff
= (char *)realloc(b
->buff
, 2*b
->room
*(sizeof(char)));
27 strncpy(b
->buff
+ b
->used
, str
, len
);
31 void ReadFile(buffer
, input
)
32 register Buffer
*buffer
;
39 while (!feof(input
) && (bytes
= fread(buf
, 1, BUFSIZ
, input
)) > 0) {
40 AppendToBuffer(buffer
, buf
, bytes
);
42 AppendToBuffer(buffer
, "", 1);
47 char * filename
= "xbug.c";
53 if (!freopen (filename
, "r", stdin
))
54 fprintf(stderr
, "cannot open file\n");
56 if (!(input
= popen("/bin/cat", "r")))
57 fprintf(stderr
, "cannot run \n");
59 ReadFile(&buffer
, input
);