Back to index

php5  5.3.10
Functions
mbfl_memory_device.c File Reference
#include "mbfl_allocators.h"
#include "mbfl_string.h"
#include "mbfl_memory_device.h"

Go to the source code of this file.

Functions

void mbfl_memory_device_init (mbfl_memory_device *device, int initsz, int allocsz)
void mbfl_memory_device_realloc (mbfl_memory_device *device, int initsz, int allocsz)
void mbfl_memory_device_clear (mbfl_memory_device *device)
void mbfl_memory_device_reset (mbfl_memory_device *device)
void mbfl_memory_device_unput (mbfl_memory_device *device)
mbfl_stringmbfl_memory_device_result (mbfl_memory_device *device, mbfl_string *result)
int mbfl_memory_device_output (int c, void *data)
int mbfl_memory_device_output2 (int c, void *data)
int mbfl_memory_device_output4 (int c, void *data)
int mbfl_memory_device_strcat (mbfl_memory_device *device, const char *psrc)
int mbfl_memory_device_strncat (mbfl_memory_device *device, const char *psrc, int len)
int mbfl_memory_device_devcat (mbfl_memory_device *dest, mbfl_memory_device *src)
void mbfl_wchar_device_init (mbfl_wchar_device *device)
void mbfl_wchar_device_clear (mbfl_wchar_device *device)
int mbfl_wchar_device_output (int c, void *data)

Function Documentation

Definition at line 89 of file mbfl_memory_device.c.

{
       if (device) {
              if (device->buffer) {
                     mbfl_free(device->buffer);
              }
              device->buffer = (unsigned char *)0;
              device->length = 0;
              device->pos = 0;
       }
}

Here is the caller graph for this function:

Definition at line 276 of file mbfl_memory_device.c.

{
       int n;
       unsigned char *p, *w;

       if ((dest->pos + src->pos) >= dest->length) {
              /* reallocate buffer */
              int newlen = dest->length + src->pos + MBFL_MEMORY_DEVICE_ALLOC_SIZE;
              unsigned char *tmp = (unsigned char *)mbfl_realloc((void *)dest->buffer, newlen*sizeof(unsigned char));
              if (tmp == NULL) {
                     return -1;
              }
              dest->length = newlen;
              dest->buffer = tmp;
       }

       p = src->buffer;
       w = &dest->buffer[dest->pos];
       n = src->pos;
       dest->pos += n;
       while (n > 0) {
              *w++ = *p++;
              n--;
       }

       return n;
}

Here is the caller graph for this function:

void mbfl_memory_device_init ( mbfl_memory_device device,
int  initsz,
int  allocsz 
)

Definition at line 47 of file mbfl_memory_device.c.

{
       if (device) {
              device->length = 0;
              device->buffer = (unsigned char *)0;
              if (initsz > 0) {
                     device->buffer = (unsigned char *)mbfl_malloc(initsz*sizeof(unsigned char));
                     if (device->buffer != NULL) {
                            device->length = initsz;
                     }
              }
              device->pos= 0;
              if (allocsz > MBFL_MEMORY_DEVICE_ALLOC_SIZE) {
                     device->allocsz = allocsz;
              } else {
                     device->allocsz = MBFL_MEMORY_DEVICE_ALLOC_SIZE;
              }
       }
}

Here is the caller graph for this function:

int mbfl_memory_device_output ( int  c,
void *  data 
)

Definition at line 139 of file mbfl_memory_device.c.

{
       mbfl_memory_device *device = (mbfl_memory_device *)data;

       if (device->pos >= device->length) {
              /* reallocate buffer */
              int newlen;
              unsigned char *tmp;

              newlen = device->length + device->allocsz;
              tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen*sizeof(unsigned char));
              if (tmp == NULL) {
                     return -1;
              }
              device->length = newlen;
              device->buffer = tmp;
       }

       device->buffer[device->pos++] = (unsigned char)c;
       return c;
}

Here is the caller graph for this function:

int mbfl_memory_device_output2 ( int  c,
void *  data 
)

Definition at line 162 of file mbfl_memory_device.c.

{
       mbfl_memory_device *device = (mbfl_memory_device *)data;

       if ((device->pos + 2) >= device->length) {
              /* reallocate buffer */
              int newlen;
              unsigned char *tmp;

              newlen = device->length + device->allocsz;
              tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen*sizeof(unsigned char));
              if (tmp == NULL) {
                     return -1;
              }
              device->length = newlen;
              device->buffer = tmp;
       }

       device->buffer[device->pos++] = (unsigned char)((c >> 8) & 0xff);
       device->buffer[device->pos++] = (unsigned char)(c & 0xff);

       return c;
}
int mbfl_memory_device_output4 ( int  c,
void *  data 
)

Definition at line 187 of file mbfl_memory_device.c.

