rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char* buffer;
int size;
int end;
} bd_buffer;
typedef struct {
FILE * ini_fp;
char * ini_node_prev;
char * ini_node_curr;
char * ini_node_next;
bd_buffer ini_data;
} rf_ini;
int
buffer_init (bd_buffer *buff, int size) {
buff->buffer = malloc (size);
memset (buff->buffer, '\0', size);
buff->size = size;
buff->end = 0;
}
int
buffer_resize_append (bd_buffer * buff, char * string, int size)
{
char* temp;
size += buff->size;
temp = realloc (buff->buffer, size+1);
if (temp == NULL) {
free (temp);
return 1;
}
buff->buffer = temp;
buff->size += size;
char *ptr;
ptr = buff->buffer + buff->end;
if (buff->size < size) {
return 1;
}
else
memcpy (ptr, string, size);
buff->end += size;
return 0;
}
int
rf_ini_open (rf_ini * ini, char * path)
{
char temp_ptr[1024];
buffer_init (&ini->ini_data, 10);
ini->ini_fp = fopen (path, "r");
while (fgets (temp_ptr, 1024, ini->ini_fp) != NULL) {
printf ("\n\ndata so far: %s\n\n", temp_ptr);
buffer_resize_append (&ini->ini_data, temp_ptr, 1025);
}
printf ("\n\nexited loop\n\n");
fclose (ini->ini_fp);
free (temp_ptr);
}
int
main(int argc, char *argv[])
{
rf_ini my_ini_file;
rf_ini_open (&my_ini_file, "test.ini");
printf ("\n\ncontrol returned to main\n\n");
printf ("File data: %s", my_ini_file.ini_data.buffer);
system("PAUSE");
return 0;
}