Back to index

glibc  2.9
Classes | Defines | Typedefs | Functions
xbug.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  _Buffer

Defines

#define INIT_BUFFER_SIZE   10000

Typedefs

typedef struct _Buffer Buffer

Functions

void InitBuffer (Buffer *b)
void AppendToBuffer (Buffer *b, const char *str, int len)
void ReadFile (Buffer *buffer, FILE *input)
int main (int argc, char *argv[])

Class Documentation

struct _Buffer

Definition at line 6 of file xbug.c.

Class Members
char * buff
int room
int used

Define Documentation

#define INIT_BUFFER_SIZE   10000

Definition at line 17 of file xbug.c.


Typedef Documentation

typedef struct _Buffer Buffer

Function Documentation

void AppendToBuffer ( Buffer b,
const char *  str,
int  len 
)

Definition at line 27 of file xbug.c.

{
  while (b->used + len > b->room) {
    b->buff = (char *)realloc(b->buff, 2*b->room*(sizeof(char)));
    b->room *= 2;
  }
  strncpy(b->buff + b->used, str, len);
  b->used += len;
}

Here is the caller graph for this function:

void InitBuffer ( Buffer b)

Definition at line 19 of file xbug.c.

{
  b->room = INIT_BUFFER_SIZE;
  b->used = 0;
  b->buff = (char *)malloc(INIT_BUFFER_SIZE*sizeof(char));
}

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 55 of file xbug.c.

{
  char filename[] = "xbug.c";
  FILE *input;
  Buffer buffer;

  InitBuffer(&buffer);

  if (!freopen (filename, "r", stdin))
    fprintf(stderr, "cannot open file\n");

  unsetenv ("LD_LIBRARY_PATH");

  if (!(input = popen("/bin/cat", "r")))
    fprintf(stderr, "cannot run \n");

  ReadFile(&buffer, input);
  pclose(input);

  return 0;
}

Here is the call graph for this function:

void ReadFile ( Buffer buffer,
FILE input 
)

Definition at line 40 of file xbug.c.

{
  char       buf[BUFSIZ + 1];
  register int        bytes;

  buffer->used = 0;
  while (!feof(input) && (bytes = fread(buf, 1, BUFSIZ, input)) > 0) {
    AppendToBuffer(buffer, buf, bytes);
  }
  AppendToBuffer(buffer, "", 1);
}

Here is the call graph for this function:

Here is the caller graph for this function: