fix types
[compress.git] / code.c
1 #include <stddef.h>
2 #include <stdio.h>
3 #include "debug.h"
4
5 #include "code.h"
6
7 /* concatenate code */
8
9 int codcat (char *dst, size_t n, char *src)
10 {
11 while ((*dst != 0) && (n > 0)) {
12 n--;
13 dst++;
14 }
15
16 return (n > 0) ? codcpy (dst, n, src) : -1;
17 }
18
19 /* compare 2 codes */
20
21 int codcmp (char *cod1, char *cod2)
22 {
23 int i = -1;
24
25 do {
26 i++;
27 if (cod1[i] != cod2[i]) {
28 return (cod1[i] < cod2[i]) ? -1 : 1;
29 }
30 } while (cod1[i] != 0);
31
32 return 0;
33 }
34
35 /* copy code */
36
37 int codcpy (char *dst, size_t n, char *src)
38 {
39 size_t i;
40
41 for (i = 0; i < n; i++) {
42 dst[i] = src[i];
43 if (src[i]== 0) {
44 return i;
45 }
46 }
47 VERBOSE (ERROR, printf ("Buffer too short\n"));
48
49 return -1;
50 }
51
52 /* code length */
53
54 int codlen (char *code)
55 {
56 int i = 0;
57
58 while (code[i] != 0) {
59 i++;
60 }
61
62 return i;
63 }
64
65 // vim: ts=4 sw=4 et