// mallocset.c
// $Id: mallocset.c,v 1.2 2007/10/17 11:03:08 sendan Exp $
// masashi shimakura

#include<stdio.h>
#include<stdlib.h>

#include"file_comp.h"


int comp_private_malloc_set(private_data_comp *pd, int max_buff_len)
{
int count;

if((pd->val_data=(char**)malloc(sizeof(char*)*(max_buff_len + 10)))==NULL){exit(1);}
if((pd->val_attr=(unsigned char *)malloc(sizeof(unsigned char*)*(max_buff_len + 11)))==NULL){exit(1);}

// head_buff
if((pd->head_buff.comment=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}
if((pd->head_buff.command_path=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}
if((pd->head_buff.command_name=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}
if((pd->head_buff.user=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}
if((pd->head_buff.group=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}
if((pd->head_buff.permission=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}

for(count = 0; count < max_buff_len + 10; count++){
   if((pd->val_data[count]=(char*)calloc(2, sizeof(char)))==NULL){exit(1);}
   pd->val_attr[count] = 0;
   }

return 0;
}



int comp_private_malloc_free(private_data_comp *pd, int max_buff_len)
{
int count;

// head_buff
free(pd->head_buff.comment);
free(pd->head_buff.command_path);
free(pd->head_buff.command_name);
free(pd->head_buff.user);
free(pd->head_buff.group);
free(pd->head_buff.permission);

for(count = 0; count < max_buff_len + 10; count++){
   free(pd->val_data[count]);
   }

free(pd->val_data);
free(pd->val_attr);

return 0;
}



