mktime: check signed shifts on long_int and time_t, too
[glibc.git] / stdio-common / xbug.c
blob76a8c547268d4f260d6fa2130549f3de897c7c18
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
6 typedef struct _Buffer {
7 char *buff;
8 int room, used;
9 } Buffer;
11 void InitBuffer (Buffer *b);
12 void AppendToBuffer (register Buffer *b, const char *str, register int len);
13 void ReadFile (register Buffer *buffer, FILE *input);
15 #define INIT_BUFFER_SIZE 10000
17 void InitBuffer(b)
18 Buffer *b;
20 b->room = INIT_BUFFER_SIZE;
21 b->used = 0;
22 b->buff = (char *)malloc(INIT_BUFFER_SIZE*sizeof(char));
25 void AppendToBuffer(b, str, len)
26 register Buffer *b;
27 const char *str;
28 register int len;
30 while (b->used + len > b->room) {
31 b->buff = (char *)realloc(b->buff, 2*b->room*(sizeof(char)));
32 b->room *= 2;
34 strncpy(b->buff + b->used, str, len);
35 b->used += len;
38 void ReadFile(buffer, input)
39 register Buffer *buffer;
40 FILE *input;
42 char buf[BUFSIZ + 1];
43 register int bytes;
45 buffer->used = 0;
46 while (!feof(input) && (bytes = fread(buf, 1, BUFSIZ, input)) > 0) {
47 AppendToBuffer(buffer, buf, bytes);
49 AppendToBuffer(buffer, "", 1);
52 int
53 main(int argc, char *argv[])
55 char filename[] = "xbug.c";
56 FILE *input;
57 Buffer buffer;
59 InitBuffer(&buffer);
61 if (!freopen (filename, "r", stdin))
62 fprintf(stderr, "cannot open file\n");
64 unsetenv ("LD_LIBRARY_PATH");
66 if (!(input = popen("/bin/cat", "r")))
67 fprintf(stderr, "cannot run \n");
69 ReadFile(&buffer, input);
70 pclose(input);
72 return 0;