/home/dko/projects/mobilec/trunk/src/dynstring.c

Go to the documentation of this file.
00001 /* SVN FILE INFO
00002  * $Revision: 174 $ : Last Committed Revision
00003  * $Date: 2008年06月24日 10:50:29 -0700 (2008年6月24日) $ : Last Committed Date */
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include "include/dynstring.h"
00008 dynstring_t* dynstring_New(void)
00009 {
00010 dynstring_t* message;
00011 message = (dynstring_t*)malloc(sizeof(dynstring_t));
00012 message->len = 0;
00013 message->size = COMPOSE_BLOCKSIZE;
00014 message->message = (char*)malloc(sizeof(char) * message->size);
00015 if (message->message == NULL) {
00016 fprintf(stderr, "Memory error. %s:%d\n", __FILE__, __LINE__);
00017 exit(0);
00018 }
00019 memset(message->message, 0, message->size);
00020 
00021 return message;
00022 }
00023 
00024 int dynstring_Append(dynstring_t* msg, char* str)
00025 {
00026 char* tmp;
00027 /* Check to see if we need to reallocate the message buffer */
00028 while ( (strlen(str)+4) > (msg->size - msg->len) ) {
00029 /* Increase the size of the buffer by COMPOSE_BLOCKSIZE */
00030 tmp = (char*)malloc(
00031 sizeof(char) * 
00032 (msg->size + COMPOSE_BLOCKSIZE)
00033 );
00034 if (tmp == NULL) {
00035 fprintf(stderr, "Memory Error. %s:%d\n", __FILE__, __LINE__);
00036 exit(0);
00037 }
00038 msg->size = msg->size + COMPOSE_BLOCKSIZE;
00039 strcpy(tmp, msg->message);
00040 free(msg->message);
00041 msg->message = tmp;
00042 }
00043 strcat(msg->message, str);
00044 msg->len += strlen(str);
00045 
00046 return 0;
00047 }
00048 
00049 int dynstring_Destroy(dynstring_t* dynstring)
00050 {
00051 free(dynstring->message);
00052 free(dynstring);
00053 return 0;
00054 }

Generated on Tue Oct 28 17:03:22 2008 for Mobile-C by doxygen 1.5.5

AltStyle によって変換されたページ (->オリジナル) /