Subversion Repositories Games.Chess Giants

Rev

Rev 116 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 116 Rev 154
Line 80... Line 80...
80
{
80
{
81
   // this function writes the content of data to a buffer's data at position write_index.
81
   // this function writes the content of data to a buffer's data at position write_index.
82
   // Returns 1 on success, 0 on error.
82
   // Returns 1 on success, 0 on error.
83
 
83
 
84
   char *new_data;
84
   char *new_data;
-
 
85
   char *dest;
85
 
86
 
86
   // see if we need to grow the data
87
   // see if we need to grow the data
87
   if (write_index + data_size > buffer->size)
88
   if (write_index + data_size > buffer->size)
88
   {
89
   {
89
      // if so, reallocate data buffer at the right size
90
      // if so, reallocate data buffer at the right size
Line 92... Line 93...
92
         return (0); // on failure, return an error value
93
         return (0); // on failure, return an error value
93
 
94
 
94
      buffer->data = new_data; // save pointer to reallocated data
95
      buffer->data = new_data; // save pointer to reallocated data
95
   }
96
   }
96
 
97
 
-
 
98
   // do dest and source overlap ?
-
 
99
   dest = &buffer->data[write_index];
-
 
100
   if (((data <= dest) && (data + data_size > dest)) || ((dest <= data) && (dest + data_size > data)))
-
 
101
      memmove (&buffer->data[write_index], data, data_size); // if so, move data in place
-
 
102
   else
97
   memcpy (&buffer->data[write_index], data, data_size); // write data in place
103
      memcpy (&buffer->data[write_index], data, data_size); // else write data in place (faster)
98
   if (write_index + data_size > buffer->size)
104
   if (write_index + data_size > buffer->size)
99
      buffer->size = write_index + data_size; // update data size only if it growed
105
      buffer->size = write_index + data_size; // update data size only if it growed
100
 
106
 
101
   return (1); // buffer written successfully, return SUCCESS
107
   return (1); // buffer written successfully, return SUCCESS
102
}
108
}