{
       mbfl_memory_device *device = (mbfl_memory_device *)data;

       if ((device->pos + 4) >= device->length) {
              /* reallocate buffer */
              int newlen;
              unsigned char *tmp;

              newlen = device->length + device->allocsz;
              tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen*sizeof(unsigned char));
              if (tmp == NULL) {
                     return -1;
              }
              device->length = newlen;
              device->buffer = tmp;
       }

       device->buffer[device->pos++] = (unsigned char)((c >> 24) & 0xff);
       device->buffer[device->pos++] = (unsigned char)((c >> 16) & 0xff);
       device->buffer[device->pos++] = (unsigned char)((c >> 8) & 0xff);
       device->buffer[device->pos++] = (unsigned char)(c & 0xff);

       return c;
}

Here is the caller graph for this function:

void mbfl_memory_device_realloc ( mbfl_memory_device device,
int  initsz,
int  allocsz 
)

Definition at line 68 of file mbfl_memory_device.c.

{
       unsigned char *tmp;

       if (device) {
              if (initsz > device->length) {
                     tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, initsz*sizeof(unsigned char));
                     if (tmp != NULL) {
                            device->buffer = tmp;
                            device->length = initsz;
                     }
              }
              if (allocsz > MBFL_MEMORY_DEVICE_ALLOC_SIZE) {
                     device->allocsz = allocsz;
              } else {
                     device->allocsz = MBFL_MEMORY_DEVICE_ALLOC_SIZE;
              }
       }
}

Here is the caller graph for this function:

Definition at line 102 of file mbfl_memory_device.c.

{
       if (device) {
              device->pos = 0;
       }
}

Here is the caller graph for this function:

Definition at line 118 of file mbfl_memory_device.c.

{
       if (device && result) {
              result->len = device->pos;
              mbfl_memory_device_output4('\0', device);
              result->val = device->buffer;
              device->buffer = (unsigned char *)0;
              device->length = 0;
              device->pos= 0;
              if (result->val == NULL) {
                     result->len = 0;
                     result = NULL;
              }
       } else {
              result = NULL;
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mbfl_memory_device_strcat ( mbfl_memory_device device,
const char *  psrc 
)

Definition at line 214 of file mbfl_memory_device.c.

{
       int len;
       unsigned char *w;
       const unsigned char *p;

       len = 0;
       p = psrc;
       while (*p) {
              p++;
              len++;
       }

       if ((device->pos + len) >= device->length) {
              /* reallocate buffer */
              int newlen = device->length + (len + MBFL_MEMORY_DEVICE_ALLOC_SIZE)*sizeof(unsigned char);
              unsigned char *tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen*sizeof(unsigned char));
              if (tmp == NULL) {
                     return -1;
              }
              device->length = newlen;
              device->buffer = tmp;
       }

       p = psrc;
       w = &device->buffer[device->pos];
       device->pos += len;
       while (len > 0) {
              *w++ = *p++;
              len--;
       }

       return len;
}
int mbfl_memory_device_strncat ( mbfl_memory_device device,
const char *  psrc,
int  len 
)

Definition at line 250 of file mbfl_memory_device.c.

{
       unsigned char *w;

       if ((device->pos + len) >= device->length) {
              /* reallocate buffer */
              int newlen = device->length + len + MBFL_MEMORY_DEVICE_ALLOC_SIZE;
              unsigned char *tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen*sizeof(unsigned char));
              if (tmp == NULL) {
                     return -1;
              }
              device->length = newlen;
              device->buffer = tmp;
       }

       w = &device->buffer[device->pos];
       device->pos += len;
       while (len > 0) {
              *w++ = *psrc++;
              len--;
       }

       return len;
}

Here is the caller graph for this function:

Definition at line 110 of file mbfl_memory_device.c.

{
       if (device->pos > 0) {
              device->pos--;
       }
}

Here is the caller graph for this function:

Definition at line 316 of file mbfl_memory_device.c.

{
       if (device) {
              if (device->buffer) {
                     mbfl_free(device->buffer);
              }
              device->buffer = (unsigned int*)0;
              device->length = 0;
              device->pos = 0;
       }
}

Here is the caller graph for this function:

Definition at line 305 of file mbfl_memory_device.c.

{
       if (device) {
              device->buffer = (unsigned int *)0;
              device->length = 0;
              device->pos= 0;
              device->allocsz = MBFL_MEMORY_DEVICE_ALLOC_SIZE;
       }
}

Here is the caller graph for this function:

int mbfl_wchar_device_output ( int  c,
void *  data 
)

Definition at line 329 of file mbfl_memory_device.c.

{
       mbfl_wchar_device *device = (mbfl_wchar_device *)data;

       if (device->pos >= device->length) {
              /* reallocate buffer */
              int newlen;
              unsigned int *tmp;

              newlen = device->length + device->allocsz;
              tmp = (unsigned int *)mbfl_realloc((void *)device->buffer, newlen*sizeof(int));
              if (tmp == NULL) {
                     return -1;
              }
              device->length = newlen;
              device->buffer = tmp;
       }

       device->buffer[device->pos++] = c;

       return c;
}

Here is the caller graph for this function: