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