tool to upload data to a SuperCharger cartridge
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
638B

  1. #include "streambuffer.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define CHUNKSIZE (1024*256)
  5. void streaminit( streambuffer_t *buffer )
  6. {
  7. memset( buffer, 0, sizeof( streambuffer_t ) );
  8. }
  9. void streamadd( streambuffer_t *buffer, const unsigned char *data, int size )
  10. {
  11. if( buffer->used + size > buffer->malloced )
  12. {
  13. buffer->malloced += CHUNKSIZE;
  14. buffer->start = (unsigned char*)realloc( buffer->start, buffer->malloced );
  15. }
  16. memcpy( buffer->start + buffer->used, data, size );
  17. buffer->used += size;
  18. }
  19. void streamclean( streambuffer_t *buffer )
  20. {
  21. free( buffer->start );
  22. streaminit( buffer );
  23. }