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, char* str)
00031 {
00032 char* tmp;
00033
00034 while ( (strlen(str)+4) > (msg->size - msg->len) ) {
00035
00036 tmp = (char*)malloc(
00037 sizeof(char) *
00038 (msg->size + COMPOSE_BLOCKSIZE)
00039 );
00040 if (tmp == NULL) {
00041 fprintf(stderr, "Memory Error. %s:%d\n", __FILE__, __LINE__);
00042 exit(0);
00043 }
00044 msg->size = msg->size + COMPOSE_BLOCKSIZE;
00045 memset(tmp, 0, msg->size);
00046 strcpy(tmp, msg->message);
00047 free(msg->message);
00048 msg->message = tmp;
00049 }
00050 strcat(msg->message, str);
00051 msg->len += strlen(str);
00052
00053 return 0;
00054 }
00055
00056 int dynstring_Destroy(dynstring_t* dynstring)
00057 {
00058 free(dynstring->message);
00059 free(dynstring);
00060 return 0;
00061 }