00001
00002
00003
00004 #ifndef _WIN32
00005 #include "config.h"
00006 #else
00007 #include "winconfig.h"
00008 #endif
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include "include/dynstring.h"
00014 dynstring_t* dynstring_New(void)
00015 {
00016 dynstring_t* message;
00017 message = (dynstring_t*)malloc(sizeof(dynstring_t));
00018 message->len = 0;
00019 message->size = COMPOSE_BLOCKSIZE;
00020 message->message = (char*)malloc(sizeof(char) * message->size);
00021 if (message->message == NULL) {
00022 fprintf(stderr, "Memory error. %s:%d\n", __FILE__, __LINE__);
00023 exit(0);
00024 }
00025 memset(message->message, 0, message->size);
00026
00027 return message;
00028 }
00029
00030 int dynstring_Append(dynstring_t* msg, const char* str)
00031 {
00032 char* tmp;
00033
00034 while ( (strlen(str)+4) > (msg->size - msg->len) ) {
00035
00036 msg->size = msg->size + COMPOSE_BLOCKSIZE;
00037 }
00038 tmp = (char*)malloc( sizeof(char) * (msg->size));
00039 if (tmp == NULL) {
00040 fprintf(stderr, "Memory Error. %s:%d\n", __FILE__, __LINE__);
00041 exit(0);
00042 }
00043 memset(tmp, 0, msg->size);
00044 strcpy(tmp, msg->message);
00045 free(msg->message);
00046 msg->message = tmp;
00047 strcat(msg->message, str);
00048 msg->len += strlen(str);
00049
00050 return 0;
00051 }
00052
00053 int dynstring_Destroy(dynstring_t* dynstring)
00054 {
00055 free(dynstring->message);
00056 free(dynstring);
00057 return 0;
00058 }