c_rle.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <openssl/objects.h>
  5. #include <openssl/comp.h>
  6. static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
  7. unsigned int olen, unsigned char *in, unsigned int ilen);
  8. static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
  9. unsigned int olen, unsigned char *in, unsigned int ilen);
  10. static COMP_METHOD rle_method={
  11. NID_rle_compression,
  12. LN_rle_compression,
  13. NULL,
  14. NULL,
  15. rle_compress_block,
  16. rle_expand_block,
  17. NULL,
  18. NULL,
  19. };
  20. COMP_METHOD *COMP_rle(void)
  21. {
  22. return(&rle_method);
  23. }
  24. static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
  25. unsigned int olen, unsigned char *in, unsigned int ilen)
  26. {
  27. /* int i; */
  28. if (olen < (ilen+1))
  29. {
  30. /* ZZZZZZZZZZZZZZZZZZZZZZ */
  31. return(-1);
  32. }
  33. *(out++)=0;
  34. memcpy(out,in,ilen);
  35. return(ilen+1);
  36. }
  37. static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
  38. unsigned int olen, unsigned char *in, unsigned int ilen)
  39. {
  40. int i;
  41. if (olen < (ilen-1))
  42. {
  43. /* ZZZZZZZZZZZZZZZZZZZZZZ */
  44. return(-1);
  45. }
  46. i= *(in++);
  47. if (i == 0)
  48. {
  49. memcpy(out,in,ilen-1);
  50. }
  51. return(ilen-1);
  52. }